@dbx-tools/shared-core 0.3.44 → 0.4.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/lib/index.d.ts +36 -0
- package/lib/index.js +30 -0
- package/lib/src/async.d.ts +152 -0
- package/lib/src/async.js +163 -0
- package/lib/src/brand.d.ts +94 -0
- package/lib/src/brand.js +123 -0
- package/lib/src/error.d.ts +76 -0
- package/lib/src/error.js +168 -0
- package/lib/src/function.d.ts +38 -0
- package/lib/src/function.js +44 -0
- package/lib/src/hash.d.ts +102 -0
- package/lib/src/hash.js +274 -0
- package/lib/src/http.d.ts +79 -0
- package/lib/src/http.js +189 -0
- package/lib/src/json.d.ts +48 -0
- package/lib/src/json.js +49 -0
- package/lib/src/log.d.ts +86 -0
- package/lib/src/log.js +352 -0
- package/lib/src/net.d.ts +246 -0
- package/lib/src/net.js +465 -0
- package/lib/src/object.d.ts +382 -0
- package/lib/src/object.js +749 -0
- package/lib/src/predicate.d.ts +81 -0
- package/lib/src/predicate.js +43 -0
- package/lib/src/string.d.ts +221 -0
- package/lib/src/string.js +509 -0
- package/lib/src/token.d.ts +30 -0
- package/lib/src/token.js +126 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/package.json +9 -5
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dependency-free object + iterable utilities.
|
|
3
|
+
*
|
|
4
|
+
* Value guards / coercions / shape types: {@link isRecord} narrows parsed JSON
|
|
5
|
+
* to a record, {@link toBoolean} coerces loose truthy/falsy values, {@link
|
|
6
|
+
* deepEqual} compares structurally, and {@link NameLike}/{@link NonFunctionKeys}
|
|
7
|
+
* describe object shapes.
|
|
8
|
+
*
|
|
9
|
+
* Iterable helpers: {@link generator} flattens mixed arguments; {@link sequence}
|
|
10
|
+
* wraps source(s) in a lazy, `Array`-compatible {@link Sequence}. Every
|
|
11
|
+
* transform/terminal is a standalone function operating on plain {@link
|
|
12
|
+
* Container}s (see {@link map}, {@link filter}, {@link group}, ...); the {@link
|
|
13
|
+
* Sequence} methods are thin forwarders over them so the same logic backs both
|
|
14
|
+
* the free-function and the fluent/chained styles.
|
|
15
|
+
*
|
|
16
|
+
* @module
|
|
17
|
+
*/
|
|
18
|
+
/** Lazy sequence over iterable source(s). See {@link sequence}. */
|
|
19
|
+
export type Sequence<T> = SequenceImpl<T>;
|
|
20
|
+
type SequenceSource<T> = Iterable<T> | ReadonlyMap<unknown, T> | OneOrMany<T> | null | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* A non-scalar {@link Iterable} - one to treat as a collection of elements
|
|
23
|
+
* rather than a scalar. {@link isContainer} narrows to this, excluding strings,
|
|
24
|
+
* `String`/`RegExp` objects, and functions. {@link Collection} is the eagerly-
|
|
25
|
+
* sized subset. The element defaults to `unknown` so any `Collection` is
|
|
26
|
+
* assignable to a bare `Container`.
|
|
27
|
+
*/
|
|
28
|
+
export type Container<T = unknown> = Iterable<T>;
|
|
29
|
+
/**
|
|
30
|
+
* A built-in, eagerly-sized {@link Container}: an {@link Array}, {@link Set}, or
|
|
31
|
+
* {@link Map} (whose *values* are `T` - a Map iterates `[key, value]` entries,
|
|
32
|
+
* so its element type differs, but its value type is `T`). All share a cheap
|
|
33
|
+
* emptiness check ({@link isEmpty}).
|
|
34
|
+
*/
|
|
35
|
+
export type Collection<T> = ReadonlyArray<T> | ReadonlySet<T> | ReadonlyMap<unknown, T>;
|
|
36
|
+
export type OneOrMany<T> = [T, ...T[]];
|
|
37
|
+
/** Narrow a readonly array to a non-empty {@link OneOrMany} tuple. */
|
|
38
|
+
export declare function isOneOrMany<T = unknown>(value: readonly T[]): value is OneOrMany<T>;
|
|
39
|
+
/** A source accepted by a variadic op: a {@link Container} of `T`, or nothing. */
|
|
40
|
+
type Source<T> = Container<T> | null | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Element type of a {@link group} bucket array: when the predicate `P` is a type
|
|
43
|
+
* guard (`value is S`), the bucket is narrowed to `S & T`; otherwise it stays `T`.
|
|
44
|
+
*/
|
|
45
|
+
type GroupValue<T, P> = P extends (value: any, ...rest: any[]) => value is infer S ? S & T : T;
|
|
46
|
+
/** A map of group name -> predicate, as accepted by {@link group}. */
|
|
47
|
+
type GroupPredicates<T> = Record<string, (value: T, index: number) => boolean>;
|
|
48
|
+
/**
|
|
49
|
+
* Type guard for a {@link Collection}: an {@link Array}, {@link Set}, or
|
|
50
|
+
* {@link Map}. Narrows `value` so its element/value type is treated as `T`.
|
|
51
|
+
*
|
|
52
|
+
* @typeParam T - Element (or Map value) type asserted for the collection.
|
|
53
|
+
* @param value - Value to test.
|
|
54
|
+
* @returns `true` (narrowing `value` to {@link Collection}<`T`>) for a
|
|
55
|
+
* built-in array/set/map.
|
|
56
|
+
*/
|
|
57
|
+
export declare function isCollection<T = unknown>(value: unknown): value is Collection<T>;
|
|
58
|
+
/**
|
|
59
|
+
* `true` when a {@link Collection} has no elements. Uses `length` for arrays
|
|
60
|
+
* and `size` for {@link Set}/{@link Map}.
|
|
61
|
+
*
|
|
62
|
+
* @param collection - The array, set, or map to test.
|
|
63
|
+
*/
|
|
64
|
+
export declare function isEmpty(collection: Collection<unknown> | Record<string, unknown>, options?: {
|
|
65
|
+
recursive?: boolean;
|
|
66
|
+
}): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Normalizes a source to an iterable of its `T` values, so Maps are treated
|
|
69
|
+
* uniformly with arrays/sets: a {@link Map} yields its *values* (matching
|
|
70
|
+
* {@link Collection}'s value-typed `T`), any other iterable yields itself. This
|
|
71
|
+
* is what {@link sequence} consumes, so a `Map` contributes values everywhere
|
|
72
|
+
* rather than `[key, value]` entries.
|
|
73
|
+
*/
|
|
74
|
+
export declare function values<T>(source: Iterable<T> | ReadonlyMap<unknown, T>): Iterable<T>;
|
|
75
|
+
/**
|
|
76
|
+
* Type guard for a {@link Container} - an iterable to be treated as a collection
|
|
77
|
+
* rather than a scalar.
|
|
78
|
+
*
|
|
79
|
+
* Deliberately excludes values that are technically iterable but should be
|
|
80
|
+
* treated as scalars here - strings, `String`/`RegExp` objects, and functions -
|
|
81
|
+
* so a lone string is never spread character-by-character.
|
|
82
|
+
*
|
|
83
|
+
* @typeParam T - Element type asserted for the iterable.
|
|
84
|
+
* @param value - Value to test.
|
|
85
|
+
* @returns `true` (narrowing `value` to {@link Container}<`T`>) for a non-string
|
|
86
|
+
* iterable.
|
|
87
|
+
*/
|
|
88
|
+
export declare function isContainer<T = unknown>(value: unknown): value is Container<T>;
|
|
89
|
+
/**
|
|
90
|
+
* Same semantics as `Array.prototype.map`, over a single {@link Container}.
|
|
91
|
+
*
|
|
92
|
+
* @param source - The container to map (nullish yields an empty sequence).
|
|
93
|
+
* @param callback - Called per element with its index; its result is emitted.
|
|
94
|
+
*/
|
|
95
|
+
export declare function map<T, U>(source: Source<T>, callback: (value: T, index: number) => U): Sequence<U>;
|
|
96
|
+
/**
|
|
97
|
+
* Same semantics as `Array.prototype.filter`, over a single {@link Container}.
|
|
98
|
+
* A type-guard predicate narrows the resulting element type.
|
|
99
|
+
*
|
|
100
|
+
* @param source - The container to filter (nullish yields an empty sequence).
|
|
101
|
+
* @param predicate - Keeps elements for which it returns `true`.
|
|
102
|
+
*/
|
|
103
|
+
export declare function filter<T, S extends T>(source: Source<T>, predicate: (value: T, index: number) => value is S): Sequence<S>;
|
|
104
|
+
export declare function filter<T>(source: Source<T>, predicate: (value: T, index: number) => boolean): Sequence<T>;
|
|
105
|
+
/**
|
|
106
|
+
* Concatenates the sources and yields only elements that are not `null` or
|
|
107
|
+
* `undefined`, narrowing the element type to {@link NonNullable}<`T`>.
|
|
108
|
+
*
|
|
109
|
+
* @param sources - Containers to concatenate (nullish sources are skipped).
|
|
110
|
+
*/
|
|
111
|
+
export declare function nonNull<T>(...sources: readonly Source<T>[]): Sequence<NonNullable<T>>;
|
|
112
|
+
/**
|
|
113
|
+
* Same semantics as `Array.prototype.flatMap`, over a single {@link Container}.
|
|
114
|
+
*
|
|
115
|
+
* @param source - The container to map (nullish yields an empty sequence).
|
|
116
|
+
* @param callback - Returns a value or array of values, flattened one level.
|
|
117
|
+
*/
|
|
118
|
+
export declare function flatMap<T, U>(source: Source<T>, callback: (value: T, index: number) => U | ReadonlyArray<U>): Sequence<U>;
|
|
119
|
+
/**
|
|
120
|
+
* Same semantics as `Array.prototype.flat` (arrays only). `depth` leads so the
|
|
121
|
+
* sources can stay variadic; use `depth < 1` for a no-op passthrough.
|
|
122
|
+
*
|
|
123
|
+
* @param depth - How many array levels to flatten.
|
|
124
|
+
* @param sources - Containers to concatenate, then flatten (nullish skipped).
|
|
125
|
+
*/
|
|
126
|
+
export declare function flat<T>(depth: number, ...sources: readonly Source<T>[]): Sequence<T>;
|
|
127
|
+
/**
|
|
128
|
+
* Concatenates the sources, then lazily yields values in encounter order,
|
|
129
|
+
* skipping a value only when an equal one was already yielded (`Set` /
|
|
130
|
+
* SameValueZero). Uniqueness is checked per element as it is consumed.
|
|
131
|
+
*
|
|
132
|
+
* @param sources - Containers to concatenate (nullish sources are skipped).
|
|
133
|
+
*/
|
|
134
|
+
export declare function distinct<T>(...sources: readonly Source<T>[]): Sequence<T>;
|
|
135
|
+
/**
|
|
136
|
+
* Yields `source`, then each appended `item` in order (arrays spread one level),
|
|
137
|
+
* mirroring `Array.prototype.concat`. `items` are scalar values/arrays, not
|
|
138
|
+
* containers, so `source` stays a single leading argument.
|
|
139
|
+
*
|
|
140
|
+
* @param source - The leading container (nullish yields just the items).
|
|
141
|
+
* @param items - Values (or arrays of values) appended after the source.
|
|
142
|
+
*/
|
|
143
|
+
export declare function concat<T>(source: Source<T>, ...items: readonly (T | ReadonlyArray<T>)[]): Sequence<T>;
|
|
144
|
+
/**
|
|
145
|
+
* Yields at most `count` elements from the front of the concatenated sources.
|
|
146
|
+
* `count` leads so the sources can stay variadic.
|
|
147
|
+
*
|
|
148
|
+
* @param count - Maximum number of elements to yield (`<= 0` yields none).
|
|
149
|
+
* @param sources - Containers to concatenate (nullish sources are skipped).
|
|
150
|
+
*/
|
|
151
|
+
export declare function take<T>(count: number, ...sources: readonly Source<T>[]): Sequence<T>;
|
|
152
|
+
/**
|
|
153
|
+
* Splits the concatenated sources into one array per named predicate. Consumes
|
|
154
|
+
* the input once, routing each element to the FIRST predicate it satisfies (so
|
|
155
|
+
* groups are disjoint); elements matching no predicate are dropped. Type-guard
|
|
156
|
+
* predicates narrow their group's element type (see {@link GroupValue}).
|
|
157
|
+
* `predicates` leads so the sources can stay variadic.
|
|
158
|
+
*
|
|
159
|
+
* @typeParam G - The map of group name -> predicate.
|
|
160
|
+
* @param predicates - Named predicates; evaluated in declaration order.
|
|
161
|
+
* @param sources - Containers to concatenate (nullish sources are skipped).
|
|
162
|
+
* @returns An object with the same keys, each an array of its group's elements.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* const { strings, fns } = group({ strings: isString, fns: isFunction }, xs);
|
|
166
|
+
*/
|
|
167
|
+
export declare function group<T, G extends GroupPredicates<T>>(predicates: G, ...sources: readonly Source<T>[]): {
|
|
168
|
+
[K in keyof G]: GroupValue<T, G[K]>[];
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* Same semantics as `Array.prototype.find`, over a single {@link Container}.
|
|
172
|
+
* Consumes elements until a match. A type guard narrows the return type.
|
|
173
|
+
*/
|
|
174
|
+
export declare function find<T, S extends T>(source: Source<T>, predicate: (value: T, index: number) => value is S): S | undefined;
|
|
175
|
+
export declare function find<T>(source: Source<T>, predicate: (value: T, index: number) => boolean): T | undefined;
|
|
176
|
+
/**
|
|
177
|
+
* Same semantics as `Array.prototype.findLast`, over a single {@link Container}.
|
|
178
|
+
* Consumes the full source. A type guard narrows the return type.
|
|
179
|
+
*/
|
|
180
|
+
export declare function findLast<T, S extends T>(source: Source<T>, predicate: (value: T, index: number) => value is S): S | undefined;
|
|
181
|
+
export declare function findLast<T>(source: Source<T>, predicate: (value: T, index: number) => boolean): T | undefined;
|
|
182
|
+
/**
|
|
183
|
+
* Same semantics as `Array.prototype.findIndex`, over a single {@link Container}.
|
|
184
|
+
* Consumes elements until a match.
|
|
185
|
+
*/
|
|
186
|
+
export declare function findIndex<T>(source: Source<T>, predicate: (value: T, index: number) => boolean): number;
|
|
187
|
+
/**
|
|
188
|
+
* Same semantics as `Array.prototype.findLastIndex`, over a single
|
|
189
|
+
* {@link Container}. Consumes the full source.
|
|
190
|
+
*/
|
|
191
|
+
export declare function findLastIndex<T>(source: Source<T>, predicate: (value: T, index: number) => boolean): number;
|
|
192
|
+
/**
|
|
193
|
+
* Same semantics as `Array.prototype.some`, over a single {@link Container}.
|
|
194
|
+
* Short-circuits on the first match.
|
|
195
|
+
*/
|
|
196
|
+
export declare function some<T>(source: Source<T>, predicate: (value: T, index: number) => boolean): boolean;
|
|
197
|
+
/**
|
|
198
|
+
* Same semantics as `Array.prototype.every`, over a single {@link Container}.
|
|
199
|
+
* Short-circuits on the first failure.
|
|
200
|
+
*/
|
|
201
|
+
export declare function every<T, S extends T>(source: Source<T>, predicate: (value: T, index: number) => value is S): boolean;
|
|
202
|
+
export declare function every<T>(source: Source<T>, predicate: (value: T, index: number) => boolean): boolean;
|
|
203
|
+
/**
|
|
204
|
+
* Same semantics as `Array.prototype.forEach`, over a single {@link Container}.
|
|
205
|
+
* Consumes the source.
|
|
206
|
+
*/
|
|
207
|
+
export declare function forEach<T>(source: Source<T>, callback: (value: T, index: number) => void): void;
|
|
208
|
+
/**
|
|
209
|
+
* Same semantics as `Array.prototype.at` over the concatenated sources.
|
|
210
|
+
* Non-negative indices scan lazily; negative indices materialize first. `index`
|
|
211
|
+
* leads so the sources can stay variadic.
|
|
212
|
+
*
|
|
213
|
+
* @param index - Zero-based position; negative counts from the end.
|
|
214
|
+
* @param sources - Containers to concatenate (nullish sources are skipped).
|
|
215
|
+
*/
|
|
216
|
+
export declare function at<T>(index: number, ...sources: readonly Source<T>[]): T | undefined;
|
|
217
|
+
export declare function toOneOrMany<T>(input: T | OneOrMany<T>): OneOrMany<T>;
|
|
218
|
+
/**
|
|
219
|
+
* Materializes the concatenated sources into a new array. Consumes single-pass
|
|
220
|
+
* sources.
|
|
221
|
+
*
|
|
222
|
+
* @param sources - Containers to concatenate (nullish sources are skipped).
|
|
223
|
+
*/
|
|
224
|
+
export declare function toArray<T>(...sources: readonly Source<T>[]): readonly T[];
|
|
225
|
+
/**
|
|
226
|
+
* Lazy iterable sequence with `Array`-compatible transforms and terminal
|
|
227
|
+
* methods. Single-pass by default; call {@link SequenceImpl.cache} to retain
|
|
228
|
+
* pulled values for re-iteration. Built for generators and other sources where
|
|
229
|
+
* a second pass is not guaranteed.
|
|
230
|
+
*
|
|
231
|
+
* The methods forward to the standalone functions of the same name - see each
|
|
232
|
+
* method's `@see` - so the free-function and chained styles share one impl.
|
|
233
|
+
*/
|
|
234
|
+
declare class SequenceImpl<T> {
|
|
235
|
+
private readonly source;
|
|
236
|
+
private readonly buffer;
|
|
237
|
+
private iterator?;
|
|
238
|
+
private exhausted;
|
|
239
|
+
constructor(source: Iterable<T>, buffer: T[] | undefined, state?: {
|
|
240
|
+
readonly exhausted?: boolean;
|
|
241
|
+
});
|
|
242
|
+
private get caching();
|
|
243
|
+
/** Advance the underlying source once, creating the iterator on first use. */
|
|
244
|
+
private pull;
|
|
245
|
+
[Symbol.iterator](): Iterator<T>;
|
|
246
|
+
/** @see {@link map} */
|
|
247
|
+
map<U>(callback: (value: T, index: number) => U): Sequence<U>;
|
|
248
|
+
/** @see {@link filter} */
|
|
249
|
+
filter<S extends T>(predicate: (value: T, index: number) => value is S): Sequence<S>;
|
|
250
|
+
filter(predicate: (value: T, index: number) => boolean): Sequence<T>;
|
|
251
|
+
/** @see {@link nonNull} */
|
|
252
|
+
nonNull(): Sequence<NonNullable<T>>;
|
|
253
|
+
/** @see {@link flatMap} */
|
|
254
|
+
flatMap<U>(callback: (value: T, index: number) => U | ReadonlyArray<U>): Sequence<U>;
|
|
255
|
+
/** @see {@link flat} */
|
|
256
|
+
flat(depth?: number): Sequence<T>;
|
|
257
|
+
/** @see {@link distinct} */
|
|
258
|
+
distinct(): Sequence<T>;
|
|
259
|
+
/** @see {@link concat} */
|
|
260
|
+
concat(...items: readonly (T | ReadonlyArray<T>)[]): Sequence<T>;
|
|
261
|
+
/**
|
|
262
|
+
* Lazily yields this sequence followed by each iterable `source` in order.
|
|
263
|
+
* Like {@link concat}, but for iterable sources (generators, other sequences,
|
|
264
|
+
* `Set`, `Map`, etc.) rather than scalar values or arrays. A {@link Map}
|
|
265
|
+
* source contributes its values.
|
|
266
|
+
*
|
|
267
|
+
* @see {@link sequence}
|
|
268
|
+
*/
|
|
269
|
+
join(...sources: readonly SequenceSource<T>[]): Sequence<T>;
|
|
270
|
+
/** @see {@link take} */
|
|
271
|
+
take(count: number): Sequence<T>;
|
|
272
|
+
/** @see {@link group} */
|
|
273
|
+
group<G extends GroupPredicates<T>>(predicates: G): {
|
|
274
|
+
[K in keyof G]: GroupValue<T, G[K]>[];
|
|
275
|
+
};
|
|
276
|
+
/**
|
|
277
|
+
* Returns a cached, re-iterable view of this sequence. An already-caching
|
|
278
|
+
* sequence returns itself; otherwise this one-pass sequence is wrapped in a
|
|
279
|
+
* new instance that retains pulled values. Iterate the returned instance, not
|
|
280
|
+
* the original, to avoid competing for the same single-pass source.
|
|
281
|
+
*/
|
|
282
|
+
cache(): Sequence<T>;
|
|
283
|
+
/** @see {@link find} */
|
|
284
|
+
find<S extends T>(predicate: (value: T, index: number) => value is S): S | undefined;
|
|
285
|
+
find(predicate: (value: T, index: number) => boolean): T | undefined;
|
|
286
|
+
/** @see {@link findLast} */
|
|
287
|
+
findLast<S extends T>(predicate: (value: T, index: number) => value is S): S | undefined;
|
|
288
|
+
findLast(predicate: (value: T, index: number) => boolean): T | undefined;
|
|
289
|
+
/** @see {@link findIndex} */
|
|
290
|
+
findIndex(predicate: (value: T, index: number) => boolean): number;
|
|
291
|
+
/** @see {@link findLastIndex} */
|
|
292
|
+
findLastIndex(predicate: (value: T, index: number) => boolean): number;
|
|
293
|
+
/** @see {@link some} */
|
|
294
|
+
some(predicate: (value: T, index: number) => boolean): boolean;
|
|
295
|
+
/** @see {@link every} (the `S extends T` overload narrows at compile time only). */
|
|
296
|
+
every<S extends T>(predicate: (value: T, index: number) => value is S): this is Sequence<S>;
|
|
297
|
+
every(predicate: (value: T, index: number) => boolean): boolean;
|
|
298
|
+
/** @see {@link forEach} */
|
|
299
|
+
forEach(callback: (value: T, index: number) => void): void;
|
|
300
|
+
/** @see {@link at} */
|
|
301
|
+
at(index: number): T | undefined;
|
|
302
|
+
/**
|
|
303
|
+
* Materialize the sequence into a new array. Consumes a single-pass source; a
|
|
304
|
+
* cached, exhausted sequence copies its buffer directly.
|
|
305
|
+
*
|
|
306
|
+
* @see {@link toArray}
|
|
307
|
+
*/
|
|
308
|
+
toArray(): readonly T[];
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Wrap one or more iterable `sources` in a single lazy {@link Sequence},
|
|
312
|
+
* iterated in order. `null`/`undefined` sources are skipped; when nothing
|
|
313
|
+
* remains (every source omitted, `null`, `undefined`, or an empty array /
|
|
314
|
+
* `Set` / `Map`), {@link emptySequence} is returned. The result is single-pass
|
|
315
|
+
* - call `.cache()` to make it re-iterable.
|
|
316
|
+
*
|
|
317
|
+
* A {@link Map} source contributes its values (see {@link values}), consistent
|
|
318
|
+
* with {@link Collection}'s value-typed `T`.
|
|
319
|
+
*
|
|
320
|
+
* @typeParam T - Element type of the sequence.
|
|
321
|
+
* @param sources - Iterables to concatenate, in order (`Map` sources use values).
|
|
322
|
+
*/
|
|
323
|
+
export declare function sequence<T>(...sources: readonly SequenceSource<T>[]): Sequence<T>;
|
|
324
|
+
/**
|
|
325
|
+
* Flattens a mix of single items and iterables into one lazy {@link Generator}.
|
|
326
|
+
*
|
|
327
|
+
* Arguments are emitted in order: `null`/`undefined` are skipped, non-string
|
|
328
|
+
* iterables (per {@link isContainer}) are yielded element-by-element, and
|
|
329
|
+
* anything else (including strings) is yielded as a single item.
|
|
330
|
+
*
|
|
331
|
+
* @typeParam T - Element type produced by the generator.
|
|
332
|
+
* @param items - Items and/or iterables to flatten, in order.
|
|
333
|
+
* @returns A generator over the flattened elements.
|
|
334
|
+
*/
|
|
335
|
+
export declare function generator<T>(...items: readonly (T | Iterable<T> | null | undefined)[]): Generator<T>;
|
|
336
|
+
/** Minimal shape for objects that expose an optional `name` (e.g. AppKit plugins). */
|
|
337
|
+
export interface NameLike {
|
|
338
|
+
name?: string;
|
|
339
|
+
}
|
|
340
|
+
export type NonFunctionKeys<T> = {
|
|
341
|
+
[K in keyof T]: T[K] extends (...args: any[]) => any ? never : K;
|
|
342
|
+
}[keyof T];
|
|
343
|
+
/**
|
|
344
|
+
* Narrow `value` to a plain (non-array) object. Use as a type guard
|
|
345
|
+
* before indexing into / mutating parsed JSON so the access is
|
|
346
|
+
* type-safe.
|
|
347
|
+
*
|
|
348
|
+
* @example
|
|
349
|
+
* if (isRecord(parsed)) parsed.foo = 1;
|
|
350
|
+
*/
|
|
351
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
352
|
+
/**
|
|
353
|
+
* Coerce a loose boolean-ish value to a real `boolean`, or `undefined`
|
|
354
|
+
* when it can't be interpreted. Recognizes `true`/`t`/`on`/`1`/`yes`/`y`
|
|
355
|
+
* and their negatives (case- and whitespace-insensitive for strings), as
|
|
356
|
+
* well as the numbers `1` and `0`.
|
|
357
|
+
*/
|
|
358
|
+
export declare function toBoolean(value: unknown): boolean | undefined;
|
|
359
|
+
/**
|
|
360
|
+
* Structural deep-equality with an optional custom comparator.
|
|
361
|
+
*
|
|
362
|
+
* {@link deepEqual} mirrors the semantics of the `fast-deep-equal`
|
|
363
|
+
* package (handled: nested plain objects/arrays, `Map`, `Set`, `Date`,
|
|
364
|
+
* `RegExp`, typed arrays, `NaN`, and `+0`/`-0` treated as equal) but is
|
|
365
|
+
* dependency-free so `@dbx-tools/shared-core` keeps no runtime deps.
|
|
366
|
+
*
|
|
367
|
+
* The optional `comparator` short-circuits the structural walk at any
|
|
368
|
+
* node: return `true`/`false` to force the result for that pair, or
|
|
369
|
+
* `undefined` to defer to the built-in comparison. It is invoked for the
|
|
370
|
+
* root pair and recursively for each nested pair, so a caller can, e.g.,
|
|
371
|
+
* compare two domain objects by id while letting everything else fall
|
|
372
|
+
* back to structural equality.
|
|
373
|
+
*
|
|
374
|
+
* @example
|
|
375
|
+
* deepEqual({ a: 1 }, { a: 1 }); // true
|
|
376
|
+
* deepEqual([1, 2], [1, 2]); // true
|
|
377
|
+
* deepEqual(a, b, (x, y) =>
|
|
378
|
+
* isEntity(x) && isEntity(y) ? x.id === y.id : undefined);
|
|
379
|
+
*/
|
|
380
|
+
export type DeepEqualComparator = (a: unknown, b: unknown) => boolean | undefined;
|
|
381
|
+
export declare function deepEqual(a: unknown, b: unknown, comparator?: DeepEqualComparator): boolean;
|
|
382
|
+
export {};
|