Path: blob/master/node_modules/@hapi/hoek/lib/index.d.ts
1126 views
/// <reference types="node" />123/**4* Performs a deep comparison of the two values including support for circular dependencies, prototype, and enumerable properties.5*6* @param obj - The value being compared.7* @param ref - The reference value used for comparison.8*9* @return true when the two values are equal, otherwise false.10*/11export function deepEqual(obj: any, ref: any, options?: deepEqual.Options): boolean;1213export namespace deepEqual {1415interface Options {1617/**18* Compare functions with difference references by comparing their internal code and properties.19*20* @default false21*/22readonly deepFunction?: boolean;2324/**25* Allow partial match.26*27* @default false28*/29readonly part?: boolean;3031/**32* Compare the objects' prototypes.33*34* @default true35*/36readonly prototype?: boolean;3738/**39* List of object keys to ignore different values of.40*41* @default null42*/43readonly skip?: (string | symbol)[];4445/**46* Compare symbol properties.47*48* @default true49*/50readonly symbols?: boolean;51}52}535455/**56* Clone any value, object, or array.57*58* @param obj - The value being cloned.59* @param options - Optional settings.60*61* @returns A deep clone of `obj`.62*/63export function clone<T>(obj: T, options?: clone.Options): T;6465export namespace clone {6667interface Options {6869/**70* Clone the object's prototype.71*72* @default true73*/74readonly prototype?: boolean;7576/**77* Include symbol properties.78*79* @default true80*/81readonly symbols?: boolean;8283/**84* Shallow clone the specified keys.85*86* @default undefined87*/88readonly shallow?: string[] | string[][] | boolean;89}90}919293/**94* Merge all the properties of source into target.95*96* @param target - The object being modified.97* @param source - The object used to copy properties from.98* @param options - Optional settings.99*100* @returns The `target` object.101*/102export function merge<T1 extends object, T2 extends object>(target: T1, source: T2, options?: merge.Options): T1 & T2;103104export namespace merge {105106interface Options {107108/**109* When true, null value from `source` overrides existing value in `target`.110*111* @default true112*/113readonly nullOverride?: boolean;114115/**116* When true, array value from `source` is merged with the existing value in `target`.117*118* @default false119*/120readonly mergeArrays?: boolean;121122/**123* Compare symbol properties.124*125* @default true126*/127readonly symbols?: boolean;128}129}130131132/**133* Apply source to a copy of the defaults.134*135* @param defaults - An object with the default values to use of `options` does not contain the same keys.136* @param source - The source used to override the `defaults`.137* @param options - Optional settings.138*139* @returns A copy of `defaults` with `source` keys overriding any conflicts.140*/141export function applyToDefaults<T extends object>(defaults: Partial<T>, source: Partial<T> | boolean | null, options?: applyToDefaults.Options): Partial<T>;142143export namespace applyToDefaults {144145interface Options {146147/**148* When true, null value from `source` overrides existing value in `target`.149*150* @default true151*/152readonly nullOverride?: boolean;153154/**155* Shallow clone the specified keys.156*157* @default undefined158*/159readonly shallow?: string[] | string[][];160}161}162163164/**165* Find the common unique items in two arrays.166*167* @param array1 - The first array to compare.168* @param array2 - The second array to compare.169* @param options - Optional settings.170*171* @return - An array of the common items. If `justFirst` is true, returns the first common item.172*/173export function intersect<T1, T2>(array1: intersect.Array<T1>, array2: intersect.Array<T2>, options?: intersect.Options): Array<T1 | T2>;174export function intersect<T1, T2>(array1: intersect.Array<T1>, array2: intersect.Array<T2>, options?: intersect.Options): T1 | T2;175176export namespace intersect {177178type Array<T> = ArrayLike<T> | Set<T> | null;179180interface Options {181182/**183* When true, return the first overlapping value.184*185* @default false186*/187readonly first?: boolean;188}189}190191192/**193* Checks if the reference value contains the provided values.194*195* @param ref - The reference string, array, or object.196* @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.197*198* @return true if the value contains the provided values, otherwise false.199*/200export function contain(ref: string, values: string | string[], options?: contain.Options): boolean;201export function contain(ref: any[], values: any, options?: contain.Options): boolean;202export function contain(ref: object, values: string | string[] | object, options?: Omit<contain.Options, 'once'>): boolean;203204export namespace contain {205206interface Options {207208/**209* Perform a deep comparison.210*211* @default false212*/213readonly deep?: boolean;214215/**216* Allow only one occurrence of each value.217*218* @default false219*/220readonly once?: boolean;221222/**223* Allow only values explicitly listed.224*225* @default false226*/227readonly only?: boolean;228229/**230* Allow partial match.231*232* @default false233*/234readonly part?: boolean;235236/**237* Include symbol properties.238*239* @default true240*/241readonly symbols?: boolean;242}243}244245246/**247* Flatten an array with sub arrays248*249* @param array - an array of items or other arrays to flatten.250* @param target - if provided, an array to shallow copy the flattened `array` items to251*252* @return a flat array of the provided values (appended to `target` is provided).253*/254export function flatten<T>(array: ArrayLike<T | ReadonlyArray<T>>, target?: ArrayLike<T | ReadonlyArray<T>>): T[];255256257/**258* Convert an object key chain string to reference.259*260* @param obj - the object from which to look up the value.261* @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.262*263* @return The value referenced by the chain if found, otherwise undefined. If chain is null, undefined, or false, the object itself will be returned.264*/265export function reach(obj: object | null, chain: string | (string | number)[] | false | null | undefined, options?: reach.Options): any;266267export namespace reach {268269interface Options {270271/**272* String to split chain path on. Defaults to '.'.273*274* @default false275*/276readonly separator?: string;277278/**279* Value to return if the path or value is not present. No default value.280*281* @default false282*/283readonly default?: any;284285/**286* If true, will throw an error on missing member in the chain. Default to false.287*288* @default false289*/290readonly strict?: boolean;291292/**293* If true, allows traversing functions for properties. false will throw an error if a function is part of the chain.294*295* @default true296*/297readonly functions?: boolean;298299/**300* If true, allows traversing Set and Map objects for properties. false will return undefined regardless of the Set or Map passed.301*302* @default false303*/304readonly iterables?: boolean;305}306}307308309/**310* Replace string parameters (using format "{path.to.key}") with their corresponding object key values using `Hoek.reach()`.311*312* @param obj - the object from which to look up the value.313* @param template - the string containing {} enclosed key paths to be replaced.314*315* @return The template string with the {} enclosed keys replaced with looked-up values.316*/317export function reachTemplate(obj: object | null, template: string, options?: reach.Options): string;318319320/**321* Throw an error if condition is falsy.322*323* @param condition - If `condition` is not truthy, an exception is thrown.324* @param error - The error thrown if the condition fails.325*326* @return Does not return a value but throws if the `condition` is falsy.327*/328export function assert(condition: any, error: Error): void;329330331/**332* Throw an error if condition is falsy.333*334* @param condition - If `condition` is not truthy, an exception is thrown.335* @param args - Any number of values, concatenated together (space separated) to create the error message.336*337* @return Does not return a value but throws if the `condition` is falsy.338*/339export function assert(condition: any, ...args: any): void;340341342/**343* A benchmarking timer, using the internal node clock for maximum accuracy.344*/345export class Bench {346347constructor();348349/** The starting timestamp expressed in the number of milliseconds since the epoch. */350ts: number;351352/** The time in milliseconds since the object was created. */353elapsed(): number;354355/** Reset the `ts` value to now. */356reset(): void;357358/** The current time in milliseconds since the epoch. */359static now(): number;360}361362363/**364* Escape string for Regex construction by prefixing all reserved characters with a backslash.365*366* @param string - The string to be escaped.367*368* @return The escaped string.369*/370export function escapeRegex(string: string): string;371372373/**374* Escape string for usage as an attribute value in HTTP headers.375*376* @param attribute - The string to be escaped.377*378* @return The escaped string. Will throw on invalid characters that are not supported to be escaped.379*/380export function escapeHeaderAttribute(attribute: string): string;381382383/**384* Escape string for usage in HTML.385*386* @param string - The string to be escaped.387*388* @return The escaped string.389*/390export function escapeHtml(string: string): string;391392393/**394* Escape string for usage in JSON.395*396* @param string - The string to be escaped.397*398* @return The escaped string.399*/400export function escapeJson(string: string): string;401402403/**404* Wraps a function to ensure it can only execute once.405*406* @param method - The function to be wrapped.407*408* @return The wrapped function.409*/410export function once<T extends Function>(method: T): T;411412413/**414* A reusable no-op function.415*/416export function ignore(...ignore: any): void;417418419/**420* Converts a JavaScript value to a JavaScript Object Notation (JSON) string with protection against thrown errors.421*422* @param value A JavaScript value, usually an object or array, to be converted.423* @param replacer The JSON.stringify() `replacer` argument.424* @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.425*426* @return The JSON string. If the operation fails, an error string value is returned (no exception thrown).427*/428export function stringify(value: any, replacer?: any, space?: string | number): string;429430431/**432* Returns a Promise that resolves after the requested timeout.433*434* @param timeout - The number of milliseconds to wait before resolving the Promise.435* @param returnValue - The value that the Promise will resolve to.436*437* @return A Promise that resolves with `returnValue`.438*/439export function wait<T>(timeout?: number, returnValue?: T): Promise<T>;440441442/**443* Returns a Promise that never resolves.444*/445export function block(): Promise<void>;446447448/**449* Determines if an object is a promise.450*451* @param promise - the object tested.452*453* @returns true if the object is a promise, otherwise false.454*/455export function isPromise(promise: any): boolean;456457458export namespace ts {459460/**461* Defines a type that can must be one of T or U but not both.462*/463type XOR<T, U> = (T | U) extends object ? (internals.Without<T, U> & U) | (internals.Without<U, T> & T) : T | U;464}465466467declare namespace internals {468469type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };470}471472473