umsizi 0.7.0 → 0.9.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/dist/index.d.ts +137 -1
- package/dist/index.js +165 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -41,6 +41,22 @@ type PartitionedValues<T extends object, S extends T[StringKeyOf<T>]> = readonly
|
|
|
41
41
|
type PartitionedObject<T extends object> = readonly [Partial<{ [K in StringKeyOf<T>]: T[K] }>, Partial<{ [K in StringKeyOf<T>]: T[K] }>];
|
|
42
42
|
type CompactedObject<T extends object> = Partial<{ [K in StringKeyOf<T>]: Exclude<T[K], null | undefined> }>;
|
|
43
43
|
type InvertedObject<T extends Record<string, PropertyKey>> = { [K in StringKeyOf<T> as T[K]]: K };
|
|
44
|
+
type Validator<T> = (value: unknown) => value is T;
|
|
45
|
+
type ObjectSchema = Record<string, Validator<unknown>>;
|
|
46
|
+
type SchemaValue<T> = T extends Validator<infer U> ? U : never;
|
|
47
|
+
type InferSchema<T extends ObjectSchema> = { [K in keyof T]: SchemaValue<T[K]> };
|
|
48
|
+
type GroupedByKey<T extends object, K$1 extends keyof T> = Partial<Record<Extract<T[K$1], PropertyKey>, Array<T>>>;
|
|
49
|
+
type IndexedByKey<T extends object, K$1 extends keyof T> = Partial<Record<Extract<T[K$1], PropertyKey>, T>>;
|
|
50
|
+
type KeyMatch<K$1 extends PropertyKey, L, R> = {
|
|
51
|
+
key: K$1;
|
|
52
|
+
left: L;
|
|
53
|
+
right: R;
|
|
54
|
+
};
|
|
55
|
+
type Simplify<T> = { [K in keyof T]: T[K] } & {};
|
|
56
|
+
type WithDefault<T, D> = undefined extends T ? Exclude<T, undefined> | D : T;
|
|
57
|
+
type MergeDefaultValue<T, D> = T extends readonly unknown[] ? WithDefault<T, D> : T extends object ? D extends object ? MergeDefaulted<T, D> : WithDefault<T, D> : WithDefault<T, D>;
|
|
58
|
+
type Defaulted<T extends object, D extends object> = Simplify<{ [K in keyof T | keyof D]: K extends keyof T ? K extends keyof D ? WithDefault<T[K], D[K]> : T[K] : K extends keyof D ? D[K] : never }>;
|
|
59
|
+
type MergeDefaulted<T extends object, D extends object> = Simplify<{ [K in keyof T | keyof D]: K extends keyof T ? K extends keyof D ? MergeDefaultValue<T[K], D[K]> : T[K] : K extends keyof D ? D[K] : never }>;
|
|
44
60
|
type PathValueAtSegment<T, K$1 extends PathSegment> = K$1 extends keyof T ? T[K$1] : K$1 extends number ? T extends readonly (infer U)[] ? U : T extends (infer U)[] ? U : never : never;
|
|
45
61
|
type PathValue<T, P extends ObjectPath> = P extends readonly [] ? T : P extends readonly [infer Head extends PathSegment, ...infer Tail extends ObjectPath] ? PathValueAtSegment<T, Head> extends never ? never : PathValue<PathValueAtSegment<T, Head>, Tail> : never;
|
|
46
62
|
//#endregion
|
|
@@ -59,6 +75,15 @@ type PathValue<T, P extends ObjectPath> = P extends readonly [] ? T : P extends
|
|
|
59
75
|
*/
|
|
60
76
|
declare function compactObject<T extends object>(object: T): CompactedObject<T>;
|
|
61
77
|
//#endregion
|
|
78
|
+
//#region src/core/defaults.d.ts
|
|
79
|
+
/**
|
|
80
|
+
* Creates a new object by filling missing or `undefined` properties from a
|
|
81
|
+
* defaults object.
|
|
82
|
+
*
|
|
83
|
+
* `null`, `false`, `0`, and other defined values are preserved as-is.
|
|
84
|
+
*/
|
|
85
|
+
declare function defaults<T extends object, D extends object>(object: T, defaultValues: D): Defaulted<T, D>;
|
|
86
|
+
//#endregion
|
|
62
87
|
//#region src/core/filter-keys.d.ts
|
|
63
88
|
/**
|
|
64
89
|
* Filters an object's own enumerable string-keyed properties by key.
|
|
@@ -112,6 +137,25 @@ declare function get<T, const P extends ObjectPath, D>(object: T, path: P, defau
|
|
|
112
137
|
declare function get<T>(object: T, path: string): unknown;
|
|
113
138
|
declare function get<T, D>(object: T, path: string, defaultValue: D): D | unknown;
|
|
114
139
|
//#endregion
|
|
140
|
+
//#region src/core/group-by-key.d.ts
|
|
141
|
+
/**
|
|
142
|
+
* Groups items by a property whose value can be used as an object key.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* groupByKey(
|
|
147
|
+
* [
|
|
148
|
+
* { id: "1", role: "admin" },
|
|
149
|
+
* { id: "2", role: "member" },
|
|
150
|
+
* { id: "3", role: "admin" },
|
|
151
|
+
* ],
|
|
152
|
+
* "role",
|
|
153
|
+
* );
|
|
154
|
+
* // { admin: [...], member: [...] }
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
declare function groupByKey<T extends object, K$1 extends keyof T>(items: ReadonlyArray<T>, key: K$1): GroupedByKey<T, K$1>;
|
|
158
|
+
//#endregion
|
|
115
159
|
//#region src/core/has-keys.d.ts
|
|
116
160
|
/**
|
|
117
161
|
* Checks whether a plain object has all of the requested own keys.
|
|
@@ -172,6 +216,26 @@ declare function hasPath(object: unknown, pathInput: PathInput): boolean;
|
|
|
172
216
|
*/
|
|
173
217
|
declare function identity<T>(value: T): T;
|
|
174
218
|
//#endregion
|
|
219
|
+
//#region src/core/index-by-key.d.ts
|
|
220
|
+
/**
|
|
221
|
+
* Indexes items by a property whose value can be used as an object key.
|
|
222
|
+
*
|
|
223
|
+
* Later items overwrite earlier items with the same key.
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```ts
|
|
227
|
+
* indexByKey(
|
|
228
|
+
* [
|
|
229
|
+
* { id: "1", name: "Ada" },
|
|
230
|
+
* { id: "2", name: "Linus" },
|
|
231
|
+
* ],
|
|
232
|
+
* "id",
|
|
233
|
+
* );
|
|
234
|
+
* // { 1: { ... }, 2: { ... } }
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
declare function indexByKey<T extends object, K$1 extends keyof T>(items: ReadonlyArray<T>, key: K$1): IndexedByKey<T, K$1>;
|
|
238
|
+
//#endregion
|
|
175
239
|
//#region src/core/invert-object.d.ts
|
|
176
240
|
/**
|
|
177
241
|
* Inverts an object's own enumerable string-keyed properties.
|
|
@@ -255,6 +319,35 @@ declare function mapKeys<T extends object, R extends string>(object: T, mapper:
|
|
|
255
319
|
*/
|
|
256
320
|
declare function mapValues<T extends object, R>(object: T, mapper: ValueMapper<T, R>): MappedValues<T, R>;
|
|
257
321
|
//#endregion
|
|
322
|
+
//#region src/core/match-by-key.d.ts
|
|
323
|
+
/**
|
|
324
|
+
* Matches items from two arrays when their key values are equal.
|
|
325
|
+
*
|
|
326
|
+
* Supports either the same key on both sides or separate left/right keys.
|
|
327
|
+
*
|
|
328
|
+
* @example
|
|
329
|
+
* ```ts
|
|
330
|
+
* matchByKey(
|
|
331
|
+
* [{ id: "1", name: "Ada" }],
|
|
332
|
+
* [{ userId: "1", status: "active" }],
|
|
333
|
+
* "id",
|
|
334
|
+
* "userId",
|
|
335
|
+
* );
|
|
336
|
+
* // [{ key: "1", left: { ... }, right: { ... } }]
|
|
337
|
+
* ```
|
|
338
|
+
*/
|
|
339
|
+
declare function matchByKey<L extends object, R extends object, K$1 extends keyof L & keyof R>(leftItems: ReadonlyArray<L>, rightItems: ReadonlyArray<R>, key: K$1): Array<KeyMatch<Extract<L[K$1] & R[K$1], PropertyKey>, L, R>>;
|
|
340
|
+
declare function matchByKey<L extends object, R extends object, LK extends keyof L, RK extends keyof R>(leftItems: ReadonlyArray<L>, rightItems: ReadonlyArray<R>, leftKey: LK, rightKey: RK): Array<KeyMatch<Extract<L[LK] & R[RK], PropertyKey>, L, R>>;
|
|
341
|
+
//#endregion
|
|
342
|
+
//#region src/core/merge-defaults.d.ts
|
|
343
|
+
/**
|
|
344
|
+
* Recursively fills missing or `undefined` properties from a defaults object.
|
|
345
|
+
*
|
|
346
|
+
* Only plain objects are merged deeply. Arrays and other object-like values are
|
|
347
|
+
* treated as leaf values.
|
|
348
|
+
*/
|
|
349
|
+
declare function mergeDefaults<T extends object, D extends object>(object: T, defaultValues: D): MergeDefaulted<T, D>;
|
|
350
|
+
//#endregion
|
|
258
351
|
//#region src/core/omit.d.ts
|
|
259
352
|
/**
|
|
260
353
|
* Creates a new object excluding the selected own enumerable properties.
|
|
@@ -273,6 +366,22 @@ declare function omit<T extends object, const Keys extends readonly (keyof T)[]>
|
|
|
273
366
|
declare function omit<T extends object, const FirstKey extends keyof T, const RestKeys extends readonly (keyof T)[]>(object: T, keys: readonly [FirstKey, ...RestKeys]): Omit<T, FirstKey | RestKeys[number]>;
|
|
274
367
|
declare function omit<T extends object>(object: T, keys: readonly (keyof T)[]): Partial<T>;
|
|
275
368
|
//#endregion
|
|
369
|
+
//#region src/core/parse-object.d.ts
|
|
370
|
+
/**
|
|
371
|
+
* Parses an unknown value as a typed object by validating it against a schema.
|
|
372
|
+
*
|
|
373
|
+
* Throws a `TypeError` when validation fails.
|
|
374
|
+
*
|
|
375
|
+
* @example
|
|
376
|
+
* ```ts
|
|
377
|
+
* const user = parseObject(payload, schema({
|
|
378
|
+
* id: (value): value is string => typeof value === "string",
|
|
379
|
+
* active: (value): value is boolean => typeof value === "boolean",
|
|
380
|
+
* }));
|
|
381
|
+
* ```
|
|
382
|
+
*/
|
|
383
|
+
declare function parseObject<const T extends ObjectSchema>(value: unknown, definition: T): InferSchema<T>;
|
|
384
|
+
//#endregion
|
|
276
385
|
//#region src/core/partition-object.d.ts
|
|
277
386
|
/**
|
|
278
387
|
* Partitions an object's own enumerable string-keyed properties into matching
|
|
@@ -415,5 +524,32 @@ declare function typedFromEntries<const T extends EntryTuples>(entries: T): Obje
|
|
|
415
524
|
*/
|
|
416
525
|
declare function typedKeys<T extends object>(object: T): Array<StringKeyOf<T>>;
|
|
417
526
|
//#endregion
|
|
418
|
-
|
|
527
|
+
//#region src/core/validate-object.d.ts
|
|
528
|
+
/**
|
|
529
|
+
* Validates an unknown value against a schema of field validators.
|
|
530
|
+
*
|
|
531
|
+
* All schema keys must exist as own properties on the input object and every
|
|
532
|
+
* field validator must accept its corresponding value.
|
|
533
|
+
*
|
|
534
|
+
* @example
|
|
535
|
+
* ```ts
|
|
536
|
+
* const isUser = validateObject(
|
|
537
|
+
* { id: "usr_1", active: true },
|
|
538
|
+
* schema({
|
|
539
|
+
* id: (value): value is string => typeof value === "string",
|
|
540
|
+
* active: (value): value is boolean => typeof value === "boolean",
|
|
541
|
+
* }),
|
|
542
|
+
* );
|
|
543
|
+
* ```
|
|
544
|
+
*/
|
|
545
|
+
declare function validateObject<const T extends ObjectSchema>(value: unknown, definition: T): value is InferSchema<T>;
|
|
546
|
+
//#endregion
|
|
547
|
+
//#region src/core/with-defaults.d.ts
|
|
548
|
+
type DefaultsApplicator<D extends object> = <T extends object>(object: T) => MergeDefaulted<T, D>;
|
|
549
|
+
/**
|
|
550
|
+
* Creates a reusable function that applies the provided defaults.
|
|
551
|
+
*/
|
|
552
|
+
declare function withDefaults<D extends object>(defaultValues: D): DefaultsApplicator<D>;
|
|
553
|
+
//#endregion
|
|
554
|
+
export { assertKeys, compactObject, defaults, filterKeys, filterValues, get, groupByKey, hasKeys, hasOwn, hasPath, identity, identity as schema, indexByKey, invertObject, isEmpty, isPlainObject, isPlainObject as isRecord, mapKeys, mapValues, matchByKey, mergeDefaults, omit, parseObject, partitionObject, path, pick, renameKeys, requireKeys, set, typedEntries, typedFromEntries, typedKeys, validateObject, withDefaults };
|
|
419
555
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -72,6 +72,20 @@ function compactObject(object) {
|
|
|
72
72
|
return result;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/core/defaults.ts
|
|
77
|
+
/**
|
|
78
|
+
* Creates a new object by filling missing or `undefined` properties from a
|
|
79
|
+
* defaults object.
|
|
80
|
+
*
|
|
81
|
+
* `null`, `false`, `0`, and other defined values are preserved as-is.
|
|
82
|
+
*/
|
|
83
|
+
function defaults(object, defaultValues) {
|
|
84
|
+
const result = { ...object };
|
|
85
|
+
for (const key of typedKeys(defaultValues)) if (result[key] === void 0) result[key] = defaultValues[key];
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
|
|
75
89
|
//#endregion
|
|
76
90
|
//#region src/core/filter-keys.ts
|
|
77
91
|
function filterKeys(object, predicate) {
|
|
@@ -155,6 +169,38 @@ function get(object, pathInput, defaultValue) {
|
|
|
155
169
|
return current;
|
|
156
170
|
}
|
|
157
171
|
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region src/core/group-by-key.ts
|
|
174
|
+
/**
|
|
175
|
+
* Groups items by a property whose value can be used as an object key.
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* groupByKey(
|
|
180
|
+
* [
|
|
181
|
+
* { id: "1", role: "admin" },
|
|
182
|
+
* { id: "2", role: "member" },
|
|
183
|
+
* { id: "3", role: "admin" },
|
|
184
|
+
* ],
|
|
185
|
+
* "role",
|
|
186
|
+
* );
|
|
187
|
+
* // { admin: [...], member: [...] }
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
function groupByKey(items, key) {
|
|
191
|
+
const result = {};
|
|
192
|
+
for (const item of items) {
|
|
193
|
+
const groupKey = item[key];
|
|
194
|
+
const existing = result[groupKey];
|
|
195
|
+
if (existing) {
|
|
196
|
+
existing.push(item);
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
result[groupKey] = [item];
|
|
200
|
+
}
|
|
201
|
+
return result;
|
|
202
|
+
}
|
|
203
|
+
|
|
158
204
|
//#endregion
|
|
159
205
|
//#region src/core/has-path.ts
|
|
160
206
|
/**
|
|
@@ -189,6 +235,31 @@ function identity(value) {
|
|
|
189
235
|
return value;
|
|
190
236
|
}
|
|
191
237
|
|
|
238
|
+
//#endregion
|
|
239
|
+
//#region src/core/index-by-key.ts
|
|
240
|
+
/**
|
|
241
|
+
* Indexes items by a property whose value can be used as an object key.
|
|
242
|
+
*
|
|
243
|
+
* Later items overwrite earlier items with the same key.
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```ts
|
|
247
|
+
* indexByKey(
|
|
248
|
+
* [
|
|
249
|
+
* { id: "1", name: "Ada" },
|
|
250
|
+
* { id: "2", name: "Linus" },
|
|
251
|
+
* ],
|
|
252
|
+
* "id",
|
|
253
|
+
* );
|
|
254
|
+
* // { 1: { ... }, 2: { ... } }
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
function indexByKey(items, key) {
|
|
258
|
+
const result = {};
|
|
259
|
+
for (const item of items) result[item[key]] = item;
|
|
260
|
+
return result;
|
|
261
|
+
}
|
|
262
|
+
|
|
192
263
|
//#endregion
|
|
193
264
|
//#region src/core/invert-object.ts
|
|
194
265
|
/**
|
|
@@ -303,6 +374,42 @@ function mapValues(object, mapper) {
|
|
|
303
374
|
return result;
|
|
304
375
|
}
|
|
305
376
|
|
|
377
|
+
//#endregion
|
|
378
|
+
//#region src/core/match-by-key.ts
|
|
379
|
+
function matchByKey(leftItems, rightItems, leftKey, rightKey) {
|
|
380
|
+
const rightIndex = groupByKey(rightItems, rightKey ?? leftKey);
|
|
381
|
+
const matches = [];
|
|
382
|
+
for (const left of leftItems) {
|
|
383
|
+
const key = left[leftKey];
|
|
384
|
+
const matchingRights = rightIndex[key];
|
|
385
|
+
if (!matchingRights) continue;
|
|
386
|
+
for (const right of matchingRights) matches.push({
|
|
387
|
+
key,
|
|
388
|
+
left,
|
|
389
|
+
right
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
return matches;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
//#endregion
|
|
396
|
+
//#region src/core/merge-defaults.ts
|
|
397
|
+
/**
|
|
398
|
+
* Recursively fills missing or `undefined` properties from a defaults object.
|
|
399
|
+
*
|
|
400
|
+
* Only plain objects are merged deeply. Arrays and other object-like values are
|
|
401
|
+
* treated as leaf values.
|
|
402
|
+
*/
|
|
403
|
+
function mergeDefaults(object, defaultValues) {
|
|
404
|
+
const result = { ...object };
|
|
405
|
+
for (const key of typedKeys(defaultValues)) {
|
|
406
|
+
const value = result[key];
|
|
407
|
+
const fallback = defaultValues[key];
|
|
408
|
+
result[key] = value === void 0 ? fallback : isPlainObject(value) && isPlainObject(fallback) ? mergeDefaults(value, fallback) : value;
|
|
409
|
+
}
|
|
410
|
+
return result;
|
|
411
|
+
}
|
|
412
|
+
|
|
306
413
|
//#endregion
|
|
307
414
|
//#region src/core/omit.ts
|
|
308
415
|
function omit(object, firstKeyOrKeys, ...restKeys) {
|
|
@@ -313,6 +420,54 @@ function omit(object, firstKeyOrKeys, ...restKeys) {
|
|
|
313
420
|
return result;
|
|
314
421
|
}
|
|
315
422
|
|
|
423
|
+
//#endregion
|
|
424
|
+
//#region src/core/validate-object.ts
|
|
425
|
+
/**
|
|
426
|
+
* Validates an unknown value against a schema of field validators.
|
|
427
|
+
*
|
|
428
|
+
* All schema keys must exist as own properties on the input object and every
|
|
429
|
+
* field validator must accept its corresponding value.
|
|
430
|
+
*
|
|
431
|
+
* @example
|
|
432
|
+
* ```ts
|
|
433
|
+
* const isUser = validateObject(
|
|
434
|
+
* { id: "usr_1", active: true },
|
|
435
|
+
* schema({
|
|
436
|
+
* id: (value): value is string => typeof value === "string",
|
|
437
|
+
* active: (value): value is boolean => typeof value === "boolean",
|
|
438
|
+
* }),
|
|
439
|
+
* );
|
|
440
|
+
* ```
|
|
441
|
+
*/
|
|
442
|
+
function validateObject(value, definition) {
|
|
443
|
+
if (!isPlainObject(value)) return false;
|
|
444
|
+
for (const key of typedKeys(definition)) {
|
|
445
|
+
if (!hasOwn(value, key)) return false;
|
|
446
|
+
if (!definition[key](value[key])) return false;
|
|
447
|
+
}
|
|
448
|
+
return true;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
//#endregion
|
|
452
|
+
//#region src/core/parse-object.ts
|
|
453
|
+
/**
|
|
454
|
+
* Parses an unknown value as a typed object by validating it against a schema.
|
|
455
|
+
*
|
|
456
|
+
* Throws a `TypeError` when validation fails.
|
|
457
|
+
*
|
|
458
|
+
* @example
|
|
459
|
+
* ```ts
|
|
460
|
+
* const user = parseObject(payload, schema({
|
|
461
|
+
* id: (value): value is string => typeof value === "string",
|
|
462
|
+
* active: (value): value is boolean => typeof value === "boolean",
|
|
463
|
+
* }));
|
|
464
|
+
* ```
|
|
465
|
+
*/
|
|
466
|
+
function parseObject(value, definition) {
|
|
467
|
+
if (validateObject(value, definition)) return value;
|
|
468
|
+
throw new TypeError("Invalid object.");
|
|
469
|
+
}
|
|
470
|
+
|
|
316
471
|
//#endregion
|
|
317
472
|
//#region src/core/partition-object.ts
|
|
318
473
|
function partitionObject(object, predicate) {
|
|
@@ -437,5 +592,14 @@ function typedFromEntries(entries) {
|
|
|
437
592
|
}
|
|
438
593
|
|
|
439
594
|
//#endregion
|
|
440
|
-
|
|
595
|
+
//#region src/core/with-defaults.ts
|
|
596
|
+
/**
|
|
597
|
+
* Creates a reusable function that applies the provided defaults.
|
|
598
|
+
*/
|
|
599
|
+
function withDefaults(defaultValues) {
|
|
600
|
+
return (object) => mergeDefaults(object, defaultValues);
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
//#endregion
|
|
604
|
+
export { assertKeys, compactObject, defaults, filterKeys, filterValues, get, groupByKey, hasKeys, hasOwn, hasPath, identity, identity as schema, indexByKey, invertObject, isEmpty, isPlainObject, isPlainObject as isRecord, mapKeys, mapValues, matchByKey, mergeDefaults, omit, parseObject, partitionObject, path, pick, renameKeys, requireKeys, set, typedEntries, typedFromEntries, typedKeys, validateObject, withDefaults };
|
|
441
605
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["missingKeys: Array<keyof T>","segments: PathSegment[]","toPath","current: unknown","toPath","result: Partial<T>","result: Partial<T>","toPath"],"sources":["../src/core/has-keys.ts","../src/core/require-keys.ts","../src/core/assert-keys.ts","../src/core/typed-keys.ts","../src/core/compact-object.ts","../src/core/filter-keys.ts","../src/core/filter-values.ts","../src/core/has-own.ts","../src/core/path.ts","../src/core/get.ts","../src/core/has-path.ts","../src/core/identity.ts","../src/core/invert-object.ts","../src/core/is-empty.ts","../src/core/is-plain-object.ts","../src/core/map-keys.ts","../src/core/map-values.ts","../src/core/omit.ts","../src/core/partition-object.ts","../src/core/pick.ts","../src/core/rename-keys.ts","../src/core/set.ts","../src/core/typed-entries.ts","../src/core/typed-from-entries.ts"],"sourcesContent":["/**\n * Checks whether a plain object has all of the requested own keys.\n *\n * Prefer the rest-key form for the strongest autocomplete and inference.\n *\n * @example\n * ```ts\n * const user = { id: \"1\", role: \"admin\" } as const;\n *\n * hasKeys(user, \"id\", \"role\"); // true\n * hasKeys(user, [\"id\", \"role\"] as const); // true\n * ```\n */\nexport function hasKeys<\n\tT extends object,\n\tconst FirstKey extends keyof T,\n\tconst RestKeys extends readonly (keyof T)[],\n>(\n\tvalue: T,\n\tfirstKey: FirstKey,\n\t...restKeys: RestKeys\n): value is T & Required<Pick<T, FirstKey | RestKeys[number]>>;\nexport function hasKeys<\n\tT extends object,\n\tconst FirstKey extends keyof T,\n\tconst RestKeys extends readonly (keyof T)[],\n>(\n\tvalue: T,\n\tkeys: readonly [FirstKey, ...RestKeys],\n): value is T & Required<Pick<T, FirstKey | RestKeys[number]>>;\nexport function hasKeys<T extends object>(\n\tvalue: T,\n\tkeys: readonly (keyof T)[],\n): value is T;\nexport function hasKeys<T extends object>(\n\tvalue: T,\n\tfirstKeyOrKeys: keyof T | readonly (keyof T)[],\n\t...restKeys: readonly (keyof T)[]\n): boolean {\n\tif (value === null || typeof value !== \"object\") {\n\t\treturn false;\n\t}\n\n\tconst prototype = Object.getPrototypeOf(value);\n\n\tif (prototype !== Object.prototype && prototype !== null) {\n\t\treturn false;\n\t}\n\n\tconst keys = Array.isArray(firstKeyOrKeys)\n\t\t? firstKeyOrKeys\n\t\t: ([firstKeyOrKeys, ...restKeys] as readonly (keyof T)[]);\n\n\tfor (const key of keys) {\n\t\tif (!Object.hasOwn(value, key)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn true;\n}\n","import { hasKeys } from \"./has-keys\";\n\n/**\n * Requires that a plain object has all of the requested own keys.\n *\n * Prefer the rest-key form for the strongest autocomplete and inference.\n *\n * @example\n * ```ts\n * const user = { id: \"1\", role: \"admin\" } as const;\n * const result = requireKeys(user, \"id\", \"role\");\n *\n * result.id; // \"1\"\n * ```\n */\nexport function requireKeys<\n\tT extends object,\n\tconst FirstKey extends keyof T,\n\tconst RestKeys extends readonly (keyof T)[],\n>(\n\tvalue: T,\n\tfirstKey: FirstKey,\n\t...restKeys: RestKeys\n): T & Required<Pick<T, FirstKey | RestKeys[number]>>;\nexport function requireKeys<\n\tT extends object,\n\tconst FirstKey extends keyof T,\n\tconst RestKeys extends readonly (keyof T)[],\n>(\n\tvalue: T,\n\tkeys: readonly [FirstKey, ...RestKeys],\n): T & Required<Pick<T, FirstKey | RestKeys[number]>>;\nexport function requireKeys<T extends object>(\n\tvalue: T,\n\tkeys: readonly (keyof T)[],\n): T;\nexport function requireKeys<T extends object>(\n\tvalue: T,\n\tfirstKeyOrKeys: keyof T | readonly (keyof T)[],\n\t...restKeys: readonly (keyof T)[]\n): T {\n\tconst keys = Array.isArray(firstKeyOrKeys)\n\t\t? firstKeyOrKeys\n\t\t: ([firstKeyOrKeys, ...restKeys] as readonly (keyof T)[]);\n\n\tif (hasKeys(value, keys)) {\n\t\treturn value;\n\t}\n\n\tconst missingKeys: Array<keyof T> = [];\n\n\tif (value !== null && typeof value === \"object\") {\n\t\tconst prototype = Object.getPrototypeOf(value);\n\n\t\tif (prototype === Object.prototype || prototype === null) {\n\t\t\tfor (const key of keys) {\n\t\t\t\tif (!Object.hasOwn(value, key)) {\n\t\t\t\t\tmissingKeys.push(key);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif (missingKeys.length === 0) {\n\t\tmissingKeys.push(...keys);\n\t}\n\n\tconst label = missingKeys.length === 1 ? \"key\" : \"keys\";\n\n\tthrow new TypeError(\n\t\t`Missing required ${label}: ${missingKeys.map(String).join(\", \")}`,\n\t);\n}\n","import { requireKeys } from \"./require-keys\";\n\n/**\n * Asserts that a plain object has all of the requested own keys.\n *\n * Prefer the rest-key form for the strongest autocomplete and inference.\n *\n * @example\n * ```ts\n * const user = { id: \"1\", role: \"admin\" } as const;\n *\n * assertKeys(user, \"id\", \"role\");\n * user.id; // \"1\"\n * ```\n */\nexport function assertKeys<\n\tT extends object,\n\tconst FirstKey extends keyof T,\n\tconst RestKeys extends readonly (keyof T)[],\n>(\n\tvalue: T,\n\tfirstKey: FirstKey,\n\t...restKeys: RestKeys\n): asserts value is T & Required<Pick<T, FirstKey | RestKeys[number]>>;\nexport function assertKeys<\n\tT extends object,\n\tconst FirstKey extends keyof T,\n\tconst RestKeys extends readonly (keyof T)[],\n>(\n\tvalue: T,\n\tkeys: readonly [FirstKey, ...RestKeys],\n): asserts value is T & Required<Pick<T, FirstKey | RestKeys[number]>>;\nexport function assertKeys<T extends object>(\n\tvalue: T,\n\tkeys: readonly (keyof T)[],\n): asserts value is T;\nexport function assertKeys<T extends object>(\n\tvalue: T,\n\tfirstKeyOrKeys: keyof T | readonly (keyof T)[],\n\t...restKeys: readonly (keyof T)[]\n): void {\n\trequireKeys(value, firstKeyOrKeys as keyof T, ...restKeys);\n}\n","import type { StringKeyOf } from \"./types\";\n\n/**\n * Returns the own enumerable string keys of an object with preserved key types.\n *\n * This is a typed wrapper around `Object.keys`.\n *\n * @example\n * ```ts\n * const user = { id: \"1\", name: \"Umsizi\" } as const;\n *\n * typedKeys(user); // [\"id\", \"name\"]\n * ```\n */\nexport function typedKeys<T extends object>(object: T): Array<StringKeyOf<T>> {\n\treturn Object.keys(object) as Array<StringKeyOf<T>>;\n}\n","import { typedKeys } from \"./typed-keys\";\nimport type { CompactedObject } from \"./types\";\n\n/**\n * Creates a new object with all `null` and `undefined` values removed.\n *\n * Other falsy values such as `0`, `false`, `\"\"`, and `NaN` are preserved.\n *\n * @example\n * ```ts\n * const user = { id: \"1\", nickname: null, active: false } as const;\n *\n * compactObject(user); // { id: \"1\", active: false }\n * ```\n */\nexport function compactObject<T extends object>(object: T): CompactedObject<T> {\n\tconst result = {} as CompactedObject<T>;\n\n\tfor (const key of typedKeys(object)) {\n\t\tconst value = object[key];\n\n\t\tif (value != null) {\n\t\t\tresult[key] = value as Exclude<T[typeof key], null | undefined>;\n\t\t}\n\t}\n\n\treturn result;\n}\n","import { typedKeys } from \"./typed-keys\";\nimport type { FilteredKeys, KeyGuard, KeyPredicate } from \"./types\";\n\n/**\n * Filters an object's own enumerable string-keyed properties by key.\n *\n * Supports both boolean predicates and key type guards. The result remains\n * partial because any property may be removed at runtime.\n *\n * @example\n * ```ts\n * const metrics = { total: 5, temp_cache: 2, temp_jobs: 1 } as const;\n *\n * filterKeys(metrics, (key) => key.startsWith(\"temp_\"));\n * // { temp_cache: 2, temp_jobs: 1 }\n * ```\n */\nexport function filterKeys<\n\tT extends object,\n\tS extends Extract<keyof T, string>,\n>(object: T, predicate: KeyGuard<T, S>): FilteredKeys<T, S>;\nexport function filterKeys<T extends object>(\n\tobject: T,\n\tpredicate: KeyPredicate<T>,\n): FilteredKeys<T, Extract<keyof T, string>>;\nexport function filterKeys<T extends object>(\n\tobject: T,\n\tpredicate: KeyPredicate<T>,\n): FilteredKeys<T, Extract<keyof T, string>> {\n\tconst result = {} as FilteredKeys<T, Extract<keyof T, string>>;\n\n\tfor (const key of typedKeys(object)) {\n\t\tif (predicate(key, object[key], object)) {\n\t\t\tresult[key] = object[key];\n\t\t}\n\t}\n\n\treturn result;\n}\n","import { typedKeys } from \"./typed-keys\";\nimport type { FilteredValues, ValueGuard, ValuePredicate } from \"./types\";\n\n/**\n * Filters an object's own enumerable string-keyed properties by value.\n *\n * Supports both boolean predicates and type-guard predicates. The result type\n * remains partial because any property may be removed at runtime.\n *\n * @example\n * ```ts\n * const settings = { retries: 3, label: \"\", timeout: null } as const;\n *\n * filterValues(settings, (value) => value !== null);\n * // { retries: 3, label: \"\" }\n * ```\n */\nexport function filterValues<\n\tT extends object,\n\tS extends T[Extract<keyof T, string>],\n>(object: T, predicate: ValueGuard<T, S>): FilteredValues<T, S>;\nexport function filterValues<T extends object>(\n\tobject: T,\n\tpredicate: ValuePredicate<T>,\n): FilteredValues<T, T[Extract<keyof T, string>]>;\nexport function filterValues<T extends object>(\n\tobject: T,\n\tpredicate: ValuePredicate<T>,\n): FilteredValues<T, T[Extract<keyof T, string>]> {\n\tconst result = {} as FilteredValues<T, T[Extract<keyof T, string>]>;\n\n\tfor (const key of typedKeys(object)) {\n\t\tconst value = object[key];\n\n\t\tif (predicate(value, key, object)) {\n\t\t\tresult[key] = value;\n\t\t}\n\t}\n\n\treturn result;\n}\n","/**\n * Checks whether an object has the given property as its own key.\n *\n * This is a typed wrapper around `Object.hasOwn` that narrows the provided key\n * when the check succeeds.\n *\n * @example\n * ```ts\n * const user = { id: \"1\" };\n * const key: string = \"id\";\n *\n * if (hasOwn(user, key)) {\n * user[key]; // key is narrowed to \"id\"\n * }\n * ```\n */\nexport function hasOwn<T extends object, K extends PropertyKey>(\n\tobject: T,\n\tkey: K,\n): key is Extract<K, keyof T> {\n\treturn Object.hasOwn(object, key);\n}\n","import type { ObjectPath, PathInput, PathSegment } from \"./types\";\n\nconst BRACKET_PATH_SEGMENT_PATTERN =\n\t/[^.[\\]]+|\\[(?:([^\"'[\\]]+)|([\"'])(.*?)\\2)\\]/g;\n\nfunction toPathSegment(value: string): PathSegment {\n\treturn /^\\d+$/.test(value) ? Number(value) : value;\n}\n\n/**\n * Converts dot/bracket notation into a normalized object path array.\n *\n * @example\n * ```ts\n * path(\"profile.addresses[0].city\");\n * // [\"profile\", \"addresses\", 0, \"city\"]\n * ```\n */\nexport function path(input: PathInput): ObjectPath {\n\tif (typeof input !== \"string\") {\n\t\treturn [...input];\n\t}\n\n\tconst source = input;\n\tconst segments: PathSegment[] = [];\n\n\tfor (const match of source.matchAll(BRACKET_PATH_SEGMENT_PATTERN)) {\n\t\tconst [, bareSegment, , quotedSegment] = match;\n\t\tconst segment = quotedSegment ?? bareSegment ?? match[0];\n\n\t\tif (segment !== \"\") {\n\t\t\tsegments.push(toPathSegment(segment));\n\t\t}\n\t}\n\n\treturn segments;\n}\n","import { hasOwn } from \"./has-own\";\nimport { path as toPath } from \"./path\";\nimport type { ObjectPath, PathInput, PathValue } from \"./types\";\n\nfunction hasMissingPathSegment(\n\tvalue: unknown,\n\tsegment: string | number,\n): boolean {\n\treturn (\n\t\tvalue === null ||\n\t\tvalue === undefined ||\n\t\t(typeof value !== \"object\" && typeof value !== \"function\") ||\n\t\t!hasOwn(value, segment)\n\t);\n}\n\n/**\n * Reads a nested own property using a tuple path or dot/bracket notation.\n *\n * @example\n * ```ts\n * const user = { profile: { addresses: [{ city: \"Durban\" }] } } as const;\n *\n * get(user, [\"profile\", \"addresses\", 0, \"city\"]);\n * get(user, \"profile.addresses[0].city\");\n * ```\n */\nexport function get<T, const P extends ObjectPath>(\n\tobject: T,\n\tpath: P,\n): PathValue<T, P> | undefined;\nexport function get<T, const P extends ObjectPath, D>(\n\tobject: T,\n\tpath: P,\n\tdefaultValue: D,\n): Exclude<PathValue<T, P>, undefined> | D;\nexport function get<T>(object: T, path: string): unknown;\nexport function get<T, D>(\n\tobject: T,\n\tpath: string,\n\tdefaultValue: D,\n): D | unknown;\nexport function get<T, D>(\n\tobject: T,\n\tpathInput: PathInput,\n\tdefaultValue?: D,\n): D | unknown {\n\tconst segments = toPath(pathInput);\n\tlet current: unknown = object;\n\n\tfor (const segment of segments) {\n\t\tif (hasMissingPathSegment(current, segment)) {\n\t\t\treturn defaultValue;\n\t\t}\n\n\t\tcurrent = (current as Record<string | number, unknown>)[segment];\n\t}\n\n\treturn current;\n}\n","import { hasOwn } from \"./has-own\";\nimport { path as toPath } from \"./path\";\nimport type { PathInput } from \"./types\";\n\n/**\n * Checks whether a nested own-property path exists.\n *\n * A resolved `undefined` value still counts as existing as long as every\n * segment is present as an own property.\n */\nexport function hasPath(object: unknown, pathInput: PathInput): boolean {\n\tlet current = object;\n\n\tfor (const segment of toPath(pathInput)) {\n\t\tif (\n\t\t\tcurrent === null ||\n\t\t\tcurrent === undefined ||\n\t\t\t(typeof current !== \"object\" && typeof current !== \"function\") ||\n\t\t\t!hasOwn(current, segment)\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\n\t\tcurrent = (current as Record<string | number, unknown>)[segment];\n\t}\n\n\treturn true;\n}\n","/**\n * Returns the given value unchanged.\n *\n * Useful as a default callback, a type-inference anchor, or a no-op\n * placeholder where a transform function is expected.\n *\n * @example\n * ```ts\n * identity(\"umsizi\"); // \"umsizi\"\n * ```\n */\nexport function identity<T>(value: T): T {\n\treturn value;\n}\n","import { typedKeys } from \"./typed-keys\";\nimport type { InvertedObject } from \"./types\";\n\n/**\n * Inverts an object's own enumerable string-keyed properties.\n *\n * Source values must be valid property keys. When multiple source keys share\n * the same value, the later assignment wins.\n *\n * @example\n * ```ts\n * const roles = { admin: \"A\", member: \"M\" } as const;\n *\n * invertObject(roles);\n * // { A: \"admin\", M: \"member\" }\n * ```\n */\nexport function invertObject<T extends Record<string, PropertyKey>>(\n\tobject: T,\n): InvertedObject<T> {\n\tconst result = {} as InvertedObject<T>;\n\n\tfor (const key of typedKeys(object)) {\n\t\tconst value = object[key] as PropertyKey;\n\n\t\t(result as Record<PropertyKey, string>)[value] = key;\n\t}\n\n\treturn result;\n}\n","/**\n * Returns `true` when an object has no own enumerable properties.\n *\n * Both string keys and symbol keys are considered. Non-enumerable properties\n * are ignored.\n *\n * @example\n * ```ts\n * isEmpty({}); // true\n * isEmpty({ id: \"1\" }); // false\n * ```\n */\nexport function isEmpty(object: object): boolean {\n\tif (Object.keys(object).length > 0) {\n\t\treturn false;\n\t}\n\n\tfor (const key of Object.getOwnPropertySymbols(object)) {\n\t\tif (Object.prototype.propertyIsEnumerable.call(object, key)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn true;\n}\n","/**\n * Checks whether a value is a plain object with a prototype of\n * `Object.prototype` or `null`.\n *\n * Arrays, functions, boxed primitives, dates, maps, sets, and class instances\n * all return `false`.\n *\n * @example\n * ```ts\n * const payload: unknown = { id: \"1\" };\n *\n * if (isPlainObject(payload)) {\n * \tpayload.id;\n * }\n * ```\n */\nexport function isPlainObject(\n\tvalue: unknown,\n): value is Record<PropertyKey, unknown> {\n\tif (value === null || typeof value !== \"object\") {\n\t\treturn false;\n\t}\n\n\tconst prototype = Object.getPrototypeOf(value);\n\n\treturn prototype === Object.prototype || prototype === null;\n}\n","import { typedKeys } from \"./typed-keys\";\nimport type { KeyMapper, MappedKeys } from \"./types\";\n\n/**\n * Maps an object's own enumerable string keys to new string keys.\n *\n * When multiple source keys map to the same target key, the later assignment\n * wins.\n *\n * @example\n * ```ts\n * const user = { id: \"1\", active: true } as const;\n *\n * mapKeys(user, (key) => `user_${key}`);\n * // { user_id: \"1\", user_active: true }\n * ```\n */\nexport function mapKeys<T extends object, R extends string>(\n\tobject: T,\n\tmapper: KeyMapper<T, R>,\n): MappedKeys<T, R> {\n\tconst result = {} as MappedKeys<T, R>;\n\n\tfor (const key of typedKeys(object)) {\n\t\tconst mappedKey = mapper(key, object[key], object);\n\n\t\tresult[mappedKey] = object[key];\n\t}\n\n\treturn result;\n}\n","import { typedKeys } from \"./typed-keys\";\nimport type { MappedValues, ValueMapper } from \"./types\";\n\n/**\n * Maps the values of an object's own enumerable string-keyed properties while\n * preserving the original enumerable string-key set.\n *\n * @example\n * ```ts\n * const counts = { draft: 1, published: 2 };\n *\n * mapValues(counts, (value) => value * 2);\n * // { draft: 2, published: 4 }\n * ```\n */\nexport function mapValues<T extends object, R>(\n\tobject: T,\n\tmapper: ValueMapper<T, R>,\n): MappedValues<T, R> {\n\tconst result = {} as MappedValues<T, R>;\n\n\tfor (const key of typedKeys(object)) {\n\t\tresult[key] = mapper(object[key], key, object);\n\t}\n\n\treturn result;\n}\n","/**\n * Creates a new object excluding the selected own enumerable properties.\n *\n * Prefer the rest-key form for the strongest autocomplete and inference.\n *\n * @example\n * ```ts\n * const user = { id: \"1\", name: \"Umsizi\", role: \"admin\" } as const;\n *\n * omit(user, \"id\", \"name\"); // { role: \"admin\" }\n * omit(user, [\"role\"] as const); // { id: \"1\", name: \"Umsizi\" }\n * ```\n */\nexport function omit<T extends object, const Keys extends readonly (keyof T)[]>(\n\tobject: T,\n\t...keys: Keys\n): Omit<T, Keys[number]>;\nexport function omit<\n\tT extends object,\n\tconst FirstKey extends keyof T,\n\tconst RestKeys extends readonly (keyof T)[],\n>(\n\tobject: T,\n\tkeys: readonly [FirstKey, ...RestKeys],\n): Omit<T, FirstKey | RestKeys[number]>;\nexport function omit<T extends object>(\n\tobject: T,\n\tkeys: readonly (keyof T)[],\n): Partial<T>;\nexport function omit<T extends object>(\n\tobject: T,\n\tfirstKeyOrKeys: keyof T | readonly (keyof T)[],\n\t...restKeys: readonly (keyof T)[]\n): Partial<T> {\n\tconst keys = (\n\t\tArray.isArray(firstKeyOrKeys)\n\t\t\t? firstKeyOrKeys\n\t\t\t: [firstKeyOrKeys, ...restKeys]\n\t) as readonly (keyof T)[];\n\tconst omittedKeys = new Set<PropertyKey>(keys as readonly PropertyKey[]);\n\tconst result: Partial<T> = {};\n\n\tfor (const key of Reflect.ownKeys(object) as (keyof T)[]) {\n\t\tif (\n\t\t\tObject.prototype.propertyIsEnumerable.call(object, key) &&\n\t\t\t!omittedKeys.has(key)\n\t\t) {\n\t\t\t(result as T)[key] = object[key];\n\t\t}\n\t}\n\n\treturn result;\n}\n","import { typedKeys } from \"./typed-keys\";\nimport type {\n\tPartitionedObject,\n\tPartitionedValues,\n\tValueGuard,\n\tValuePredicate,\n} from \"./types\";\n\n/**\n * Partitions an object's own enumerable string-keyed properties into matching\n * and non-matching objects.\n *\n * Supports both boolean predicates and type-guard predicates.\n *\n * @example\n * ```ts\n * const settings = { retries: 3, label: \"ok\", timeout: null } as const;\n *\n * partitionObject(settings, (value) => value !== null);\n * // [{ retries: 3, label: \"ok\" }, { timeout: null }]\n * ```\n */\nexport function partitionObject<\n\tT extends object,\n\tS extends T[Extract<keyof T, string>],\n>(object: T, predicate: ValueGuard<T, S>): PartitionedValues<T, S>;\nexport function partitionObject<T extends object>(\n\tobject: T,\n\tpredicate: ValuePredicate<T>,\n): PartitionedObject<T>;\nexport function partitionObject<T extends object>(\n\tobject: T,\n\tpredicate: ValuePredicate<T>,\n): PartitionedObject<T> {\n\tconst matching = {} as PartitionedObject<T>[0];\n\tconst rest = {} as PartitionedObject<T>[1];\n\n\tfor (const key of typedKeys(object)) {\n\t\tconst value = object[key];\n\n\t\tif (predicate(value, key, object)) {\n\t\t\t(matching as Record<string, T[Extract<keyof T, string>]>)[key] = value;\n\t\t\tcontinue;\n\t\t}\n\n\t\t(rest as Record<string, T[Extract<keyof T, string>]>)[key] = value;\n\t}\n\n\treturn [matching, rest];\n}\n","import { hasOwn } from \"./has-own\";\n\n/**\n * Creates a new object containing only the selected own properties.\n *\n * Prefer the rest-key form for the strongest autocomplete and inference.\n *\n * @example\n * ```ts\n * const user = { id: \"1\", name: \"Umsizi\", role: \"admin\" } as const;\n *\n * pick(user, \"name\"); // { name: \"Umsizi\" }\n * pick(user, [\"id\", \"role\"] as const); // { id: \"1\", role: \"admin\" }\n * ```\n */\nexport function pick<T extends object, const Keys extends readonly (keyof T)[]>(\n\tobject: T,\n\t...keys: Keys\n): Pick<T, Keys[number]>;\nexport function pick<\n\tT extends object,\n\tconst FirstKey extends keyof T,\n\tconst RestKeys extends readonly (keyof T)[],\n>(\n\tobject: T,\n\tkeys: readonly [FirstKey, ...RestKeys],\n): Pick<T, FirstKey | RestKeys[number]>;\nexport function pick<T extends object>(\n\tobject: T,\n\tkeys: readonly (keyof T)[],\n): Partial<T>;\nexport function pick<T extends object>(\n\tobject: T,\n\tfirstKeyOrKeys: keyof T | readonly (keyof T)[],\n\t...restKeys: readonly (keyof T)[]\n): Partial<T> {\n\tconst keys = (\n\t\tArray.isArray(firstKeyOrKeys)\n\t\t\t? firstKeyOrKeys\n\t\t\t: [firstKeyOrKeys, ...restKeys]\n\t) as readonly (keyof T)[];\n\tconst result: Partial<T> = {};\n\n\tfor (const key of keys) {\n\t\tif (hasOwn(object, key)) {\n\t\t\tresult[key] = object[key];\n\t\t}\n\t}\n\n\treturn result;\n}\n","import { hasOwn } from \"./has-own\";\nimport { typedKeys } from \"./typed-keys\";\nimport type { RenamedKeys } from \"./types\";\n\n/**\n * Renames selected own enumerable string-keyed properties using a key map.\n *\n * Unmapped keys are copied through unchanged. When multiple source keys resolve\n * to the same target key, the later assignment wins.\n *\n * @example\n * ```ts\n * const user = { id: \"1\", givenName: \"Umsizi\" } as const;\n *\n * renameKeys(user, { givenName: \"name\" });\n * // { id: \"1\", name: \"Umsizi\" }\n * ```\n */\nexport function renameKeys<\n\tT extends object,\n\tconst M extends Partial<Record<Extract<keyof T, string>, string>>,\n>(object: T, names: M): RenamedKeys<T, M> {\n\tconst result = {} as RenamedKeys<T, M>;\n\n\tfor (const key of typedKeys(object)) {\n\t\tconst renamedKey = (hasOwn(names, key) ? names[key] : key) as string;\n\n\t\t(result as Record<string, T[Extract<keyof T, string>]>)[renamedKey] =\n\t\t\tobject[key];\n\t}\n\n\treturn result;\n}\n","import { path as toPath } from \"./path\";\nimport type { PathInput, PathSegment } from \"./types\";\n\nfunction isContainer(value: unknown): value is object {\n\treturn typeof value === \"object\" && value !== null;\n}\n\nfunction createContainer(\n\tnextSegment: PathSegment | undefined,\n): unknown[] | Record<string, unknown> {\n\treturn typeof nextSegment === \"number\" ? [] : {};\n}\n\nfunction cloneContainer(value: unknown, nextSegment: PathSegment | undefined) {\n\tif (Array.isArray(value)) {\n\t\treturn [...value];\n\t}\n\n\tif (isContainer(value)) {\n\t\treturn Object.assign(\n\t\t\tObject.create(Object.getPrototypeOf(value)),\n\t\t\tvalue,\n\t\t) as Record<string | number, unknown>;\n\t}\n\n\treturn createContainer(nextSegment);\n}\n\nfunction setAtPath(\n\tcurrent: unknown,\n\tsegments: readonly PathSegment[],\n\tvalue: unknown,\n): unknown {\n\tconst [segment, ...rest] = segments as readonly [\n\t\tPathSegment,\n\t\t...PathSegment[],\n\t];\n\n\tconst clone = cloneContainer(current, segment) as Record<\n\t\tPropertyKey,\n\t\tunknown\n\t>;\n\tconst existingValue =\n\t\tisContainer(current) || Array.isArray(current)\n\t\t\t? (current as Record<string | number, unknown>)[segment]\n\t\t\t: undefined;\n\n\tclone[segment] =\n\t\trest.length === 0 ? value : setAtPath(existingValue, rest, value);\n\n\treturn clone;\n}\n\n/**\n * Returns a new object with the nested path set to the given value.\n *\n * Missing containers are created automatically. Only the updated path is\n * cloned; untouched branches retain their existing references.\n */\nexport function set<T extends object>(\n\tobject: T,\n\tpathInput: PathInput,\n\tvalue: unknown,\n): T {\n\tconst segments = toPath(pathInput);\n\n\tif (segments.length === 0) {\n\t\treturn object;\n\t}\n\n\treturn setAtPath(object, segments, value) as T;\n}\n","import type { ObjectEntries } from \"./types\";\n\n/**\n * Returns the own enumerable string-keyed entries of an object with preserved\n * key/value pairing.\n *\n * This is a typed wrapper around `Object.entries`.\n *\n * @example\n * ```ts\n * const user = { id: \"1\", active: true } as const;\n *\n * typedEntries(user); // [[\"id\", \"1\"], [\"active\", true]]\n * ```\n */\nexport function typedEntries<T extends object>(object: T): ObjectEntries<T> {\n\treturn Object.entries(object) as unknown as ObjectEntries<T>;\n}\n","import type { EntryTuples, ObjectFromEntries } from \"./types\";\n\n/**\n * Creates an object from entries while preserving the key and value types from\n * the input tuple array.\n *\n * This is a typed wrapper around `Object.fromEntries`.\n *\n * @example\n * ```ts\n * const status = typedFromEntries([\n * [\"id\", \"1\"],\n * [\"active\", true],\n * ] as const);\n *\n * // inferred as: { id: \"1\"; active: true }\n * ```\n */\nexport function typedFromEntries<const T extends EntryTuples>(\n\tentries: T,\n): ObjectFromEntries<T> {\n\treturn Object.fromEntries(entries) as ObjectFromEntries<T>;\n}\n"],"mappings":";AAkCA,SAAgB,QACf,OACA,gBACA,GAA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R,aACsC;AACtC,QAAO,OAAO,gBAAgB,WAAW,EAAE,GAAG,EAAE;;AAGjD,SAAS,eAAe,OAAgB,aAAsC;AAC7E,KAAI,MAAM,QAAQ,MAAM,CACvB,QAAO,CAAC,GAAG,MAAM;AAGlB,KAAI,YAAY,MAAM,CACrB,QAAO,OAAO,OACb,OAAO,OAAO,OAAO,eAAe,MAAM,CAAC,EAC3C,MACA;AAGF,QAAO,gBAAgB,YAAY;;AAGpC,SAAS,UACR,SACA,UACA,OACU;CACV,MAAM,CAAC,SAAS,GAAG,QAAQ;CAK3B,MAAM,QAAQ,eAAe,SAAS,QAAQ;CAI9C,MAAM,gBACL,YAAY,QAAQ,IAAI,MAAM,QAAQ,QAAQ,GAC1C,QAA6C,WAC9C;AAEJ,OAAM,WACL,KAAK,WAAW,IAAI,QAAQ,UAAU,eAAe,MAAM,MAAM;AAElE,QAAO;;;;;;;;AASR,SAAgB,IACf,QACA,WACA,OACI;CACJ,MAAM,WAAWC,KAAO,UAAU;AAElC,KAAI,SAAS,WAAW,EACvB,QAAO;AAGR,QAAO,UAAU,QAAQ,UAAU,MAAM;;;;;;;;;;;;;;;;;;ACvD1C,SAAgB,aAA+B,QAA6B;AAC3E,QAAO,OAAO,QAAQ,OAAO;;;;;;;;;;;;;;;;;;;;;ACE9B,SAAgB,iBACf,SACuB;AACvB,QAAO,OAAO,YAAY,QAAQ"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["missingKeys: Array<keyof T>","segments: PathSegment[]","toPath","current: unknown","toPath","matches: Array<KeyMatch<PropertyKey, L, R>>","result: Partial<T>","isRecord","result: Partial<T>","toPath"],"sources":["../src/core/has-keys.ts","../src/core/require-keys.ts","../src/core/assert-keys.ts","../src/core/typed-keys.ts","../src/core/compact-object.ts","../src/core/defaults.ts","../src/core/filter-keys.ts","../src/core/filter-values.ts","../src/core/has-own.ts","../src/core/path.ts","../src/core/get.ts","../src/core/group-by-key.ts","../src/core/has-path.ts","../src/core/identity.ts","../src/core/index-by-key.ts","../src/core/invert-object.ts","../src/core/is-empty.ts","../src/core/is-plain-object.ts","../src/core/map-keys.ts","../src/core/map-values.ts","../src/core/match-by-key.ts","../src/core/merge-defaults.ts","../src/core/omit.ts","../src/core/validate-object.ts","../src/core/parse-object.ts","../src/core/partition-object.ts","../src/core/pick.ts","../src/core/rename-keys.ts","../src/core/set.ts","../src/core/typed-entries.ts","../src/core/typed-from-entries.ts","../src/core/with-defaults.ts"],"sourcesContent":["/**\n * Checks whether a plain object has all of the requested own keys.\n *\n * Prefer the rest-key form for the strongest autocomplete and inference.\n *\n * @example\n * ```ts\n * const user = { id: \"1\", role: \"admin\" } as const;\n *\n * hasKeys(user, \"id\", \"role\"); // true\n * hasKeys(user, [\"id\", \"role\"] as const); // true\n * ```\n */\nexport function hasKeys<\n\tT extends object,\n\tconst FirstKey extends keyof T,\n\tconst RestKeys extends readonly (keyof T)[],\n>(\n\tvalue: T,\n\tfirstKey: FirstKey,\n\t...restKeys: RestKeys\n): value is T & Required<Pick<T, FirstKey | RestKeys[number]>>;\nexport function hasKeys<\n\tT extends object,\n\tconst FirstKey extends keyof T,\n\tconst RestKeys extends readonly (keyof T)[],\n>(\n\tvalue: T,\n\tkeys: readonly [FirstKey, ...RestKeys],\n): value is T & Required<Pick<T, FirstKey | RestKeys[number]>>;\nexport function hasKeys<T extends object>(\n\tvalue: T,\n\tkeys: readonly (keyof T)[],\n): value is T;\nexport function hasKeys<T extends object>(\n\tvalue: T,\n\tfirstKeyOrKeys: keyof T | readonly (keyof T)[],\n\t...restKeys: readonly (keyof T)[]\n): boolean {\n\tif (value === null || typeof value !== \"object\") {\n\t\treturn false;\n\t}\n\n\tconst prototype = Object.getPrototypeOf(value);\n\n\tif (prototype !== Object.prototype && prototype !== null) {\n\t\treturn false;\n\t}\n\n\tconst keys = Array.isArray(firstKeyOrKeys)\n\t\t? firstKeyOrKeys\n\t\t: ([firstKeyOrKeys, ...restKeys] as readonly (keyof T)[]);\n\n\tfor (const key of keys) {\n\t\tif (!Object.hasOwn(value, key)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn true;\n}\n","import { hasKeys } from \"./has-keys\";\n\n/**\n * Requires that a plain object has all of the requested own keys.\n *\n * Prefer the rest-key form for the strongest autocomplete and inference.\n *\n * @example\n * ```ts\n * const user = { id: \"1\", role: \"admin\" } as const;\n * const result = requireKeys(user, \"id\", \"role\");\n *\n * result.id; // \"1\"\n * ```\n */\nexport function requireKeys<\n\tT extends object,\n\tconst FirstKey extends keyof T,\n\tconst RestKeys extends readonly (keyof T)[],\n>(\n\tvalue: T,\n\tfirstKey: FirstKey,\n\t...restKeys: RestKeys\n): T & Required<Pick<T, FirstKey | RestKeys[number]>>;\nexport function requireKeys<\n\tT extends object,\n\tconst FirstKey extends keyof T,\n\tconst RestKeys extends readonly (keyof T)[],\n>(\n\tvalue: T,\n\tkeys: readonly [FirstKey, ...RestKeys],\n): T & Required<Pick<T, FirstKey | RestKeys[number]>>;\nexport function requireKeys<T extends object>(\n\tvalue: T,\n\tkeys: readonly (keyof T)[],\n): T;\nexport function requireKeys<T extends object>(\n\tvalue: T,\n\tfirstKeyOrKeys: keyof T | readonly (keyof T)[],\n\t...restKeys: readonly (keyof T)[]\n): T {\n\tconst keys = Array.isArray(firstKeyOrKeys)\n\t\t? firstKeyOrKeys\n\t\t: ([firstKeyOrKeys, ...restKeys] as readonly (keyof T)[]);\n\n\tif (hasKeys(value, keys)) {\n\t\treturn value;\n\t}\n\n\tconst missingKeys: Array<keyof T> = [];\n\n\tif (value !== null && typeof value === \"object\") {\n\t\tconst prototype = Object.getPrototypeOf(value);\n\n\t\tif (prototype === Object.prototype || prototype === null) {\n\t\t\tfor (const key of keys) {\n\t\t\t\tif (!Object.hasOwn(value, key)) {\n\t\t\t\t\tmissingKeys.push(key);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif (missingKeys.length === 0) {\n\t\tmissingKeys.push(...keys);\n\t}\n\n\tconst label = missingKeys.length === 1 ? \"key\" : \"keys\";\n\n\tthrow new TypeError(\n\t\t`Missing required ${label}: ${missingKeys.map(String).join(\", \")}`,\n\t);\n}\n","import { requireKeys } from \"./require-keys\";\n\n/**\n * Asserts that a plain object has all of the requested own keys.\n *\n * Prefer the rest-key form for the strongest autocomplete and inference.\n *\n * @example\n * ```ts\n * const user = { id: \"1\", role: \"admin\" } as const;\n *\n * assertKeys(user, \"id\", \"role\");\n * user.id; // \"1\"\n * ```\n */\nexport function assertKeys<\n\tT extends object,\n\tconst FirstKey extends keyof T,\n\tconst RestKeys extends readonly (keyof T)[],\n>(\n\tvalue: T,\n\tfirstKey: FirstKey,\n\t...restKeys: RestKeys\n): asserts value is T & Required<Pick<T, FirstKey | RestKeys[number]>>;\nexport function assertKeys<\n\tT extends object,\n\tconst FirstKey extends keyof T,\n\tconst RestKeys extends readonly (keyof T)[],\n>(\n\tvalue: T,\n\tkeys: readonly [FirstKey, ...RestKeys],\n): asserts value is T & Required<Pick<T, FirstKey | RestKeys[number]>>;\nexport function assertKeys<T extends object>(\n\tvalue: T,\n\tkeys: readonly (keyof T)[],\n): asserts value is T;\nexport function assertKeys<T extends object>(\n\tvalue: T,\n\tfirstKeyOrKeys: keyof T | readonly (keyof T)[],\n\t...restKeys: readonly (keyof T)[]\n): void {\n\trequireKeys(value, firstKeyOrKeys as keyof T, ...restKeys);\n}\n","import type { StringKeyOf } from \"./types\";\n\n/**\n * Returns the own enumerable string keys of an object with preserved key types.\n *\n * This is a typed wrapper around `Object.keys`.\n *\n * @example\n * ```ts\n * const user = { id: \"1\", name: \"Umsizi\" } as const;\n *\n * typedKeys(user); // [\"id\", \"name\"]\n * ```\n */\nexport function typedKeys<T extends object>(object: T): Array<StringKeyOf<T>> {\n\treturn Object.keys(object) as Array<StringKeyOf<T>>;\n}\n","import { typedKeys } from \"./typed-keys\";\nimport type { CompactedObject } from \"./types\";\n\n/**\n * Creates a new object with all `null` and `undefined` values removed.\n *\n * Other falsy values such as `0`, `false`, `\"\"`, and `NaN` are preserved.\n *\n * @example\n * ```ts\n * const user = { id: \"1\", nickname: null, active: false } as const;\n *\n * compactObject(user); // { id: \"1\", active: false }\n * ```\n */\nexport function compactObject<T extends object>(object: T): CompactedObject<T> {\n\tconst result = {} as CompactedObject<T>;\n\n\tfor (const key of typedKeys(object)) {\n\t\tconst value = object[key];\n\n\t\tif (value != null) {\n\t\t\tresult[key] = value as Exclude<T[typeof key], null | undefined>;\n\t\t}\n\t}\n\n\treturn result;\n}\n","import { typedKeys } from \"./typed-keys\";\nimport type { Defaulted } from \"./types\";\n\n/**\n * Creates a new object by filling missing or `undefined` properties from a\n * defaults object.\n *\n * `null`, `false`, `0`, and other defined values are preserved as-is.\n */\nexport function defaults<T extends object, D extends object>(\n\tobject: T,\n\tdefaultValues: D,\n): Defaulted<T, D> {\n\tconst result = { ...object } as Record<string, unknown>;\n\n\tfor (const key of typedKeys(defaultValues)) {\n\t\tif (result[key] === undefined) {\n\t\t\tresult[key] = defaultValues[key];\n\t\t}\n\t}\n\n\treturn result as Defaulted<T, D>;\n}\n","import { typedKeys } from \"./typed-keys\";\nimport type { FilteredKeys, KeyGuard, KeyPredicate } from \"./types\";\n\n/**\n * Filters an object's own enumerable string-keyed properties by key.\n *\n * Supports both boolean predicates and key type guards. The result remains\n * partial because any property may be removed at runtime.\n *\n * @example\n * ```ts\n * const metrics = { total: 5, temp_cache: 2, temp_jobs: 1 } as const;\n *\n * filterKeys(metrics, (key) => key.startsWith(\"temp_\"));\n * // { temp_cache: 2, temp_jobs: 1 }\n * ```\n */\nexport function filterKeys<\n\tT extends object,\n\tS extends Extract<keyof T, string>,\n>(object: T, predicate: KeyGuard<T, S>): FilteredKeys<T, S>;\nexport function filterKeys<T extends object>(\n\tobject: T,\n\tpredicate: KeyPredicate<T>,\n): FilteredKeys<T, Extract<keyof T, string>>;\nexport function filterKeys<T extends object>(\n\tobject: T,\n\tpredicate: KeyPredicate<T>,\n): FilteredKeys<T, Extract<keyof T, string>> {\n\tconst result = {} as FilteredKeys<T, Extract<keyof T, string>>;\n\n\tfor (const key of typedKeys(object)) {\n\t\tif (predicate(key, object[key], object)) {\n\t\t\tresult[key] = object[key];\n\t\t}\n\t}\n\n\treturn result;\n}\n","import { typedKeys } from \"./typed-keys\";\nimport type { FilteredValues, ValueGuard, ValuePredicate } from \"./types\";\n\n/**\n * Filters an object's own enumerable string-keyed properties by value.\n *\n * Supports both boolean predicates and type-guard predicates. The result type\n * remains partial because any property may be removed at runtime.\n *\n * @example\n * ```ts\n * const settings = { retries: 3, label: \"\", timeout: null } as const;\n *\n * filterValues(settings, (value) => value !== null);\n * // { retries: 3, label: \"\" }\n * ```\n */\nexport function filterValues<\n\tT extends object,\n\tS extends T[Extract<keyof T, string>],\n>(object: T, predicate: ValueGuard<T, S>): FilteredValues<T, S>;\nexport function filterValues<T extends object>(\n\tobject: T,\n\tpredicate: ValuePredicate<T>,\n): FilteredValues<T, T[Extract<keyof T, string>]>;\nexport function filterValues<T extends object>(\n\tobject: T,\n\tpredicate: ValuePredicate<T>,\n): FilteredValues<T, T[Extract<keyof T, string>]> {\n\tconst result = {} as FilteredValues<T, T[Extract<keyof T, string>]>;\n\n\tfor (const key of typedKeys(object)) {\n\t\tconst value = object[key];\n\n\t\tif (predicate(value, key, object)) {\n\t\t\tresult[key] = value;\n\t\t}\n\t}\n\n\treturn result;\n}\n","/**\n * Checks whether an object has the given property as its own key.\n *\n * This is a typed wrapper around `Object.hasOwn` that narrows the provided key\n * when the check succeeds.\n *\n * @example\n * ```ts\n * const user = { id: \"1\" };\n * const key: string = \"id\";\n *\n * if (hasOwn(user, key)) {\n * user[key]; // key is narrowed to \"id\"\n * }\n * ```\n */\nexport function hasOwn<T extends object, K extends PropertyKey>(\n\tobject: T,\n\tkey: K,\n): key is Extract<K, keyof T> {\n\treturn Object.hasOwn(object, key);\n}\n","import type { ObjectPath, PathInput, PathSegment } from \"./types\";\n\nconst BRACKET_PATH_SEGMENT_PATTERN =\n\t/[^.[\\]]+|\\[(?:([^\"'[\\]]+)|([\"'])(.*?)\\2)\\]/g;\n\nfunction toPathSegment(value: string): PathSegment {\n\treturn /^\\d+$/.test(value) ? Number(value) : value;\n}\n\n/**\n * Converts dot/bracket notation into a normalized object path array.\n *\n * @example\n * ```ts\n * path(\"profile.addresses[0].city\");\n * // [\"profile\", \"addresses\", 0, \"city\"]\n * ```\n */\nexport function path(input: PathInput): ObjectPath {\n\tif (typeof input !== \"string\") {\n\t\treturn [...input];\n\t}\n\n\tconst source = input;\n\tconst segments: PathSegment[] = [];\n\n\tfor (const match of source.matchAll(BRACKET_PATH_SEGMENT_PATTERN)) {\n\t\tconst [, bareSegment, , quotedSegment] = match;\n\t\tconst segment = quotedSegment ?? bareSegment ?? match[0];\n\n\t\tif (segment !== \"\") {\n\t\t\tsegments.push(toPathSegment(segment));\n\t\t}\n\t}\n\n\treturn segments;\n}\n","import { hasOwn } from \"./has-own\";\nimport { path as toPath } from \"./path\";\nimport type { ObjectPath, PathInput, PathValue } from \"./types\";\n\nfunction hasMissingPathSegment(\n\tvalue: unknown,\n\tsegment: string | number,\n): boolean {\n\treturn (\n\t\tvalue === null ||\n\t\tvalue === undefined ||\n\t\t(typeof value !== \"object\" && typeof value !== \"function\") ||\n\t\t!hasOwn(value, segment)\n\t);\n}\n\n/**\n * Reads a nested own property using a tuple path or dot/bracket notation.\n *\n * @example\n * ```ts\n * const user = { profile: { addresses: [{ city: \"Durban\" }] } } as const;\n *\n * get(user, [\"profile\", \"addresses\", 0, \"city\"]);\n * get(user, \"profile.addresses[0].city\");\n * ```\n */\nexport function get<T, const P extends ObjectPath>(\n\tobject: T,\n\tpath: P,\n): PathValue<T, P> | undefined;\nexport function get<T, const P extends ObjectPath, D>(\n\tobject: T,\n\tpath: P,\n\tdefaultValue: D,\n): Exclude<PathValue<T, P>, undefined> | D;\nexport function get<T>(object: T, path: string): unknown;\nexport function get<T, D>(\n\tobject: T,\n\tpath: string,\n\tdefaultValue: D,\n): D | unknown;\nexport function get<T, D>(\n\tobject: T,\n\tpathInput: PathInput,\n\tdefaultValue?: D,\n): D | unknown {\n\tconst segments = toPath(pathInput);\n\tlet current: unknown = object;\n\n\tfor (const segment of segments) {\n\t\tif (hasMissingPathSegment(current, segment)) {\n\t\t\treturn defaultValue;\n\t\t}\n\n\t\tcurrent = (current as Record<string | number, unknown>)[segment];\n\t}\n\n\treturn current;\n}\n","import type { GroupedByKey } from \"./types\";\n\n/**\n * Groups items by a property whose value can be used as an object key.\n *\n * @example\n * ```ts\n * groupByKey(\n * [\n * { id: \"1\", role: \"admin\" },\n * { id: \"2\", role: \"member\" },\n * { id: \"3\", role: \"admin\" },\n * ],\n * \"role\",\n * );\n * // { admin: [...], member: [...] }\n * ```\n */\nexport function groupByKey<T extends object, K extends keyof T>(\n\titems: ReadonlyArray<T>,\n\tkey: K,\n): GroupedByKey<T, K> {\n\tconst result = {} as GroupedByKey<T, K>;\n\n\tfor (const item of items) {\n\t\tconst groupKey = item[key] as Extract<T[K], PropertyKey>;\n\t\tconst existing = result[groupKey];\n\n\t\tif (existing) {\n\t\t\texisting.push(item);\n\t\t\tcontinue;\n\t\t}\n\n\t\tresult[groupKey] = [item];\n\t}\n\n\treturn result;\n}\n","import { hasOwn } from \"./has-own\";\nimport { path as toPath } from \"./path\";\nimport type { PathInput } from \"./types\";\n\n/**\n * Checks whether a nested own-property path exists.\n *\n * A resolved `undefined` value still counts as existing as long as every\n * segment is present as an own property.\n */\nexport function hasPath(object: unknown, pathInput: PathInput): boolean {\n\tlet current = object;\n\n\tfor (const segment of toPath(pathInput)) {\n\t\tif (\n\t\t\tcurrent === null ||\n\t\t\tcurrent === undefined ||\n\t\t\t(typeof current !== \"object\" && typeof current !== \"function\") ||\n\t\t\t!hasOwn(current, segment)\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\n\t\tcurrent = (current as Record<string | number, unknown>)[segment];\n\t}\n\n\treturn true;\n}\n","/**\n * Returns the given value unchanged.\n *\n * Useful as a default callback, a type-inference anchor, or a no-op\n * placeholder where a transform function is expected.\n *\n * @example\n * ```ts\n * identity(\"umsizi\"); // \"umsizi\"\n * ```\n */\nexport function identity<T>(value: T): T {\n\treturn value;\n}\n","import type { IndexedByKey } from \"./types\";\n\n/**\n * Indexes items by a property whose value can be used as an object key.\n *\n * Later items overwrite earlier items with the same key.\n *\n * @example\n * ```ts\n * indexByKey(\n * [\n * { id: \"1\", name: \"Ada\" },\n * { id: \"2\", name: \"Linus\" },\n * ],\n * \"id\",\n * );\n * // { 1: { ... }, 2: { ... } }\n * ```\n */\nexport function indexByKey<T extends object, K extends keyof T>(\n\titems: ReadonlyArray<T>,\n\tkey: K,\n): IndexedByKey<T, K> {\n\tconst result = {} as IndexedByKey<T, K>;\n\n\tfor (const item of items) {\n\t\tresult[item[key] as Extract<T[K], PropertyKey>] = item;\n\t}\n\n\treturn result;\n}\n","import { typedKeys } from \"./typed-keys\";\nimport type { InvertedObject } from \"./types\";\n\n/**\n * Inverts an object's own enumerable string-keyed properties.\n *\n * Source values must be valid property keys. When multiple source keys share\n * the same value, the later assignment wins.\n *\n * @example\n * ```ts\n * const roles = { admin: \"A\", member: \"M\" } as const;\n *\n * invertObject(roles);\n * // { A: \"admin\", M: \"member\" }\n * ```\n */\nexport function invertObject<T extends Record<string, PropertyKey>>(\n\tobject: T,\n): InvertedObject<T> {\n\tconst result = {} as InvertedObject<T>;\n\n\tfor (const key of typedKeys(object)) {\n\t\tconst value = object[key] as PropertyKey;\n\n\t\t(result as Record<PropertyKey, string>)[value] = key;\n\t}\n\n\treturn result;\n}\n","/**\n * Returns `true` when an object has no own enumerable properties.\n *\n * Both string keys and symbol keys are considered. Non-enumerable properties\n * are ignored.\n *\n * @example\n * ```ts\n * isEmpty({}); // true\n * isEmpty({ id: \"1\" }); // false\n * ```\n */\nexport function isEmpty(object: object): boolean {\n\tif (Object.keys(object).length > 0) {\n\t\treturn false;\n\t}\n\n\tfor (const key of Object.getOwnPropertySymbols(object)) {\n\t\tif (Object.prototype.propertyIsEnumerable.call(object, key)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn true;\n}\n","/**\n * Checks whether a value is a plain object with a prototype of\n * `Object.prototype` or `null`.\n *\n * Arrays, functions, boxed primitives, dates, maps, sets, and class instances\n * all return `false`.\n *\n * @example\n * ```ts\n * const payload: unknown = { id: \"1\" };\n *\n * if (isPlainObject(payload)) {\n * \tpayload.id;\n * }\n * ```\n */\nexport function isPlainObject(\n\tvalue: unknown,\n): value is Record<PropertyKey, unknown> {\n\tif (value === null || typeof value !== \"object\") {\n\t\treturn false;\n\t}\n\n\tconst prototype = Object.getPrototypeOf(value);\n\n\treturn prototype === Object.prototype || prototype === null;\n}\n","import { typedKeys } from \"./typed-keys\";\nimport type { KeyMapper, MappedKeys } from \"./types\";\n\n/**\n * Maps an object's own enumerable string keys to new string keys.\n *\n * When multiple source keys map to the same target key, the later assignment\n * wins.\n *\n * @example\n * ```ts\n * const user = { id: \"1\", active: true } as const;\n *\n * mapKeys(user, (key) => `user_${key}`);\n * // { user_id: \"1\", user_active: true }\n * ```\n */\nexport function mapKeys<T extends object, R extends string>(\n\tobject: T,\n\tmapper: KeyMapper<T, R>,\n): MappedKeys<T, R> {\n\tconst result = {} as MappedKeys<T, R>;\n\n\tfor (const key of typedKeys(object)) {\n\t\tconst mappedKey = mapper(key, object[key], object);\n\n\t\tresult[mappedKey] = object[key];\n\t}\n\n\treturn result;\n}\n","import { typedKeys } from \"./typed-keys\";\nimport type { MappedValues, ValueMapper } from \"./types\";\n\n/**\n * Maps the values of an object's own enumerable string-keyed properties while\n * preserving the original enumerable string-key set.\n *\n * @example\n * ```ts\n * const counts = { draft: 1, published: 2 };\n *\n * mapValues(counts, (value) => value * 2);\n * // { draft: 2, published: 4 }\n * ```\n */\nexport function mapValues<T extends object, R>(\n\tobject: T,\n\tmapper: ValueMapper<T, R>,\n): MappedValues<T, R> {\n\tconst result = {} as MappedValues<T, R>;\n\n\tfor (const key of typedKeys(object)) {\n\t\tresult[key] = mapper(object[key], key, object);\n\t}\n\n\treturn result;\n}\n","import { groupByKey } from \"./group-by-key\";\nimport type { KeyMatch } from \"./types\";\n\n/**\n * Matches items from two arrays when their key values are equal.\n *\n * Supports either the same key on both sides or separate left/right keys.\n *\n * @example\n * ```ts\n * matchByKey(\n * [{ id: \"1\", name: \"Ada\" }],\n * [{ userId: \"1\", status: \"active\" }],\n * \"id\",\n * \"userId\",\n * );\n * // [{ key: \"1\", left: { ... }, right: { ... } }]\n * ```\n */\nexport function matchByKey<\n\tL extends object,\n\tR extends object,\n\tK extends keyof L & keyof R,\n>(\n\tleftItems: ReadonlyArray<L>,\n\trightItems: ReadonlyArray<R>,\n\tkey: K,\n): Array<KeyMatch<Extract<L[K] & R[K], PropertyKey>, L, R>>;\nexport function matchByKey<\n\tL extends object,\n\tR extends object,\n\tLK extends keyof L,\n\tRK extends keyof R,\n>(\n\tleftItems: ReadonlyArray<L>,\n\trightItems: ReadonlyArray<R>,\n\tleftKey: LK,\n\trightKey: RK,\n): Array<KeyMatch<Extract<L[LK] & R[RK], PropertyKey>, L, R>>;\nexport function matchByKey<\n\tL extends object,\n\tR extends object,\n\tLK extends keyof L,\n\tRK extends keyof R,\n>(\n\tleftItems: ReadonlyArray<L>,\n\trightItems: ReadonlyArray<R>,\n\tleftKey: LK,\n\trightKey?: RK,\n): Array<KeyMatch<PropertyKey, L, R>> {\n\tconst resolvedRightKey = (rightKey ?? leftKey) as keyof R;\n\tconst rightIndex = groupByKey(rightItems, resolvedRightKey) as Record<\n\t\tPropertyKey,\n\t\tArray<R> | undefined\n\t>;\n\n\tconst matches: Array<KeyMatch<PropertyKey, L, R>> = [];\n\n\tfor (const left of leftItems) {\n\t\tconst key = left[leftKey] as PropertyKey;\n\t\tconst matchingRights = rightIndex[key];\n\n\t\tif (!matchingRights) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tfor (const right of matchingRights) {\n\t\t\tmatches.push({ key, left, right });\n\t\t}\n\t}\n\n\treturn matches;\n}\n","import { isPlainObject } from \"./is-plain-object\";\nimport { typedKeys } from \"./typed-keys\";\nimport type { MergeDefaulted } from \"./types\";\n\n/**\n * Recursively fills missing or `undefined` properties from a defaults object.\n *\n * Only plain objects are merged deeply. Arrays and other object-like values are\n * treated as leaf values.\n */\nexport function mergeDefaults<T extends object, D extends object>(\n\tobject: T,\n\tdefaultValues: D,\n): MergeDefaulted<T, D> {\n\tconst result = { ...object } as Record<string, unknown>;\n\n\tfor (const key of typedKeys(defaultValues)) {\n\t\tconst value = result[key];\n\t\tconst fallback = defaultValues[key];\n\n\t\tresult[key] =\n\t\t\tvalue === undefined\n\t\t\t\t? fallback\n\t\t\t\t: isPlainObject(value) && isPlainObject(fallback)\n\t\t\t\t\t? mergeDefaults(value, fallback)\n\t\t\t\t\t: value;\n\t}\n\n\treturn result as MergeDefaulted<T, D>;\n}\n","/**\n * Creates a new object excluding the selected own enumerable properties.\n *\n * Prefer the rest-key form for the strongest autocomplete and inference.\n *\n * @example\n * ```ts\n * const user = { id: \"1\", name: \"Umsizi\", role: \"admin\" } as const;\n *\n * omit(user, \"id\", \"name\"); // { role: \"admin\" }\n * omit(user, [\"role\"] as const); // { id: \"1\", name: \"Umsizi\" }\n * ```\n */\nexport function omit<T extends object, const Keys extends readonly (keyof T)[]>(\n\tobject: T,\n\t...keys: Keys\n): Omit<T, Keys[number]>;\nexport function omit<\n\tT extends object,\n\tconst FirstKey extends keyof T,\n\tconst RestKeys extends readonly (keyof T)[],\n>(\n\tobject: T,\n\tkeys: readonly [FirstKey, ...RestKeys],\n): Omit<T, FirstKey | RestKeys[number]>;\nexport function omit<T extends object>(\n\tobject: T,\n\tkeys: readonly (keyof T)[],\n): Partial<T>;\nexport function omit<T extends object>(\n\tobject: T,\n\tfirstKeyOrKeys: keyof T | readonly (keyof T)[],\n\t...restKeys: readonly (keyof T)[]\n): Partial<T> {\n\tconst keys = (\n\t\tArray.isArray(firstKeyOrKeys)\n\t\t\t? firstKeyOrKeys\n\t\t\t: [firstKeyOrKeys, ...restKeys]\n\t) as readonly (keyof T)[];\n\tconst omittedKeys = new Set<PropertyKey>(keys as readonly PropertyKey[]);\n\tconst result: Partial<T> = {};\n\n\tfor (const key of Reflect.ownKeys(object) as (keyof T)[]) {\n\t\tif (\n\t\t\tObject.prototype.propertyIsEnumerable.call(object, key) &&\n\t\t\t!omittedKeys.has(key)\n\t\t) {\n\t\t\t(result as T)[key] = object[key];\n\t\t}\n\t}\n\n\treturn result;\n}\n","import { hasOwn } from \"./has-own\";\nimport { isRecord } from \"./is-record\";\nimport { typedKeys } from \"./typed-keys\";\nimport type { InferSchema, ObjectSchema } from \"./types\";\n\n/**\n * Validates an unknown value against a schema of field validators.\n *\n * All schema keys must exist as own properties on the input object and every\n * field validator must accept its corresponding value.\n *\n * @example\n * ```ts\n * const isUser = validateObject(\n * { id: \"usr_1\", active: true },\n * schema({\n * id: (value): value is string => typeof value === \"string\",\n * active: (value): value is boolean => typeof value === \"boolean\",\n * }),\n * );\n * ```\n */\nexport function validateObject<const T extends ObjectSchema>(\n\tvalue: unknown,\n\tdefinition: T,\n): value is InferSchema<T> {\n\tif (!isRecord(value)) return false;\n\n\tfor (const key of typedKeys(definition)) {\n\t\tif (!hasOwn(value, key)) return false;\n\t\tif (!(definition[key] as T[typeof key])(value[key])) return false;\n\t}\n\n\treturn true;\n}\n","import type { InferSchema, ObjectSchema } from \"./types\";\nimport { validateObject } from \"./validate-object\";\n\n/**\n * Parses an unknown value as a typed object by validating it against a schema.\n *\n * Throws a `TypeError` when validation fails.\n *\n * @example\n * ```ts\n * const user = parseObject(payload, schema({\n * id: (value): value is string => typeof value === \"string\",\n * active: (value): value is boolean => typeof value === \"boolean\",\n * }));\n * ```\n */\nexport function parseObject<const T extends ObjectSchema>(\n\tvalue: unknown,\n\tdefinition: T,\n): InferSchema<T> {\n\tif (validateObject(value, definition)) return value;\n\n\tthrow new TypeError(\"Invalid object.\");\n}\n","import { typedKeys } from \"./typed-keys\";\nimport type {\n\tPartitionedObject,\n\tPartitionedValues,\n\tValueGuard,\n\tValuePredicate,\n} from \"./types\";\n\n/**\n * Partitions an object's own enumerable string-keyed properties into matching\n * and non-matching objects.\n *\n * Supports both boolean predicates and type-guard predicates.\n *\n * @example\n * ```ts\n * const settings = { retries: 3, label: \"ok\", timeout: null } as const;\n *\n * partitionObject(settings, (value) => value !== null);\n * // [{ retries: 3, label: \"ok\" }, { timeout: null }]\n * ```\n */\nexport function partitionObject<\n\tT extends object,\n\tS extends T[Extract<keyof T, string>],\n>(object: T, predicate: ValueGuard<T, S>): PartitionedValues<T, S>;\nexport function partitionObject<T extends object>(\n\tobject: T,\n\tpredicate: ValuePredicate<T>,\n): PartitionedObject<T>;\nexport function partitionObject<T extends object>(\n\tobject: T,\n\tpredicate: ValuePredicate<T>,\n): PartitionedObject<T> {\n\tconst matching = {} as PartitionedObject<T>[0];\n\tconst rest = {} as PartitionedObject<T>[1];\n\n\tfor (const key of typedKeys(object)) {\n\t\tconst value = object[key];\n\n\t\tif (predicate(value, key, object)) {\n\t\t\t(matching as Record<string, T[Extract<keyof T, string>]>)[key] = value;\n\t\t\tcontinue;\n\t\t}\n\n\t\t(rest as Record<string, T[Extract<keyof T, string>]>)[key] = value;\n\t}\n\n\treturn [matching, rest];\n}\n","import { hasOwn } from \"./has-own\";\n\n/**\n * Creates a new object containing only the selected own properties.\n *\n * Prefer the rest-key form for the strongest autocomplete and inference.\n *\n * @example\n * ```ts\n * const user = { id: \"1\", name: \"Umsizi\", role: \"admin\" } as const;\n *\n * pick(user, \"name\"); // { name: \"Umsizi\" }\n * pick(user, [\"id\", \"role\"] as const); // { id: \"1\", role: \"admin\" }\n * ```\n */\nexport function pick<T extends object, const Keys extends readonly (keyof T)[]>(\n\tobject: T,\n\t...keys: Keys\n): Pick<T, Keys[number]>;\nexport function pick<\n\tT extends object,\n\tconst FirstKey extends keyof T,\n\tconst RestKeys extends readonly (keyof T)[],\n>(\n\tobject: T,\n\tkeys: readonly [FirstKey, ...RestKeys],\n): Pick<T, FirstKey | RestKeys[number]>;\nexport function pick<T extends object>(\n\tobject: T,\n\tkeys: readonly (keyof T)[],\n): Partial<T>;\nexport function pick<T extends object>(\n\tobject: T,\n\tfirstKeyOrKeys: keyof T | readonly (keyof T)[],\n\t...restKeys: readonly (keyof T)[]\n): Partial<T> {\n\tconst keys = (\n\t\tArray.isArray(firstKeyOrKeys)\n\t\t\t? firstKeyOrKeys\n\t\t\t: [firstKeyOrKeys, ...restKeys]\n\t) as readonly (keyof T)[];\n\tconst result: Partial<T> = {};\n\n\tfor (const key of keys) {\n\t\tif (hasOwn(object, key)) {\n\t\t\tresult[key] = object[key];\n\t\t}\n\t}\n\n\treturn result;\n}\n","import { hasOwn } from \"./has-own\";\nimport { typedKeys } from \"./typed-keys\";\nimport type { RenamedKeys } from \"./types\";\n\n/**\n * Renames selected own enumerable string-keyed properties using a key map.\n *\n * Unmapped keys are copied through unchanged. When multiple source keys resolve\n * to the same target key, the later assignment wins.\n *\n * @example\n * ```ts\n * const user = { id: \"1\", givenName: \"Umsizi\" } as const;\n *\n * renameKeys(user, { givenName: \"name\" });\n * // { id: \"1\", name: \"Umsizi\" }\n * ```\n */\nexport function renameKeys<\n\tT extends object,\n\tconst M extends Partial<Record<Extract<keyof T, string>, string>>,\n>(object: T, names: M): RenamedKeys<T, M> {\n\tconst result = {} as RenamedKeys<T, M>;\n\n\tfor (const key of typedKeys(object)) {\n\t\tconst renamedKey = (hasOwn(names, key) ? names[key] : key) as string;\n\n\t\t(result as Record<string, T[Extract<keyof T, string>]>)[renamedKey] =\n\t\t\tobject[key];\n\t}\n\n\treturn result;\n}\n","import { path as toPath } from \"./path\";\nimport type { PathInput, PathSegment } from \"./types\";\n\nfunction isContainer(value: unknown): value is object {\n\treturn typeof value === \"object\" && value !== null;\n}\n\nfunction createContainer(\n\tnextSegment: PathSegment | undefined,\n): unknown[] | Record<string, unknown> {\n\treturn typeof nextSegment === \"number\" ? [] : {};\n}\n\nfunction cloneContainer(value: unknown, nextSegment: PathSegment | undefined) {\n\tif (Array.isArray(value)) {\n\t\treturn [...value];\n\t}\n\n\tif (isContainer(value)) {\n\t\treturn Object.assign(\n\t\t\tObject.create(Object.getPrototypeOf(value)),\n\t\t\tvalue,\n\t\t) as Record<string | number, unknown>;\n\t}\n\n\treturn createContainer(nextSegment);\n}\n\nfunction setAtPath(\n\tcurrent: unknown,\n\tsegments: readonly PathSegment[],\n\tvalue: unknown,\n): unknown {\n\tconst [segment, ...rest] = segments as readonly [\n\t\tPathSegment,\n\t\t...PathSegment[],\n\t];\n\n\tconst clone = cloneContainer(current, segment) as Record<\n\t\tPropertyKey,\n\t\tunknown\n\t>;\n\tconst existingValue =\n\t\tisContainer(current) || Array.isArray(current)\n\t\t\t? (current as Record<string | number, unknown>)[segment]\n\t\t\t: undefined;\n\n\tclone[segment] =\n\t\trest.length === 0 ? value : setAtPath(existingValue, rest, value);\n\n\treturn clone;\n}\n\n/**\n * Returns a new object with the nested path set to the given value.\n *\n * Missing containers are created automatically. Only the updated path is\n * cloned; untouched branches retain their existing references.\n */\nexport function set<T extends object>(\n\tobject: T,\n\tpathInput: PathInput,\n\tvalue: unknown,\n): T {\n\tconst segments = toPath(pathInput);\n\n\tif (segments.length === 0) {\n\t\treturn object;\n\t}\n\n\treturn setAtPath(object, segments, value) as T;\n}\n","import type { ObjectEntries } from \"./types\";\n\n/**\n * Returns the own enumerable string-keyed entries of an object with preserved\n * key/value pairing.\n *\n * This is a typed wrapper around `Object.entries`.\n *\n * @example\n * ```ts\n * const user = { id: \"1\", active: true } as const;\n *\n * typedEntries(user); // [[\"id\", \"1\"], [\"active\", true]]\n * ```\n */\nexport function typedEntries<T extends object>(object: T): ObjectEntries<T> {\n\treturn Object.entries(object) as unknown as ObjectEntries<T>;\n}\n","import type { EntryTuples, ObjectFromEntries } from \"./types\";\n\n/**\n * Creates an object from entries while preserving the key and value types from\n * the input tuple array.\n *\n * This is a typed wrapper around `Object.fromEntries`.\n *\n * @example\n * ```ts\n * const status = typedFromEntries([\n * [\"id\", \"1\"],\n * [\"active\", true],\n * ] as const);\n *\n * // inferred as: { id: \"1\"; active: true }\n * ```\n */\nexport function typedFromEntries<const T extends EntryTuples>(\n\tentries: T,\n): ObjectFromEntries<T> {\n\treturn Object.fromEntries(entries) as ObjectFromEntries<T>;\n}\n","import { mergeDefaults } from \"./merge-defaults\";\nimport type { MergeDefaulted } from \"./types\";\n\ntype DefaultsApplicator<D extends object> = <T extends object>(\n\tobject: T,\n) => MergeDefaulted<T, D>;\n\n/**\n * Creates a reusable function that applies the provided defaults.\n */\nexport function withDefaults<D extends object>(\n\tdefaultValues: D,\n): DefaultsApplicator<D> {\n\treturn <T extends object>(object: T): MergeDefaulted<T, D> =>\n\t\tmergeDefaults(object, defaultValues);\n}\n"],"mappings":";AAkCA,SAAgB,QACf,OACA,gBACA,GAAG,UACO;AACV,KAAI,UAAU,QAAQ,OAAO,UAAU,SACtC,QAAO;CAGR,MAAM,YAAY,OAAO,eAAe,MAAM;AAE9C,KAAI,cAAc,OAAO,aAAa,cAAc,KACnD,QAAO;CAGR,MAAM,OAAO,MAAM,QAAQ,eAAe,GACvC,iBACC,CAAC,gBAAgB,GAAG,SAAS;AAEjC,MAAK,MAAM,OAAO,KACjB,KAAI,CAAC,OAAO,OAAO,OAAO,IAAI,CAC7B,QAAO;AAIT,QAAO;;;;;ACvBR,SAAgB,YACf,OACA,gBACA,GAAG,UACC;CACJ,MAAM,OAAO,MAAM,QAAQ,eAAe,GACvC,iBACC,CAAC,gBAAgB,GAAG,SAAS;AAEjC,KAAI,QAAQ,OAAO,KAAK,CACvB,QAAO;CAGR,MAAMA,cAA8B,EAAE;AAEtC,KAAI,UAAU,QAAQ,OAAO,UAAU,UAAU;EAChD,MAAM,YAAY,OAAO,eAAe,MAAM;AAE9C,MAAI,cAAc,OAAO,aAAa,cAAc,MACnD;QAAK,MAAM,OAAO,KACjB,KAAI,CAAC,OAAO,OAAO,OAAO,IAAI,CAC7B,aAAY,KAAK,IAAI;;;AAMzB,KAAI,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ACL,YAAY,QAAQ,IAAI,MAAM,QAAQ,QAAQ,GAC1C,QAA6C,WAC9C;AAEJ,OAAM,WACL,KAAK,WAAW,IAAI,QAAQ,UAAU,eAAe,MAAM,MAAM;AAElE,QAAO;;;;;;;;AASR,SAAgB,IACf,QACA,WACA,OACI;CACJ,MAAM,WAAWC,KAAO,UAAU;AAElC,KAAI,SAAS,WAAW,EACvB,QAAO;AAGR,QAAO,UAAU,QAAQ,UAAU,MAAM;;;;;;;;;;;;;;;;;;ACvD1C,SAAgB,aAA+B,QAA6B;AAC3E,QAAO,OAAO,QAAQ,OAAO;;;;;;;;;;;;;;;;;;;;;ACE9B,SAAgB,iBACf,SACuB;AACvB,QAAO,OAAO,YAAY,QAAQ;;;;;;;;ACXnC,SAAgB,aACf,eACwB;AACxB,SAA0B,WACzB,cAAc,QAAQ,cAAc"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "umsizi",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "A zero-dependency TypeScript utility library.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Jack-WebDev",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
{
|
|
73
73
|
"name": "umsizi (core)",
|
|
74
74
|
"path": "dist/index.js",
|
|
75
|
-
"limit": "1 KB"
|
|
75
|
+
"limit": "1.25 KB"
|
|
76
76
|
},
|
|
77
77
|
{
|
|
78
78
|
"name": "umsizi/react",
|