Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@hapi/hoek/lib/index.d.ts
1126 views
1
/// <reference types="node" />
2
3
4
/**
5
* Performs a deep comparison of the two values including support for circular dependencies, prototype, and enumerable properties.
6
*
7
* @param obj - The value being compared.
8
* @param ref - The reference value used for comparison.
9
*
10
* @return true when the two values are equal, otherwise false.
11
*/
12
export function deepEqual(obj: any, ref: any, options?: deepEqual.Options): boolean;
13
14
export namespace deepEqual {
15
16
interface Options {
17
18
/**
19
* Compare functions with difference references by comparing their internal code and properties.
20
*
21
* @default false
22
*/
23
readonly deepFunction?: boolean;
24
25
/**
26
* Allow partial match.
27
*
28
* @default false
29
*/
30
readonly part?: boolean;
31
32
/**
33
* Compare the objects' prototypes.
34
*
35
* @default true
36
*/
37
readonly prototype?: boolean;
38
39
/**
40
* List of object keys to ignore different values of.
41
*
42
* @default null
43
*/
44
readonly skip?: (string | symbol)[];
45
46
/**
47
* Compare symbol properties.
48
*
49
* @default true
50
*/
51
readonly symbols?: boolean;
52
}
53
}
54
55
56
/**
57
* Clone any value, object, or array.
58
*
59
* @param obj - The value being cloned.
60
* @param options - Optional settings.
61
*
62
* @returns A deep clone of `obj`.
63
*/
64
export function clone<T>(obj: T, options?: clone.Options): T;
65
66
export namespace clone {
67
68
interface Options {
69
70
/**
71
* Clone the object's prototype.
72
*
73
* @default true
74
*/
75
readonly prototype?: boolean;
76
77
/**
78
* Include symbol properties.
79
*
80
* @default true
81
*/
82
readonly symbols?: boolean;
83
84
/**
85
* Shallow clone the specified keys.
86
*
87
* @default undefined
88
*/
89
readonly shallow?: string[] | string[][] | boolean;
90
}
91
}
92
93
94
/**
95
* Merge all the properties of source into target.
96
*
97
* @param target - The object being modified.
98
* @param source - The object used to copy properties from.
99
* @param options - Optional settings.
100
*
101
* @returns The `target` object.
102
*/
103
export function merge<T1 extends object, T2 extends object>(target: T1, source: T2, options?: merge.Options): T1 & T2;
104
105
export namespace merge {
106
107
interface Options {
108
109
/**
110
* When true, null value from `source` overrides existing value in `target`.
111
*
112
* @default true
113
*/
114
readonly nullOverride?: boolean;
115
116
/**
117
* When true, array value from `source` is merged with the existing value in `target`.
118
*
119
* @default false
120
*/
121
readonly mergeArrays?: boolean;
122
123
/**
124
* Compare symbol properties.
125
*
126
* @default true
127
*/
128
readonly symbols?: boolean;
129
}
130
}
131
132
133
/**
134
* Apply source to a copy of the defaults.
135
*
136
* @param defaults - An object with the default values to use of `options` does not contain the same keys.
137
* @param source - The source used to override the `defaults`.
138
* @param options - Optional settings.
139
*
140
* @returns A copy of `defaults` with `source` keys overriding any conflicts.
141
*/
142
export function applyToDefaults<T extends object>(defaults: Partial<T>, source: Partial<T> | boolean | null, options?: applyToDefaults.Options): Partial<T>;
143
144
export namespace applyToDefaults {
145
146
interface Options {
147
148
/**
149
* When true, null value from `source` overrides existing value in `target`.
150
*
151
* @default true
152
*/
153
readonly nullOverride?: boolean;
154
155
/**
156
* Shallow clone the specified keys.
157
*
158
* @default undefined
159
*/
160
readonly shallow?: string[] | string[][];
161
}
162
}
163
164
165
/**
166
* Find the common unique items in two arrays.
167
*
168
* @param array1 - The first array to compare.
169
* @param array2 - The second array to compare.
170
* @param options - Optional settings.
171
*
172
* @return - An array of the common items. If `justFirst` is true, returns the first common item.
173
*/
174
export function intersect<T1, T2>(array1: intersect.Array<T1>, array2: intersect.Array<T2>, options?: intersect.Options): Array<T1 | T2>;
175
export function intersect<T1, T2>(array1: intersect.Array<T1>, array2: intersect.Array<T2>, options?: intersect.Options): T1 | T2;
176
177
export namespace intersect {
178
179
type Array<T> = ArrayLike<T> | Set<T> | null;
180
181
interface Options {
182
183
/**
184
* When true, return the first overlapping value.
185
*
186
* @default false
187
*/
188
readonly first?: boolean;
189
}
190
}
191
192
193
/**
194
* Checks if the reference value contains the provided values.
195
*
196
* @param ref - The reference string, array, or object.
197
* @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.
198
*
199
* @return true if the value contains the provided values, otherwise false.
200
*/
201
export function contain(ref: string, values: string | string[], options?: contain.Options): boolean;
202
export function contain(ref: any[], values: any, options?: contain.Options): boolean;
203
export function contain(ref: object, values: string | string[] | object, options?: Omit<contain.Options, 'once'>): boolean;
204
205
export namespace contain {
206
207
interface Options {
208
209
/**
210
* Perform a deep comparison.
211
*
212
* @default false
213
*/
214
readonly deep?: boolean;
215
216
/**
217
* Allow only one occurrence of each value.
218
*
219
* @default false
220
*/
221
readonly once?: boolean;
222
223
/**
224
* Allow only values explicitly listed.
225
*
226
* @default false
227
*/
228
readonly only?: boolean;
229
230
/**
231
* Allow partial match.
232
*
233
* @default false
234
*/
235
readonly part?: boolean;
236
237
/**
238
* Include symbol properties.
239
*
240
* @default true
241
*/
242
readonly symbols?: boolean;
243
}
244
}
245
246
247
/**
248
* Flatten an array with sub arrays
249
*
250
* @param array - an array of items or other arrays to flatten.
251
* @param target - if provided, an array to shallow copy the flattened `array` items to
252
*
253
* @return a flat array of the provided values (appended to `target` is provided).
254
*/
255
export function flatten<T>(array: ArrayLike<T | ReadonlyArray<T>>, target?: ArrayLike<T | ReadonlyArray<T>>): T[];
256
257
258
/**
259
* Convert an object key chain string to reference.
260
*
261
* @param obj - the object from which to look up the value.
262
* @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.
263
*
264
* @return The value referenced by the chain if found, otherwise undefined. If chain is null, undefined, or false, the object itself will be returned.
265
*/
266
export function reach(obj: object | null, chain: string | (string | number)[] | false | null | undefined, options?: reach.Options): any;
267
268
export namespace reach {
269
270
interface Options {
271
272
/**
273
* String to split chain path on. Defaults to '.'.
274
*
275
* @default false
276
*/
277
readonly separator?: string;
278
279
/**
280
* Value to return if the path or value is not present. No default value.
281
*
282
* @default false
283
*/
284
readonly default?: any;
285
286
/**
287
* If true, will throw an error on missing member in the chain. Default to false.
288
*
289
* @default false
290
*/
291
readonly strict?: boolean;
292
293
/**
294
* If true, allows traversing functions for properties. false will throw an error if a function is part of the chain.
295
*
296
* @default true
297
*/
298
readonly functions?: boolean;
299
300
/**
301
* If true, allows traversing Set and Map objects for properties. false will return undefined regardless of the Set or Map passed.
302
*
303
* @default false
304
*/
305
readonly iterables?: boolean;
306
}
307
}
308
309
310
/**
311
* Replace string parameters (using format "{path.to.key}") with their corresponding object key values using `Hoek.reach()`.
312
*
313
* @param obj - the object from which to look up the value.
314
* @param template - the string containing {} enclosed key paths to be replaced.
315
*
316
* @return The template string with the {} enclosed keys replaced with looked-up values.
317
*/
318
export function reachTemplate(obj: object | null, template: string, options?: reach.Options): string;
319
320
321
/**
322
* Throw an error if condition is falsy.
323
*
324
* @param condition - If `condition` is not truthy, an exception is thrown.
325
* @param error - The error thrown if the condition fails.
326
*
327
* @return Does not return a value but throws if the `condition` is falsy.
328
*/
329
export function assert(condition: any, error: Error): void;
330
331
332
/**
333
* Throw an error if condition is falsy.
334
*
335
* @param condition - If `condition` is not truthy, an exception is thrown.
336
* @param args - Any number of values, concatenated together (space separated) to create the error message.
337
*
338
* @return Does not return a value but throws if the `condition` is falsy.
339
*/
340
export function assert(condition: any, ...args: any): void;
341
342
343
/**
344
* A benchmarking timer, using the internal node clock for maximum accuracy.
345
*/
346
export class Bench {
347
348
constructor();
349
350
/** The starting timestamp expressed in the number of milliseconds since the epoch. */
351
ts: number;
352
353
/** The time in milliseconds since the object was created. */
354
elapsed(): number;
355
356
/** Reset the `ts` value to now. */
357
reset(): void;
358
359
/** The current time in milliseconds since the epoch. */
360
static now(): number;
361
}
362
363
364
/**
365
* Escape string for Regex construction by prefixing all reserved characters with a backslash.
366
*
367
* @param string - The string to be escaped.
368
*
369
* @return The escaped string.
370
*/
371
export function escapeRegex(string: string): string;
372
373
374
/**
375
* Escape string for usage as an attribute value in HTTP headers.
376
*
377
* @param attribute - The string to be escaped.
378
*
379
* @return The escaped string. Will throw on invalid characters that are not supported to be escaped.
380
*/
381
export function escapeHeaderAttribute(attribute: string): string;
382
383
384
/**
385
* Escape string for usage in HTML.
386
*
387
* @param string - The string to be escaped.
388
*
389
* @return The escaped string.
390
*/
391
export function escapeHtml(string: string): string;
392
393
394
/**
395
* Escape string for usage in JSON.
396
*
397
* @param string - The string to be escaped.
398
*
399
* @return The escaped string.
400
*/
401
export function escapeJson(string: string): string;
402
403
404
/**
405
* Wraps a function to ensure it can only execute once.
406
*
407
* @param method - The function to be wrapped.
408
*
409
* @return The wrapped function.
410
*/
411
export function once<T extends Function>(method: T): T;
412
413
414
/**
415
* A reusable no-op function.
416
*/
417
export function ignore(...ignore: any): void;
418
419
420
/**
421
* Converts a JavaScript value to a JavaScript Object Notation (JSON) string with protection against thrown errors.
422
*
423
* @param value A JavaScript value, usually an object or array, to be converted.
424
* @param replacer The JSON.stringify() `replacer` argument.
425
* @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
426
*
427
* @return The JSON string. If the operation fails, an error string value is returned (no exception thrown).
428
*/
429
export function stringify(value: any, replacer?: any, space?: string | number): string;
430
431
432
/**
433
* Returns a Promise that resolves after the requested timeout.
434
*
435
* @param timeout - The number of milliseconds to wait before resolving the Promise.
436
* @param returnValue - The value that the Promise will resolve to.
437
*
438
* @return A Promise that resolves with `returnValue`.
439
*/
440
export function wait<T>(timeout?: number, returnValue?: T): Promise<T>;
441
442
443
/**
444
* Returns a Promise that never resolves.
445
*/
446
export function block(): Promise<void>;
447
448
449
/**
450
* Determines if an object is a promise.
451
*
452
* @param promise - the object tested.
453
*
454
* @returns true if the object is a promise, otherwise false.
455
*/
456
export function isPromise(promise: any): boolean;
457
458
459
export namespace ts {
460
461
/**
462
* Defines a type that can must be one of T or U but not both.
463
*/
464
type XOR<T, U> = (T | U) extends object ? (internals.Without<T, U> & U) | (internals.Without<U, T> & T) : T | U;
465
}
466
467
468
declare namespace internals {
469
470
type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
471
}
472
473