@ix-xs/node-comfort 1.1.31 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +190 -0
- package/LICENSE +21 -0
- package/README.md +210 -748
- package/index.js +84 -13
- package/package.json +201 -21
- package/src/Arr.js +901 -0
- package/src/Async.js +585 -0
- package/src/Cache.js +329 -0
- package/src/Checker.js +979 -188
- package/src/Cli.js +1034 -0
- package/src/Color.js +415 -0
- package/src/Crypto.js +707 -0
- package/src/Emitter.js +289 -0
- package/src/Env.js +555 -0
- package/src/FS.js +1483 -768
- package/src/Func.js +692 -0
- package/src/Http.js +538 -0
- package/src/Id.js +418 -0
- package/src/Logger.js +739 -307
- package/src/Num.js +849 -0
- package/src/Obj.js +904 -0
- package/src/SQLite.js +1308 -994
- package/src/Schema.js +1586 -0
- package/src/Str.js +999 -0
- package/src/Sys.js +511 -0
- package/src/Time.js +1323 -0
- package/src/Utils.js +321 -325
- package/src/errors.js +292 -0
- package/types/index.d.ts +693 -120
- package/types/src/Arr.d.ts +562 -0
- package/types/src/Arr.d.ts.map +1 -0
- package/types/src/Async.d.ts +321 -0
- package/types/src/Async.d.ts.map +1 -0
- package/types/src/Cache.d.ts +195 -0
- package/types/src/Cache.d.ts.map +1 -0
- package/types/src/Checker.d.ts +609 -81
- package/types/src/Checker.d.ts.map +1 -1
- package/types/src/Cli.d.ts +582 -0
- package/types/src/Cli.d.ts.map +1 -0
- package/types/src/Color.d.ts +294 -0
- package/types/src/Color.d.ts.map +1 -0
- package/types/src/Crypto.d.ts +534 -0
- package/types/src/Crypto.d.ts.map +1 -0
- package/types/src/Emitter.d.ts +170 -0
- package/types/src/Emitter.d.ts.map +1 -0
- package/types/src/Env.d.ts +382 -0
- package/types/src/Env.d.ts.map +1 -0
- package/types/src/FS.d.ts +709 -201
- package/types/src/FS.d.ts.map +1 -1
- package/types/src/Func.d.ts +455 -0
- package/types/src/Func.d.ts.map +1 -0
- package/types/src/Http.d.ts +374 -0
- package/types/src/Http.d.ts.map +1 -0
- package/types/src/Id.d.ts +200 -0
- package/types/src/Id.d.ts.map +1 -0
- package/types/src/Logger.d.ts +374 -24
- package/types/src/Logger.d.ts.map +1 -1
- package/types/src/Num.d.ts +578 -0
- package/types/src/Num.d.ts.map +1 -0
- package/types/src/Obj.d.ts +475 -0
- package/types/src/Obj.d.ts.map +1 -0
- package/types/src/SQLite.d.ts +647 -305
- package/types/src/SQLite.d.ts.map +1 -1
- package/types/src/Schema.d.ts +940 -0
- package/types/src/Schema.d.ts.map +1 -0
- package/types/src/Str.d.ts +696 -0
- package/types/src/Str.d.ts.map +1 -0
- package/types/src/Sys.d.ts +269 -0
- package/types/src/Sys.d.ts.map +1 -0
- package/types/src/Time.d.ts +664 -0
- package/types/src/Time.d.ts.map +1 -0
- package/types/src/Utils.d.ts +154 -102
- package/types/src/Utils.d.ts.map +1 -1
- package/types/src/errors.d.ts +292 -0
- package/types/src/errors.d.ts.map +1 -0
- package/tsconfig.json +0 -18
- package/types/index.d.ts.map +0 -1
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
declare namespace _exports {
|
|
2
|
+
export { PathLeaf, Paths, NullishToUndefined, PathValue, PathStep, PathInput, DeepReadonly, Change, MergeOptions, CompactOptions };
|
|
3
|
+
}
|
|
4
|
+
declare namespace _exports {
|
|
5
|
+
export { clone };
|
|
6
|
+
export { merge };
|
|
7
|
+
export { mergeWith };
|
|
8
|
+
export { defaults };
|
|
9
|
+
export { equal };
|
|
10
|
+
export { diff };
|
|
11
|
+
export { get };
|
|
12
|
+
export { set };
|
|
13
|
+
export { unset };
|
|
14
|
+
export { has };
|
|
15
|
+
export { pick };
|
|
16
|
+
export { omit };
|
|
17
|
+
export { filter };
|
|
18
|
+
export { mapValues };
|
|
19
|
+
export { mapKeys };
|
|
20
|
+
export { renameKeys };
|
|
21
|
+
export { invert };
|
|
22
|
+
export { compact };
|
|
23
|
+
export { flatten };
|
|
24
|
+
export { unflatten };
|
|
25
|
+
export { keys };
|
|
26
|
+
export { entries };
|
|
27
|
+
export { fromEntries };
|
|
28
|
+
export { size };
|
|
29
|
+
export { isEmpty };
|
|
30
|
+
export { deepFreeze };
|
|
31
|
+
}
|
|
32
|
+
export = _exports;
|
|
33
|
+
/**
|
|
34
|
+
* Values that end a path: dates, regexes, maps, sets, functions and arrays.
|
|
35
|
+
*/
|
|
36
|
+
type PathLeaf = Date | RegExp | Map<any, any> | Set<any> | ((...args: any[]) => any) | readonly any[];
|
|
37
|
+
/**
|
|
38
|
+
* Every dotted path of an object type, up to 6 levels. This is what powers
|
|
39
|
+
* path completion in `obj.get()` and friends.
|
|
40
|
+
*/
|
|
41
|
+
type Paths<T, Depth extends unknown[] = []> = Depth["length"] extends 6 ? never : T extends PathLeaf ? never : T extends object ? { [K in keyof T & (string | number)]: NonNullable<T[K]> extends PathLeaf ? `${K}` : NonNullable<T[K]> extends object ? `${K}` | `${K}.${Paths<NonNullable<T[K]>, [...Depth, 0]>}` : `${K}`; }[keyof T & (string | number)] : never;
|
|
42
|
+
type NullishToUndefined<T> = [Extract<T, null | undefined>] extends [never] ? never : undefined;
|
|
43
|
+
/**
|
|
44
|
+
* The type found at a dotted path of `T`, or `any` for an unknown path.
|
|
45
|
+
*/
|
|
46
|
+
type PathValue<T, P extends string> = P extends `${infer Head}.${infer Rest}` ? PathStep<T, Head> extends infer Next ? ([Next] extends [typeof _NOT_FOUND] ? any : PathValue<Next, Rest> | NullishToUndefined<T>) : any : PathStep<T, P> extends infer Next ? ([Next] extends [typeof _NOT_FOUND] ? any : Next | NullishToUndefined<T>) : any;
|
|
47
|
+
type PathStep<T, K extends string> = K extends keyof NonNullable<T> ? NonNullable<T>[K] : NonNullable<T> extends readonly (infer E)[] ? (K extends `${number}` ? E | undefined : typeof _NOT_FOUND) : typeof _NOT_FOUND;
|
|
48
|
+
/**
|
|
49
|
+
* A path: a known dotted path (completed by your editor), any other string
|
|
50
|
+
* like `"items[0].name"`, or an array of keys.
|
|
51
|
+
*/
|
|
52
|
+
type PathInput<T> = Paths<T> | (string & {}) | ReadonlyArray<string | number>;
|
|
53
|
+
/**
|
|
54
|
+
* `T`, read-only all the way down.
|
|
55
|
+
*/
|
|
56
|
+
type DeepReadonly<T> = T extends (...args: any[]) => any ? T : T extends object ? { readonly [K in keyof T]: DeepReadonly<T[K]>; } : T;
|
|
57
|
+
/**
|
|
58
|
+
* One difference reported by `diff()`.
|
|
59
|
+
*/
|
|
60
|
+
type Change = {
|
|
61
|
+
/**
|
|
62
|
+
* Where it changed, like `["address", "city"]`.
|
|
63
|
+
*/
|
|
64
|
+
path: Array<string | number>;
|
|
65
|
+
type: "added" | "removed" | "changed";
|
|
66
|
+
/**
|
|
67
|
+
* The old value.
|
|
68
|
+
*/
|
|
69
|
+
from?: unknown;
|
|
70
|
+
/**
|
|
71
|
+
* The new value.
|
|
72
|
+
*/
|
|
73
|
+
to?: unknown;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Options for `mergeWith()`.
|
|
77
|
+
*/
|
|
78
|
+
type MergeOptions = {
|
|
79
|
+
/**
|
|
80
|
+
* When both sides have an array: keep the last, join them, or join without duplicates. Defaults to `"replace"`.
|
|
81
|
+
*/
|
|
82
|
+
arrays?: "concat" | "replace" | "unique" | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* Don't let `undefined` overwrite an existing value.
|
|
85
|
+
*/
|
|
86
|
+
skipUndefined?: boolean | undefined;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Options for `compact()`.
|
|
90
|
+
*/
|
|
91
|
+
type CompactOptions = {
|
|
92
|
+
/**
|
|
93
|
+
* Clean nested objects and arrays too.
|
|
94
|
+
*/
|
|
95
|
+
deep?: boolean | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* Also remove `""`, `[]` and `{}`.
|
|
98
|
+
*/
|
|
99
|
+
removeEmpty?: boolean | undefined;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Deep copy. Uses `structuredClone` when it can, and falls back to a copy
|
|
103
|
+
* that keeps functions and class prototypes.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* const copy = obj.clone({ a: { b: [1, 2] }, when: new Date() });
|
|
107
|
+
* copy.a.b.push(3); // the original is untouched
|
|
108
|
+
*
|
|
109
|
+
* @template T
|
|
110
|
+
* @param {T} value
|
|
111
|
+
* @returns {T}
|
|
112
|
+
*/
|
|
113
|
+
declare function clone<T>(value: T): T;
|
|
114
|
+
/**
|
|
115
|
+
* Deep-merges objects into a new one. Later objects win, nested objects are
|
|
116
|
+
* merged, arrays are replaced. See `mergeWith()` to join arrays instead.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* obj.merge({ db: { host: "localhost", port: 5432 } }, { db: { port: 6543 } });
|
|
120
|
+
* // { db: { host: "localhost", port: 6543 } }
|
|
121
|
+
*
|
|
122
|
+
* @template {object} A
|
|
123
|
+
* @overload
|
|
124
|
+
* @param {A} a
|
|
125
|
+
* @returns {A}
|
|
126
|
+
*/
|
|
127
|
+
declare function merge<A extends object>(a: A): A;
|
|
128
|
+
/**
|
|
129
|
+
* Deep-merges `b` into a copy of `a`.
|
|
130
|
+
*
|
|
131
|
+
* @template {object} A
|
|
132
|
+
* @template {object} B
|
|
133
|
+
* @overload
|
|
134
|
+
* @param {A} a
|
|
135
|
+
* @param {B} b
|
|
136
|
+
* @returns {A & B}
|
|
137
|
+
*/
|
|
138
|
+
declare function merge<A extends object, B extends object>(a: A, b: B): A & B;
|
|
139
|
+
/**
|
|
140
|
+
* Deep-merges three objects; the last one wins.
|
|
141
|
+
*
|
|
142
|
+
* @template {object} A
|
|
143
|
+
* @template {object} B
|
|
144
|
+
* @template {object} C
|
|
145
|
+
* @overload
|
|
146
|
+
* @param {A} a
|
|
147
|
+
* @param {B} b
|
|
148
|
+
* @param {C} c
|
|
149
|
+
* @returns {A & B & C}
|
|
150
|
+
*/
|
|
151
|
+
declare function merge<A extends object, B extends object, C extends object>(a: A, b: B, c: C): A & B & C;
|
|
152
|
+
/**
|
|
153
|
+
* Deep-merges any number of objects; the last one wins.
|
|
154
|
+
*
|
|
155
|
+
* @overload
|
|
156
|
+
* @param {...object} sources
|
|
157
|
+
* @returns {Record<string, any>}
|
|
158
|
+
*/
|
|
159
|
+
declare function merge(...sources: object[]): Record<string, any>;
|
|
160
|
+
/**
|
|
161
|
+
* Like `merge()`, with a choice of what happens to arrays and `undefined`.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* obj.mergeWith({ arrays: "unique" }, { tags: ["a", "b"] }, { tags: ["b", "c"] });
|
|
165
|
+
* // { tags: ["a", "b", "c"] }
|
|
166
|
+
* obj.mergeWith({ skipUndefined: true }, { port: 80 }, { port: undefined });
|
|
167
|
+
* // { port: 80 }
|
|
168
|
+
*
|
|
169
|
+
* @param {MergeOptions} options
|
|
170
|
+
* @param {...object} sources
|
|
171
|
+
* @returns {Record<string, any>}
|
|
172
|
+
*/
|
|
173
|
+
declare function mergeWith(options: MergeOptions, ...sources: object[]): Record<string, any>;
|
|
174
|
+
/**
|
|
175
|
+
* Fills in missing properties from defaults, deeply. Values that are set,
|
|
176
|
+
* even `null` or `0`, are kept.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* obj.defaults({ port: 8080, db: { user: "me" } }, { port: 80, db: { user: "root", pass: "" } });
|
|
180
|
+
* // { port: 8080, db: { user: "me", pass: "" } }
|
|
181
|
+
*
|
|
182
|
+
* @template {object} T
|
|
183
|
+
* @template {object} D
|
|
184
|
+
* @param {T} target
|
|
185
|
+
* @param {...D} sources The first one has the highest priority.
|
|
186
|
+
* @returns {T & D}
|
|
187
|
+
*/
|
|
188
|
+
declare function defaults<T extends object, D extends object>(target: T, ...sources: D[]): T & D;
|
|
189
|
+
/**
|
|
190
|
+
* Deep equality. Knows about arrays, dates, regexes, maps, sets, typed
|
|
191
|
+
* arrays, `NaN` and circular references.
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* obj.equal({ a: [1, { b: 2 }] }, { a: [1, { b: 2 }] }); // true
|
|
195
|
+
* obj.equal(new Set([1, 2]), new Set([2, 1])); // true
|
|
196
|
+
* obj.equal({ a: 1 }, { a: 1, b: undefined }); // false
|
|
197
|
+
*
|
|
198
|
+
* @param {unknown} a
|
|
199
|
+
* @param {unknown} b
|
|
200
|
+
* @returns {boolean}
|
|
201
|
+
*/
|
|
202
|
+
declare function equal(a: unknown, b: unknown): boolean;
|
|
203
|
+
/**
|
|
204
|
+
* Lists what changed between two values, deeply. Handy for audit logs and
|
|
205
|
+
* partial updates.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* obj.diff({ name: "Ada", tags: ["a"] }, { name: "Ada L.", tags: ["a", "b"] });
|
|
209
|
+
* // [
|
|
210
|
+
* // { path: ["name"], type: "changed", from: "Ada", to: "Ada L." },
|
|
211
|
+
* // { path: ["tags", 1], type: "added", to: "b" },
|
|
212
|
+
* // ]
|
|
213
|
+
*
|
|
214
|
+
* @param {unknown} before
|
|
215
|
+
* @param {unknown} after
|
|
216
|
+
* @returns {Change[]} Empty when nothing changed.
|
|
217
|
+
*/
|
|
218
|
+
declare function diff(before: unknown, after: unknown): Change[];
|
|
219
|
+
/**
|
|
220
|
+
* Reads a nested value from a dotted path. Your editor completes the paths
|
|
221
|
+
* and knows the type of the result.
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* obj.get(config, "db.pool.max"); // number | undefined
|
|
225
|
+
* obj.get(config, "db.pool.max", 10); // number
|
|
226
|
+
* obj.get(data, "users[0].name");
|
|
227
|
+
* obj.get(data, ["users", 0, "name"]);
|
|
228
|
+
*
|
|
229
|
+
* @template T
|
|
230
|
+
* @template {string} P
|
|
231
|
+
* @overload
|
|
232
|
+
* @param {T} object
|
|
233
|
+
* @param {P | Paths<T> | ReadonlyArray<string | number>} path Like `"a.b.c"`, `"a[0].b"` or `["a", 0, "b"]`.
|
|
234
|
+
* @returns {PathValue<T, P>}
|
|
235
|
+
*/
|
|
236
|
+
declare function get<T, P extends string>(object: T, path: P | Paths<T> | ReadonlyArray<string | number>): PathValue<T, P>;
|
|
237
|
+
/**
|
|
238
|
+
* Reads a nested value from a dotted path, or returns `fallback` if there's
|
|
239
|
+
* nothing there.
|
|
240
|
+
*
|
|
241
|
+
* @template T
|
|
242
|
+
* @template {string} P
|
|
243
|
+
* @template F
|
|
244
|
+
* @overload
|
|
245
|
+
* @param {T} object
|
|
246
|
+
* @param {P | Paths<T> | ReadonlyArray<string | number>} path Like `"a.b.c"`, `"a[0].b"` or `["a", 0, "b"]`.
|
|
247
|
+
* @param {F} fallback
|
|
248
|
+
* @returns {Exclude<PathValue<T, P>, undefined> | F}
|
|
249
|
+
*/
|
|
250
|
+
declare function get<T, P extends string, F>(object: T, path: P | Paths<T> | ReadonlyArray<string | number>, fallback: F): Exclude<PathValue<T, P>, undefined> | F;
|
|
251
|
+
/**
|
|
252
|
+
* Returns a copy with a nested value set. Missing levels are created
|
|
253
|
+
* (arrays when the next key is a number).
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* obj.set({}, "a.b.c", 1); // { a: { b: { c: 1 } } }
|
|
257
|
+
* obj.set(state, "user.name", "Ada"); // state is untouched
|
|
258
|
+
*
|
|
259
|
+
* @template T
|
|
260
|
+
* @param {T} object
|
|
261
|
+
* @param {PathInput<T>} path
|
|
262
|
+
* @param {unknown} value
|
|
263
|
+
* @returns {T}
|
|
264
|
+
*/
|
|
265
|
+
declare function set<T>(object: T, path: PathInput<T>, value: unknown): T;
|
|
266
|
+
/**
|
|
267
|
+
* Returns a copy without the property at `path`.
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* obj.unset({ a: { b: 1, c: 2 } }, "a.b"); // { a: { c: 2 } }
|
|
271
|
+
*
|
|
272
|
+
* @template T
|
|
273
|
+
* @param {T} object
|
|
274
|
+
* @param {PathInput<T>} path
|
|
275
|
+
* @returns {T}
|
|
276
|
+
*/
|
|
277
|
+
declare function unset<T>(object: T, path: PathInput<T>): T;
|
|
278
|
+
/**
|
|
279
|
+
* Does the path exist? A property set to `undefined` still counts.
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* obj.has({ a: { b: undefined } }, "a.b"); // true
|
|
283
|
+
* obj.has({ a: {} }, "a.b"); // false
|
|
284
|
+
*
|
|
285
|
+
* @template T
|
|
286
|
+
* @param {T} object
|
|
287
|
+
* @param {PathInput<T>} path
|
|
288
|
+
* @returns {boolean}
|
|
289
|
+
*/
|
|
290
|
+
declare function has<T>(object: T, path: PathInput<T>): boolean;
|
|
291
|
+
/**
|
|
292
|
+
* A copy with only the listed keys.
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* obj.pick(user, ["id", "email"]);
|
|
296
|
+
*
|
|
297
|
+
* @template {object} T
|
|
298
|
+
* @template {keyof T} K
|
|
299
|
+
* @param {T} object
|
|
300
|
+
* @param {readonly K[]} keys
|
|
301
|
+
* @returns {Pick<T, K>}
|
|
302
|
+
*/
|
|
303
|
+
declare function pick<T extends object, K extends keyof T>(object: T, keys: readonly K[]): Pick<T, K>;
|
|
304
|
+
/**
|
|
305
|
+
* A copy without the listed keys.
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
308
|
+
* obj.omit(user, ["password", "token"]);
|
|
309
|
+
*
|
|
310
|
+
* @template {object} T
|
|
311
|
+
* @template {keyof T} K
|
|
312
|
+
* @param {T} object
|
|
313
|
+
* @param {readonly K[]} keys
|
|
314
|
+
* @returns {Omit<T, K>}
|
|
315
|
+
*/
|
|
316
|
+
declare function omit<T extends object, K extends keyof T>(object: T, keys: readonly K[]): Omit<T, K>;
|
|
317
|
+
/**
|
|
318
|
+
* Keeps the entries that pass a test.
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* obj.filter({ a: 1, b: 2, c: 3 }, (value) => value > 1); // { b: 2, c: 3 }
|
|
322
|
+
*
|
|
323
|
+
* @template {object} T
|
|
324
|
+
* @param {T} object
|
|
325
|
+
* @param {(value: T[keyof T], key: keyof T & string) => unknown} predicate
|
|
326
|
+
* @returns {Partial<T>}
|
|
327
|
+
*/
|
|
328
|
+
declare function filter<T extends object>(object: T, predicate: (value: T[keyof T], key: keyof T & string) => unknown): Partial<T>;
|
|
329
|
+
/**
|
|
330
|
+
* Transforms every value, keeping the keys.
|
|
331
|
+
*
|
|
332
|
+
* @example
|
|
333
|
+
* obj.mapValues({ a: 1, b: 2 }, (v) => v * 10); // { a: 10, b: 20 }
|
|
334
|
+
*
|
|
335
|
+
* @template {object} T
|
|
336
|
+
* @template R
|
|
337
|
+
* @param {T} object
|
|
338
|
+
* @param {(value: T[keyof T], key: keyof T & string) => R} fn
|
|
339
|
+
* @returns {{ [K in keyof T]: R }}
|
|
340
|
+
*/
|
|
341
|
+
declare function mapValues<T extends object, R>(object: T, fn: (value: T[keyof T], key: keyof T & string) => R): { [K in keyof T]: R; };
|
|
342
|
+
/**
|
|
343
|
+
* Transforms every key, keeping the values.
|
|
344
|
+
*
|
|
345
|
+
* @example
|
|
346
|
+
* obj.mapKeys({ first_name: "Ada" }, (key) => nc.str.camelCase(key)); // { firstName: "Ada" }
|
|
347
|
+
*
|
|
348
|
+
* @template {object} T
|
|
349
|
+
* @param {T} object
|
|
350
|
+
* @param {(key: keyof T & string, value: T[keyof T]) => PropertyKey} fn Returns the new key.
|
|
351
|
+
* @returns {Record<string, T[keyof T]>}
|
|
352
|
+
*/
|
|
353
|
+
declare function mapKeys<T extends object>(object: T, fn: (key: keyof T & string, value: T[keyof T]) => PropertyKey): Record<string, T[keyof T]>;
|
|
354
|
+
/**
|
|
355
|
+
* Renames some keys and leaves the others alone.
|
|
356
|
+
*
|
|
357
|
+
* @example
|
|
358
|
+
* obj.renameKeys({ _id: 1, name: "Ada" }, { _id: "id" }); // { id: 1, name: "Ada" }
|
|
359
|
+
*
|
|
360
|
+
* @template {object} T
|
|
361
|
+
* @param {T} object
|
|
362
|
+
* @param {Partial<Record<keyof T, string>>} mapping Old name to new name.
|
|
363
|
+
* @returns {Record<string, T[keyof T]>}
|
|
364
|
+
*/
|
|
365
|
+
declare function renameKeys<T extends object>(object: T, mapping: Partial<Record<keyof T, string>>): Record<string, T[keyof T]>;
|
|
366
|
+
/**
|
|
367
|
+
* Swaps keys and values.
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
* obj.invert({ a: "x", b: "y" }); // { x: "a", y: "b" }
|
|
371
|
+
*
|
|
372
|
+
* @param {Record<string, PropertyKey>} object
|
|
373
|
+
* @returns {Record<string, string>}
|
|
374
|
+
*/
|
|
375
|
+
declare function invert(object: Record<string, PropertyKey>): Record<string, string>;
|
|
376
|
+
/**
|
|
377
|
+
* Removes `null` and `undefined` values, and optionally empty ones.
|
|
378
|
+
*
|
|
379
|
+
* @example
|
|
380
|
+
* obj.compact({ a: 1, b: null, c: undefined }); // { a: 1 }
|
|
381
|
+
* obj.compact({ a: { b: null, c: "" } }, { deep: true, removeEmpty: true }); // {}
|
|
382
|
+
*
|
|
383
|
+
* @template {object} T
|
|
384
|
+
* @param {T} object
|
|
385
|
+
* @param {CompactOptions} [options]
|
|
386
|
+
* @returns {Partial<T>}
|
|
387
|
+
*/
|
|
388
|
+
declare function compact<T extends object>(object: T, options?: CompactOptions): Partial<T>;
|
|
389
|
+
/**
|
|
390
|
+
* Flattens nested objects into dotted keys. Arrays stay as values.
|
|
391
|
+
*
|
|
392
|
+
* @example
|
|
393
|
+
* obj.flatten({ db: { host: "x", port: 5432 } }); // { "db.host": "x", "db.port": 5432 }
|
|
394
|
+
*
|
|
395
|
+
* @param {object} object
|
|
396
|
+
* @param {string} [prefix=""] Added in front of every key.
|
|
397
|
+
* @returns {Record<string, unknown>}
|
|
398
|
+
*/
|
|
399
|
+
declare function flatten(object: object, prefix?: string): Record<string, unknown>;
|
|
400
|
+
/**
|
|
401
|
+
* Rebuilds nested objects from dotted keys. The opposite of `flatten()`.
|
|
402
|
+
*
|
|
403
|
+
* @example
|
|
404
|
+
* obj.unflatten({ "db.host": "x", "db.port": 5432 }); // { db: { host: "x", port: 5432 } }
|
|
405
|
+
*
|
|
406
|
+
* @param {Record<string, unknown>} object
|
|
407
|
+
* @returns {Record<string, any>}
|
|
408
|
+
*/
|
|
409
|
+
declare function unflatten(object: Record<string, unknown>): Record<string, any>;
|
|
410
|
+
/**
|
|
411
|
+
* `Object.keys`, but typed with the object's actual keys.
|
|
412
|
+
*
|
|
413
|
+
* @example
|
|
414
|
+
* for (const key of obj.keys(config)) config[key]; // no type error
|
|
415
|
+
*
|
|
416
|
+
* @template {object} T
|
|
417
|
+
* @param {T} object
|
|
418
|
+
* @returns {Array<keyof T & string>}
|
|
419
|
+
*/
|
|
420
|
+
declare function keys<T extends object>(object: T): Array<keyof T & string>;
|
|
421
|
+
/**
|
|
422
|
+
* `Object.entries`, with typed keys and values.
|
|
423
|
+
*
|
|
424
|
+
* @template {object} T
|
|
425
|
+
* @param {T} object
|
|
426
|
+
* @returns {Array<[keyof T & string, T[keyof T]]>}
|
|
427
|
+
*/
|
|
428
|
+
declare function entries<T extends object>(object: T): Array<[keyof T & string, T[keyof T]]>;
|
|
429
|
+
/**
|
|
430
|
+
* `Object.fromEntries` that accepts any iterable (a `Map` too) and skips
|
|
431
|
+
* unsafe keys.
|
|
432
|
+
*
|
|
433
|
+
* @example
|
|
434
|
+
* obj.fromEntries(new Map([["x", true]])); // { x: true }
|
|
435
|
+
*
|
|
436
|
+
* @template {PropertyKey} K
|
|
437
|
+
* @template V
|
|
438
|
+
* @param {Iterable<readonly [K, V]>} pairs
|
|
439
|
+
* @returns {Record<K, V>}
|
|
440
|
+
*/
|
|
441
|
+
declare function fromEntries<K extends PropertyKey, V>(pairs: Iterable<readonly [K, V]>): Record<K, V>;
|
|
442
|
+
/**
|
|
443
|
+
* How many entries: own keys of an object, size of a map or set, length of
|
|
444
|
+
* an array or string.
|
|
445
|
+
*
|
|
446
|
+
* @example
|
|
447
|
+
* obj.size({ a: 1, b: 2 }); // 2
|
|
448
|
+
*
|
|
449
|
+
* @param {unknown} value
|
|
450
|
+
* @returns {number}
|
|
451
|
+
*/
|
|
452
|
+
declare function size(value: unknown): number;
|
|
453
|
+
/**
|
|
454
|
+
* Does the object have no own keys? `null` and `undefined` count as empty.
|
|
455
|
+
*
|
|
456
|
+
* @param {unknown} object
|
|
457
|
+
* @returns {boolean}
|
|
458
|
+
*/
|
|
459
|
+
declare function isEmpty(object: unknown): boolean;
|
|
460
|
+
/**
|
|
461
|
+
* Freezes an object and everything inside it. Good for configuration and
|
|
462
|
+
* constants.
|
|
463
|
+
*
|
|
464
|
+
* @example
|
|
465
|
+
* const CONFIG = obj.deepFreeze({ db: { host: "localhost" } });
|
|
466
|
+
* CONFIG.db.host = "x"; // TypeScript error, and ignored at runtime
|
|
467
|
+
*
|
|
468
|
+
* @template T
|
|
469
|
+
* @param {T} object
|
|
470
|
+
* @returns {DeepReadonly<T>} The same object.
|
|
471
|
+
*/
|
|
472
|
+
declare function deepFreeze<T>(object: T): DeepReadonly<T>;
|
|
473
|
+
/** Marks an unknown path segment in `PathStep`. */
|
|
474
|
+
declare const _NOT_FOUND: unique symbol;
|
|
475
|
+
//# sourceMappingURL=Obj.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Obj.d.ts","sourceRoot":"","sources":["../../src/Obj.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBAkBa,IAAI,GAAG,MAAM,GAAG,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,GAAG,SAAS,GAAG,EAAE;;;;;WAUrF,CAAC,EACY,KAAK,SAAjB,OAAO,EAAG,SACX,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,KAAK,GAAG,CAAC,SAAS,QAAQ,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