1
0
Fork 0
management/front/dkha-web-sz-main/node_modules/@hapi/hoek/lib/index.d.ts

471 lines
12 KiB
TypeScript
Raw Permalink Normal View History

2024-01-16 21:26:16 +08:00
/// <reference types="node" />
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
/**
* Performs a deep comparison of the two values including support for circular dependencies, prototype, and enumerable properties.
*
* @param obj - The value being compared.
* @param ref - The reference value used for comparison.
*
* @return true when the two values are equal, otherwise false.
2023-12-18 13:12:25 +08:00
*/
export function deepEqual(obj: any, ref: any, options?: deepEqual.Options): boolean;
2024-01-16 21:26:16 +08:00
export namespace deepEqual {
2023-12-18 13:12:25 +08:00
interface Options {
/**
2024-01-16 21:26:16 +08:00
* Compare functions with difference references by comparing their internal code and properties.
*
* @default false
*/
2023-12-18 13:12:25 +08:00
readonly deepFunction?: boolean;
/**
2024-01-16 21:26:16 +08:00
* Allow partial match.
*
* @default false
*/
2023-12-18 13:12:25 +08:00
readonly part?: boolean;
/**
2024-01-16 21:26:16 +08:00
* Compare the objects' prototypes.
*
* @default true
*/
2023-12-18 13:12:25 +08:00
readonly prototype?: boolean;
/**
2024-01-16 21:26:16 +08:00
* List of object keys to ignore different values of.
*
* @default null
*/
2023-12-18 13:12:25 +08:00
readonly skip?: (string | symbol)[];
/**
2024-01-16 21:26:16 +08:00
* Compare symbol properties.
*
* @default true
*/
2023-12-18 13:12:25 +08:00
readonly symbols?: boolean;
}
}
/**
2024-01-16 21:26:16 +08:00
* Clone any value, object, or array.
*
* @param obj - The value being cloned.
* @param options - Optional settings.
*
* @returns A deep clone of `obj`.
*/
2023-12-18 13:12:25 +08:00
export function clone<T>(obj: T, options?: clone.Options): T;
2024-01-16 21:26:16 +08:00
export namespace clone {
2023-12-18 13:12:25 +08:00
interface Options {
/**
2024-01-16 21:26:16 +08:00
* Clone the object's prototype.
*
* @default true
*/
2023-12-18 13:12:25 +08:00
readonly prototype?: boolean;
/**
2024-01-16 21:26:16 +08:00
* Include symbol properties.
*
* @default true
*/
2023-12-18 13:12:25 +08:00
readonly symbols?: boolean;
/**
2024-01-16 21:26:16 +08:00
* Shallow clone the specified keys.
*
* @default undefined
*/
2023-12-18 13:12:25 +08:00
readonly shallow?: string[] | string[][] | boolean;
}
}
/**
2024-01-16 21:26:16 +08:00
* Merge all the properties of source into target.
*
* @param target - The object being modified.
* @param source - The object used to copy properties from.
* @param options - Optional settings.
*
* @returns The `target` object.
*/
2023-12-18 13:12:25 +08:00
export function merge<T1 extends object, T2 extends object>(target: T1, source: T2, options?: merge.Options): T1 & T2;
2024-01-16 21:26:16 +08:00
export namespace merge {
2023-12-18 13:12:25 +08:00
interface Options {
/**
2024-01-16 21:26:16 +08:00
* When true, null value from `source` overrides existing value in `target`.
*
* @default true
*/
2023-12-18 13:12:25 +08:00
readonly nullOverride?: boolean;
/**
2024-01-16 21:26:16 +08:00
* When true, array value from `source` is merged with the existing value in `target`.
*
* @default false
*/
2023-12-18 13:12:25 +08:00
readonly mergeArrays?: boolean;
/**
2024-01-16 21:26:16 +08:00
* Compare symbol properties.
*
* @default true
*/
2023-12-18 13:12:25 +08:00
readonly symbols?: boolean;
}
}
/**
2024-01-16 21:26:16 +08:00
* Apply source to a copy of the defaults.
*
* @param defaults - An object with the default values to use of `options` does not contain the same keys.
* @param source - The source used to override the `defaults`.
* @param options - Optional settings.
*
* @returns A copy of `defaults` with `source` keys overriding any conflicts.
*/
2023-12-18 13:12:25 +08:00
export function applyToDefaults<T extends object>(defaults: Partial<T>, source: Partial<T> | boolean | null, options?: applyToDefaults.Options): Partial<T>;
2024-01-16 21:26:16 +08:00
export namespace applyToDefaults {
2023-12-18 13:12:25 +08:00
interface Options {
/**
2024-01-16 21:26:16 +08:00
* When true, null value from `source` overrides existing value in `target`.
*
* @default true
*/
2023-12-18 13:12:25 +08:00
readonly nullOverride?: boolean;
/**
2024-01-16 21:26:16 +08:00
* Shallow clone the specified keys.
*
* @default undefined
*/
2023-12-18 13:12:25 +08:00
readonly shallow?: string[] | string[][];
}
}
/**
2024-01-16 21:26:16 +08:00
* Find the common unique items in two arrays.
*
* @param array1 - The first array to compare.
* @param array2 - The second array to compare.
* @param options - Optional settings.
*
* @return - An array of the common items. If `justFirst` is true, returns the first common item.
*/
2023-12-18 13:12:25 +08:00
export function intersect<T1, T2>(array1: intersect.Array<T1>, array2: intersect.Array<T2>, options?: intersect.Options): Array<T1 | T2>;
export function intersect<T1, T2>(array1: intersect.Array<T1>, array2: intersect.Array<T2>, options?: intersect.Options): T1 | T2;
2024-01-16 21:26:16 +08:00
export namespace intersect {
2023-12-18 13:12:25 +08:00
type Array<T> = ArrayLike<T> | Set<T> | null;
interface Options {
/**
2024-01-16 21:26:16 +08:00
* When true, return the first overlapping value.
*
* @default false
*/
2023-12-18 13:12:25 +08:00
readonly first?: boolean;
}
}
/**
2024-01-16 21:26:16 +08:00
* Checks if the reference value contains the provided values.
*
* @param ref - The reference string, array, or object.
* @param values - A single or array of values to find within `ref`. If `ref` is an object, `values` can be a key name, an array of key names, or an object with key-value pairs to compare.
*
* @return true if the value contains the provided values, otherwise false.
*/
2023-12-18 13:12:25 +08:00
export function contain(ref: string, values: string | string[], options?: contain.Options): boolean;
export function contain(ref: any[], values: any, options?: contain.Options): boolean;
2024-01-16 21:26:16 +08:00
export function contain(ref: object, values: string | string[] | object, options?: Omit<contain.Options, 'once'>): boolean;
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
export namespace contain {
2023-12-18 13:12:25 +08:00
interface Options {
/**
2024-01-16 21:26:16 +08:00
* Perform a deep comparison.
*
* @default false
*/
2023-12-18 13:12:25 +08:00
readonly deep?: boolean;
/**
2024-01-16 21:26:16 +08:00
* Allow only one occurrence of each value.
*
* @default false
*/
2023-12-18 13:12:25 +08:00
readonly once?: boolean;
/**
2024-01-16 21:26:16 +08:00
* Allow only values explicitly listed.
*
* @default false
*/
2023-12-18 13:12:25 +08:00
readonly only?: boolean;
/**
2024-01-16 21:26:16 +08:00
* Allow partial match.
*
* @default false
*/
2023-12-18 13:12:25 +08:00
readonly part?: boolean;
/**
2024-01-16 21:26:16 +08:00
* Include symbol properties.
*
* @default true
*/
2023-12-18 13:12:25 +08:00
readonly symbols?: boolean;
}
}
/**
2024-01-16 21:26:16 +08:00
* Flatten an array with sub arrays
*
* @param array - an array of items or other arrays to flatten.
* @param target - if provided, an array to shallow copy the flattened `array` items to
*
* @return a flat array of the provided values (appended to `target` is provided).
*/
2023-12-18 13:12:25 +08:00
export function flatten<T>(array: ArrayLike<T | ReadonlyArray<T>>, target?: ArrayLike<T | ReadonlyArray<T>>): T[];
/**
2024-01-16 21:26:16 +08:00
* Convert an object key chain string to reference.
*
* @param obj - the object from which to look up the value.
* @param chain - the string path of the requested value. The chain string is split into key names using `options.separator`, or an array containing each individual key name. A chain including negative numbers will work like a negative index on an array.
*
* @return The value referenced by the chain if found, otherwise undefined. If chain is null, undefined, or false, the object itself will be returned.
*/
2023-12-18 13:12:25 +08:00
export function reach(obj: object | null, chain: string | (string | number)[] | false | null | undefined, options?: reach.Options): any;
2024-01-16 21:26:16 +08:00
export namespace reach {
2023-12-18 13:12:25 +08:00
interface Options {
/**
2024-01-16 21:26:16 +08:00
* String to split chain path on. Defaults to '.'.
*
* @default false
*/
2023-12-18 13:12:25 +08:00
readonly separator?: string;
/**
2024-01-16 21:26:16 +08:00
* Value to return if the path or value is not present. No default value.
*
* @default false
*/
2023-12-18 13:12:25 +08:00
readonly default?: any;
/**
2024-01-16 21:26:16 +08:00
* If true, will throw an error on missing member in the chain. Default to false.
*
* @default false
*/
2023-12-18 13:12:25 +08:00
readonly strict?: boolean;
/**
2024-01-16 21:26:16 +08:00
* If true, allows traversing functions for properties. false will throw an error if a function is part of the chain.
*
* @default true
*/
2023-12-18 13:12:25 +08:00
readonly functions?: boolean;
/**
2024-01-16 21:26:16 +08:00
* If true, allows traversing Set and Map objects for properties. false will return undefined regardless of the Set or Map passed.
*
* @default false
*/
2023-12-18 13:12:25 +08:00
readonly iterables?: boolean;
}
}
/**
2024-01-16 21:26:16 +08:00
* Replace string parameters (using format "{path.to.key}") with their corresponding object key values using `Hoek.reach()`.
*
* @param obj - the object from which to look up the value.
* @param template - the string containing {} enclosed key paths to be replaced.
*
* @return The template string with the {} enclosed keys replaced with looked-up values.
*/
2023-12-18 13:12:25 +08:00
export function reachTemplate(obj: object | null, template: string, options?: reach.Options): string;
/**
2024-01-16 21:26:16 +08:00
* Throw an error if condition is falsy.
*
* @param condition - If `condition` is not truthy, an exception is thrown.
* @param error - The error thrown if the condition fails.
*
* @return Does not return a value but throws if the `condition` is falsy.
*/
2023-12-18 13:12:25 +08:00
export function assert(condition: any, error: Error): void;
/**
2024-01-16 21:26:16 +08:00
* Throw an error if condition is falsy.
*
* @param condition - If `condition` is not truthy, an exception is thrown.
* @param args - Any number of values, concatenated together (space separated) to create the error message.
*
* @return Does not return a value but throws if the `condition` is falsy.
*/
2023-12-18 13:12:25 +08:00
export function assert(condition: any, ...args: any): void;
/**
2024-01-16 21:26:16 +08:00
* A benchmarking timer, using the internal node clock for maximum accuracy.
2023-12-18 13:12:25 +08:00
*/
export class Bench {
constructor();
/** The starting timestamp expressed in the number of milliseconds since the epoch. */
ts: number;
/** The time in milliseconds since the object was created. */
elapsed(): number;
/** Reset the `ts` value to now. */
reset(): void;
/** The current time in milliseconds since the epoch. */
static now(): number;
}
/**
2024-01-16 21:26:16 +08:00
* Escape string for Regex construction by prefixing all reserved characters with a backslash.
*
* @param string - The string to be escaped.
*
* @return The escaped string.
*/
2023-12-18 13:12:25 +08:00
export function escapeRegex(string: string): string;
/**
2024-01-16 21:26:16 +08:00
* Escape string for usage as an attribute value in HTTP headers.
*
* @param attribute - The string to be escaped.
*
* @return The escaped string. Will throw on invalid characters that are not supported to be escaped.
*/
2023-12-18 13:12:25 +08:00
export function escapeHeaderAttribute(attribute: string): string;
/**
2024-01-16 21:26:16 +08:00
* Escape string for usage in HTML.
*
* @param string - The string to be escaped.
*
* @return The escaped string.
*/
2023-12-18 13:12:25 +08:00
export function escapeHtml(string: string): string;
/**
2024-01-16 21:26:16 +08:00
* Escape string for usage in JSON.
*
* @param string - The string to be escaped.
*
* @return The escaped string.
*/
2023-12-18 13:12:25 +08:00
export function escapeJson(string: string): string;
/**
2024-01-16 21:26:16 +08:00
* Wraps a function to ensure it can only execute once.
*
* @param method - The function to be wrapped.
*
* @return The wrapped function.
2023-12-18 13:12:25 +08:00
*/
export function once<T extends Function>(method: T): T;
/**
2024-01-16 21:26:16 +08:00
* A reusable no-op function.
*/
2023-12-18 13:12:25 +08:00
export function ignore(...ignore: any): void;
/**
2024-01-16 21:26:16 +08:00
* Converts a JavaScript value to a JavaScript Object Notation (JSON) string with protection against thrown errors.
*
* @param value A JavaScript value, usually an object or array, to be converted.
* @param replacer The JSON.stringify() `replacer` argument.
* @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
*
* @return The JSON string. If the operation fails, an error string value is returned (no exception thrown).
*/
2023-12-18 13:12:25 +08:00
export function stringify(value: any, replacer?: any, space?: string | number): string;
/**
2024-01-16 21:26:16 +08:00
* Returns a Promise that resolves after the requested timeout.
*
* @param timeout - The number of milliseconds to wait before resolving the Promise.
*
* @return A Promise.
*/
2023-12-18 13:12:25 +08:00
export function wait(timeout?: number): Promise<void>;
/**
2024-01-16 21:26:16 +08:00
* Returns a Promise that never resolves.
*/
2023-12-18 13:12:25 +08:00
export function block(): Promise<void>;
2024-01-16 21:26:16 +08:00
/**
* Determines if an object is a promise.
*
* @param promise - the object tested.
*
* @returns true if the object is a promise, otherwise false.
*/
export function isPromise(promise: any): boolean;
export namespace ts {
/**
* Defines a type that can must be one of T or U but not both.
*/
type XOR<T, U> = (T | U) extends object ? (internals.Without<T, U> & U) | (internals.Without<U, T> & T) : T | U;
}
declare namespace internals {
type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
}