1 | // Type definitions for hoek 4.1
|
2 | // Project: https://github.com/hapijs/hoek
|
3 | // Definitions by: Prashant Tiwari <https://github.com/prashaantt>
|
4 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
5 |
|
6 | export interface ContainOptions {
|
7 | /** Perform a deep comparison of the values? */
|
8 | deep?: boolean;
|
9 | /** Allow only one occurrence of each value? */
|
10 | once?: boolean;
|
11 | /** Don't allow values not explicitly listed? */
|
12 | only?: boolean;
|
13 | /** Allow partial match of the values? */
|
14 | part?: boolean;
|
15 | }
|
16 |
|
17 | export interface ReachOptions {
|
18 | /** String to split chain path on. Defaults to ".". */
|
19 | separator?: string;
|
20 | /** Value to return if the path or value is not present. Default is undefined. */
|
21 | default?: any;
|
22 | /** Throw an error on missing member? Default is false. */
|
23 | strict?: boolean;
|
24 | /** Allow traversing functions for properties? */
|
25 | functions?: boolean;
|
26 | }
|
27 |
|
28 | // Object
|
29 |
|
30 | /**
|
31 | * Clone an object or an array.
|
32 | */
|
33 | export function clone<T>(obj: T): T;
|
34 |
|
35 | /**
|
36 | * Clone an object or array.
|
37 | */
|
38 | export function cloneWithShallow(obj: any, keys: string[]): any;
|
39 |
|
40 | /**
|
41 | * Merge all the properties of source into target.
|
42 | */
|
43 | export function merge<T1, T2>(target: T1, source: T2, isNullOverride?: boolean, isMergeArrays?: boolean): T1 & T2;
|
44 |
|
45 | /**
|
46 | * Apply options to a copy of the defaults.
|
47 | */
|
48 | export function applyToDefaults<T1, T2>(defaults: T1, options: T2, isNullOverride?: boolean): T1 & T2;
|
49 |
|
50 | /**
|
51 | * Apply options to a copy of the defaults.
|
52 | */
|
53 | export function applyToDefaultsWithShallow<T1, T2>(defaults: T1, options: T2, keys?: string[]): T1 & T2;
|
54 |
|
55 | /**
|
56 | * Perform a deep comparison of the two values.
|
57 | */
|
58 | export function deepEqual<T>(b: T, a: T, options?: any): T;
|
59 |
|
60 | /**
|
61 | * Remove duplicate items from Array.
|
62 | */
|
63 | export function unique<T>(array: T[], key?: string): T[];
|
64 |
|
65 | /**
|
66 | * Convert an Array into an Object.
|
67 | */
|
68 | export function mapToObject(array: any[], key?: string): any;
|
69 |
|
70 | /**
|
71 | * Find the common unique items in two arrays.
|
72 | */
|
73 | export function intersect(array1: any[], array2: any[]): any;
|
74 |
|
75 | /**
|
76 | * Test if the reference value contains the provided values.
|
77 | */
|
78 | export function contain(ref: any, values: any, options?: ContainOptions): boolean;
|
79 |
|
80 | /**
|
81 | * Flatten an array.
|
82 | */
|
83 | export function flatten(array: any[], target?: any[]): any[];
|
84 |
|
85 | /**
|
86 | * Convert an object key chain string to reference.
|
87 | */
|
88 | export function reach(obj: any, chain: any, options?: ReachOptions): any;
|
89 |
|
90 | /**
|
91 | * Replace string parameters ({name}) with their corresponding object key values.
|
92 | */
|
93 | export function reachTemplate(obj: any, template: string, options?: ReachOptions): any;
|
94 |
|
95 | /**
|
96 | * Transform an existing object into a new one based on the supplied obj and transform map.
|
97 | */
|
98 | export function transform(obj: any, transform: any, options?: ReachOptions): any;
|
99 |
|
100 | /**
|
101 | * Perform a shallow copy by copying the references of all the top level children.
|
102 | */
|
103 | export function shallow(obj: any): any;
|
104 |
|
105 | /**
|
106 | * Convert an object to string. Any errors are caught and reported back in the form of the returned string.
|
107 | */
|
108 | export function stringify(obj: any): string;
|
109 |
|
110 | // Timer
|
111 |
|
112 | /**
|
113 | * A Timer object.
|
114 | */
|
115 | export class Timer {
|
116 | /** The number of milliseconds elapsed since the epoch. */
|
117 | ts: number;
|
118 | /** The time (ms) elapsed since the timer was created. */
|
119 | elapsed(): number;
|
120 | }
|
121 |
|
122 | // Bench
|
123 |
|
124 | /**
|
125 | * Same as Timer, except ts stores the internal node clock.
|
126 | */
|
127 | export class Bench {
|
128 | /** The number of milliseconds on the node clock elapsed since the epoch. */
|
129 | ts: number;
|
130 | /** The time (ms) elapsed since the timer was created. */
|
131 | elapsed(): number;
|
132 | }
|
133 |
|
134 | // Binary Encoding/Decoding
|
135 |
|
136 | /**
|
137 | * Encode value of string or buffer type in Base64 or URL encoding.
|
138 | */
|
139 | export function base64urlEncode(value: string): string;
|
140 |
|
141 | /**
|
142 | * Decode string into Base64 or URL encoding.
|
143 | */
|
144 | export function base64urlDecode(value: string): string;
|
145 |
|
146 | // Escaping Characters
|
147 |
|
148 | /**
|
149 | * Escape html characters.
|
150 | */
|
151 | export function escapeHtml(htmlString: string): string;
|
152 |
|
153 | /**
|
154 | * Escape attribute value for use in HTTP header.
|
155 | */
|
156 | export function escapeHeaderAttribute(attribute: string): string;
|
157 |
|
158 | /**
|
159 | * Escape string for Regex construction.
|
160 | */
|
161 | export function escapeRegex(regexString: string): string;
|
162 |
|
163 | // Errors
|
164 |
|
165 | /**
|
166 | * Print message or throw error if condition fails.
|
167 | */
|
168 | export function assert(condition: boolean, message: string | Error): void | Error;
|
169 |
|
170 | /**
|
171 | * Throw if process.env.NODE_ENV === 'test'. Else display most recent stack and exit process.
|
172 | */
|
173 | export function abort(message: string | Error): void;
|
174 |
|
175 | /**
|
176 | * Display the trace stack.
|
177 | */
|
178 | export function displayStack(slice?: any): string[];
|
179 |
|
180 | /**
|
181 | * Return a trace stack array.
|
182 | */
|
183 | export function callStack(slice?: any): any[];
|
184 |
|
185 | // Function
|
186 |
|
187 | /**
|
188 | * Wrap fn in process.nextTick.
|
189 | */
|
190 | export function nextTick(fn: () => void): () => void;
|
191 |
|
192 | /**
|
193 | * Make sure fn is only run once.
|
194 | */
|
195 | export function once(fn: () => void): () => void;
|
196 |
|
197 | /**
|
198 | * A simple no-op function.
|
199 | */
|
200 | export function ignore(): void;
|
201 |
|
202 | // Miscellaneous
|
203 |
|
204 | /**
|
205 | * path to prepend to a randomly generated file name.
|
206 | */
|
207 | export function uniqueFilename(path: string, extension?: string): string;
|
208 |
|
209 | /**
|
210 | * Check value to see if it is an integer.
|
211 | */
|
212 | export function isInteger(value: any): boolean;
|