@helpers4/object 2.0.0-beta.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -4
- package/lib/index.d.ts +185 -35
- package/lib/index.js +305 -95
- package/lib/index.js.map +1 -1
- package/llms.txt +293 -66
- package/meta/api.json +302 -86
- package/meta/examples.json +82 -17
- package/package.json +8 -4
package/meta/api.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"category": "object",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"functions": [
|
|
5
5
|
{
|
|
6
6
|
"name": "compact",
|
|
@@ -110,54 +110,6 @@
|
|
|
110
110
|
],
|
|
111
111
|
"sourceFile": "deepClone.ts"
|
|
112
112
|
},
|
|
113
|
-
{
|
|
114
|
-
"name": "deepCompare",
|
|
115
|
-
"kind": "function",
|
|
116
|
-
"description": "Deep comparison of two objects that returns detailed information about differences.",
|
|
117
|
-
"since": "2.0.0",
|
|
118
|
-
"signatures": [
|
|
119
|
-
{
|
|
120
|
-
"signature": "deepCompare(objA: object | null | undefined, objB: object | null | undefined): boolean | DeepCompareResult",
|
|
121
|
-
"description": "Deep comparison of two objects that returns detailed information about differences.",
|
|
122
|
-
"params": [
|
|
123
|
-
{
|
|
124
|
-
"name": "objA",
|
|
125
|
-
"type": "object | null | undefined",
|
|
126
|
-
"description": "First object to compare (can be object, undefined, or null)"
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
"name": "objB",
|
|
130
|
-
"type": "object | null | undefined",
|
|
131
|
-
"description": "Second object to compare (can be object, undefined, or null)"
|
|
132
|
-
}
|
|
133
|
-
],
|
|
134
|
-
"returns": {
|
|
135
|
-
"type": "boolean | DeepCompareResult",
|
|
136
|
-
"description": "`true` if objects are identical, `false` if incompatible types, or a `DeepCompareResult` object detailing differences"
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
],
|
|
140
|
-
"examples": [
|
|
141
|
-
{
|
|
142
|
-
"title": "Compare nested objects",
|
|
143
|
-
"description": "Deeply compares two objects, returning true when they are structurally equal.",
|
|
144
|
-
"code": "deepCompare({ a: { b: 1 } }, { a: { b: 1 } })\n// => true"
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
"title": "Detect deep differences",
|
|
148
|
-
"description": "Returns a detailed diff object when nested values differ.",
|
|
149
|
-
"code": "deepCompare({ a: { b: 1 } }, { a: { b: 2 } })\n// => { a: { b: false } }"
|
|
150
|
-
}
|
|
151
|
-
],
|
|
152
|
-
"sourceFile": "deepCompare.ts",
|
|
153
|
-
"relatedTypes": [
|
|
154
|
-
{
|
|
155
|
-
"name": "DeepCompareResult",
|
|
156
|
-
"description": "Result type for deep comparison when objects are not identical",
|
|
157
|
-
"typeDefinition": "interface DeepCompareResult {}"
|
|
158
|
-
}
|
|
159
|
-
]
|
|
160
|
-
},
|
|
161
113
|
{
|
|
162
114
|
"name": "deepMerge",
|
|
163
115
|
"kind": "function",
|
|
@@ -240,6 +192,142 @@
|
|
|
240
192
|
],
|
|
241
193
|
"sourceFile": "deepMerge.ts"
|
|
242
194
|
},
|
|
195
|
+
{
|
|
196
|
+
"name": "diff",
|
|
197
|
+
"kind": "function",
|
|
198
|
+
"description": "Structural object diff.\n\nReturns `true` when both inputs are deeply equal, otherwise a\nDiffResult describing the differences key by key.\n\nComparison rules:\n- Same reference \\u2192 `true`.\n- Either side is `null`/`undefined` (and not both) \\u2192 `false`.\n- Both `Date` \\u2192 epoch comparison.\n- Both arrays \\u2192 compared with `array/equalsDeep` (leaf, no diff drill-down).\n- Special objects (Map, Set, RegExp, Promise, class instances\\u2026) \\u2192 reference equality.\n- Plain objects \\u2192 key-by-key, recursing up to `options.depth` levels.\n- Mixed types (e.g. array vs object, Date vs object) \\u2192 `false`.\n\nFor a boolean wrapper see equalsDeep from this category.\nFor a one-level boolean check see equalsShallow from this category.",
|
|
199
|
+
"since": "2.0.0",
|
|
200
|
+
"signatures": [
|
|
201
|
+
{
|
|
202
|
+
"signature": "diff(objA: object | null | undefined, objB: object | null | undefined, options: DiffOptions): boolean | DiffResult",
|
|
203
|
+
"description": "Structural object diff.\n\nReturns `true` when both inputs are deeply equal, otherwise a\nDiffResult describing the differences key by key.\n\nComparison rules:\n- Same reference \\u2192 `true`.\n- Either side is `null`/`undefined` (and not both) \\u2192 `false`.\n- Both `Date` \\u2192 epoch comparison.\n- Both arrays \\u2192 compared with `array/equalsDeep` (leaf, no diff drill-down).\n- Special objects (Map, Set, RegExp, Promise, class instances\\u2026) \\u2192 reference equality.\n- Plain objects \\u2192 key-by-key, recursing up to `options.depth` levels.\n- Mixed types (e.g. array vs object, Date vs object) \\u2192 `false`.\n\nFor a boolean wrapper see equalsDeep from this category.\nFor a one-level boolean check see equalsShallow from this category.",
|
|
204
|
+
"params": [
|
|
205
|
+
{
|
|
206
|
+
"name": "objA",
|
|
207
|
+
"type": "object | null | undefined",
|
|
208
|
+
"description": "First value (object, `null`, or `undefined`)."
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
"name": "objB",
|
|
212
|
+
"type": "object | null | undefined",
|
|
213
|
+
"description": "Second value (object, `null`, or `undefined`)."
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
"name": "options",
|
|
217
|
+
"type": "DiffOptions",
|
|
218
|
+
"description": "See DiffOptions.",
|
|
219
|
+
"defaultValue": "{}"
|
|
220
|
+
}
|
|
221
|
+
],
|
|
222
|
+
"returns": {
|
|
223
|
+
"type": "boolean | DiffResult",
|
|
224
|
+
"description": "`true` when equal, otherwise a DiffResult, or `false` for incompatible types."
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
],
|
|
228
|
+
"examples": [
|
|
229
|
+
{
|
|
230
|
+
"title": "Compare nested objects",
|
|
231
|
+
"description": "Deeply compares two objects, returning true when they are structurally equal.",
|
|
232
|
+
"code": "diff({ a: { b: 1 } }, { a: { b: 1 } })\n// => true"
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
"title": "Detect deep differences",
|
|
236
|
+
"description": "Returns a detailed diff object when nested values differ.",
|
|
237
|
+
"code": "diff({ a: { b: 1 } }, { a: { b: 2 } })\n// => { a: { b: false } }"
|
|
238
|
+
}
|
|
239
|
+
],
|
|
240
|
+
"sourceFile": "diff.ts",
|
|
241
|
+
"relatedTypes": [
|
|
242
|
+
{
|
|
243
|
+
"name": "DiffOptions",
|
|
244
|
+
"description": "Options for diff.",
|
|
245
|
+
"typeDefinition": "interface DiffOptions {\n depth?: number;\n}"
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
"name": "DiffResult",
|
|
249
|
+
"description": "Per-key diff result. Each entry tells what differs between the two\nobjects:\n- `\"onlyA\"` \\u2014 the key exists only on the first input.\n- `\"onlyB\"` \\u2014 the key exists only on the second input.\n- `false` \\u2014 both inputs have the key but the values differ.\n- nested `DiffResult` \\u2014 plain-object values that differ deeper.",
|
|
250
|
+
"typeDefinition": "interface DiffResult {}"
|
|
251
|
+
}
|
|
252
|
+
]
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
"name": "equalsDeep",
|
|
256
|
+
"kind": "function",
|
|
257
|
+
"description": "Recursive structural object equality.\n\nBoolean wrapper around diff \\u2014 returns `true` when the two values\nare deeply equal according to the same rules. Use this when you only\nneed a yes/no answer; use diff when you also need to know\n*what* differs.\n\nFor a one-level boolean check use equalsShallow.",
|
|
258
|
+
"since": "2.0.0",
|
|
259
|
+
"signatures": [
|
|
260
|
+
{
|
|
261
|
+
"signature": "equalsDeep(objA: object | null | undefined, objB: object | null | undefined): boolean",
|
|
262
|
+
"description": "Recursive structural object equality.\n\nBoolean wrapper around diff \\u2014 returns `true` when the two values\nare deeply equal according to the same rules. Use this when you only\nneed a yes/no answer; use diff when you also need to know\n*what* differs.\n\nFor a one-level boolean check use equalsShallow.",
|
|
263
|
+
"params": [
|
|
264
|
+
{
|
|
265
|
+
"name": "objA",
|
|
266
|
+
"type": "object | null | undefined",
|
|
267
|
+
"description": "First value (object, `null`, or `undefined`)."
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
"name": "objB",
|
|
271
|
+
"type": "object | null | undefined",
|
|
272
|
+
"description": "Second value (object, `null`, or `undefined`)."
|
|
273
|
+
}
|
|
274
|
+
],
|
|
275
|
+
"returns": {
|
|
276
|
+
"type": "boolean",
|
|
277
|
+
"description": "`true` if both inputs are deeply equal, `false` otherwise."
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
],
|
|
281
|
+
"examples": [
|
|
282
|
+
{
|
|
283
|
+
"title": "Compare nested objects",
|
|
284
|
+
"description": "Recursive structural equality. Returns true when the two values are deeply equal.",
|
|
285
|
+
"code": "equalsDeep({ a: { b: 1 } }, { a: { b: 1 } })\n// => true"
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
"title": "Detect deep differences",
|
|
289
|
+
"description": "Returns false when nested values differ.",
|
|
290
|
+
"code": "equalsDeep({ a: { b: 1 } }, { a: { b: 2 } })\n// => false"
|
|
291
|
+
}
|
|
292
|
+
],
|
|
293
|
+
"sourceFile": "equalsDeep.ts"
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
"name": "equalsShallow",
|
|
297
|
+
"kind": "function",
|
|
298
|
+
"description": "One-level (shallow) object equality.\n\nTwo objects are equal when they share the exact same set of own\nenumerable string keys and each pair of values satisfies strict equality\n(`===`). No recursion: nested objects/arrays are compared by reference.\n\nFalls back to strict equality when either input is `null`, `undefined`\nor not an object \\u2014 so primitives match if and only if they are `===`.\nArrays are not supported; they always return `false` (unless identical\nreferences). Use `array/equalsShallow` instead.\n\nFor recursive structural comparison use equalsDeep. For a diff\nstructure use diff.",
|
|
299
|
+
"since": "2.0.0",
|
|
300
|
+
"signatures": [
|
|
301
|
+
{
|
|
302
|
+
"signature": "equalsShallow(objA: unknown, objB: unknown): boolean",
|
|
303
|
+
"description": "One-level (shallow) object equality.\n\nTwo objects are equal when they share the exact same set of own\nenumerable string keys and each pair of values satisfies strict equality\n(`===`). No recursion: nested objects/arrays are compared by reference.\n\nFalls back to strict equality when either input is `null`, `undefined`\nor not an object \\u2014 so primitives match if and only if they are `===`.\nArrays are not supported; they always return `false` (unless identical\nreferences). Use `array/equalsShallow` instead.\n\nFor recursive structural comparison use equalsDeep. For a diff\nstructure use diff.",
|
|
304
|
+
"params": [
|
|
305
|
+
{
|
|
306
|
+
"name": "objA",
|
|
307
|
+
"type": "unknown",
|
|
308
|
+
"description": "First value to compare"
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
"name": "objB",
|
|
312
|
+
"type": "unknown",
|
|
313
|
+
"description": "Second value to compare"
|
|
314
|
+
}
|
|
315
|
+
],
|
|
316
|
+
"returns": {
|
|
317
|
+
"type": "boolean",
|
|
318
|
+
"description": "`true` if values are shallowly equal, `false` otherwise."
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
],
|
|
322
|
+
"examples": [
|
|
323
|
+
{
|
|
324
|
+
"title": "Compare two equal objects",
|
|
325
|
+
"description": "Uses JSON.stringify for a fast comparison.",
|
|
326
|
+
"code": "equalsShallow({ a: 1, b: 2 }, { a: 1, b: 2 })\n// => true"
|
|
327
|
+
}
|
|
328
|
+
],
|
|
329
|
+
"sourceFile": "equalsShallow.ts"
|
|
330
|
+
},
|
|
243
331
|
{
|
|
244
332
|
"name": "get",
|
|
245
333
|
"kind": "function",
|
|
@@ -293,6 +381,170 @@
|
|
|
293
381
|
],
|
|
294
382
|
"sourceFile": "get.ts"
|
|
295
383
|
},
|
|
384
|
+
{
|
|
385
|
+
"name": "groupBy",
|
|
386
|
+
"kind": "function",
|
|
387
|
+
"description": "Groups an array of items by a key derived from each item.\n\nA thin, typed wrapper around `Object.groupBy` (ES2024) that works on\nolder targets and provides stricter return-type inference.",
|
|
388
|
+
"since": "2.0.0",
|
|
389
|
+
"signatures": [
|
|
390
|
+
{
|
|
391
|
+
"signature": "groupBy<T, K extends PropertyKey>(items: readonly T[], keyFn: function): Partial<Record<K, T[]>>",
|
|
392
|
+
"description": "Groups an array of items by a key derived from each item.\n\nA thin, typed wrapper around `Object.groupBy` (ES2024) that works on\nolder targets and provides stricter return-type inference.",
|
|
393
|
+
"params": [
|
|
394
|
+
{
|
|
395
|
+
"name": "items",
|
|
396
|
+
"type": "readonly T[]",
|
|
397
|
+
"description": "The array to group"
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
"name": "keyFn",
|
|
401
|
+
"type": "function",
|
|
402
|
+
"description": "Function that returns the group key for each item"
|
|
403
|
+
}
|
|
404
|
+
],
|
|
405
|
+
"returns": {
|
|
406
|
+
"type": "Partial<Record<K, T[]>>",
|
|
407
|
+
"description": "A record mapping each key to the array of items with that key"
|
|
408
|
+
},
|
|
409
|
+
"typeParameters": [
|
|
410
|
+
{
|
|
411
|
+
"name": "T"
|
|
412
|
+
},
|
|
413
|
+
{
|
|
414
|
+
"name": "K",
|
|
415
|
+
"constraint": "PropertyKey"
|
|
416
|
+
}
|
|
417
|
+
]
|
|
418
|
+
}
|
|
419
|
+
],
|
|
420
|
+
"examples": [
|
|
421
|
+
{
|
|
422
|
+
"title": "Group numbers by parity",
|
|
423
|
+
"description": "Groups elements by the string key returned by the callback.",
|
|
424
|
+
"code": "groupBy([1, 2, 3, 4], n => n % 2 === 0 ? 'even' : 'odd')\n// => { odd: [1, 3], even: [2, 4] }"
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
"title": "Group objects by a property",
|
|
428
|
+
"description": "Use a property accessor as the grouping key.",
|
|
429
|
+
"code": "const users = [\n { name: 'Alice', role: 'admin' },\n { name: 'Bob', role: 'user' },\n { name: 'Carol', role: 'admin' },\n];\ngroupBy(users, u => u.role)\n// => { admin: [{...Alice}, {...Carol}], user: [{...Bob}] }"
|
|
430
|
+
}
|
|
431
|
+
],
|
|
432
|
+
"sourceFile": "groupBy.ts"
|
|
433
|
+
},
|
|
434
|
+
{
|
|
435
|
+
"name": "invert",
|
|
436
|
+
"kind": "function",
|
|
437
|
+
"description": "Returns a new object with keys and values swapped.\nIf multiple keys share the same value, the last one wins.",
|
|
438
|
+
"since": "2.0.0",
|
|
439
|
+
"signatures": [
|
|
440
|
+
{
|
|
441
|
+
"signature": "invert<K extends string, V extends PropertyKey>(obj: Record<K, V>): Record<V, K>",
|
|
442
|
+
"description": "Returns a new object with keys and values swapped.\nIf multiple keys share the same value, the last one wins.",
|
|
443
|
+
"params": [
|
|
444
|
+
{
|
|
445
|
+
"name": "obj",
|
|
446
|
+
"type": "Record<K, V>",
|
|
447
|
+
"description": "The object whose keys and values are to be swapped"
|
|
448
|
+
}
|
|
449
|
+
],
|
|
450
|
+
"returns": {
|
|
451
|
+
"type": "Record<V, K>",
|
|
452
|
+
"description": "A new object with values as keys and original keys as values"
|
|
453
|
+
},
|
|
454
|
+
"typeParameters": [
|
|
455
|
+
{
|
|
456
|
+
"name": "K",
|
|
457
|
+
"constraint": "string"
|
|
458
|
+
},
|
|
459
|
+
{
|
|
460
|
+
"name": "V",
|
|
461
|
+
"constraint": "PropertyKey"
|
|
462
|
+
}
|
|
463
|
+
]
|
|
464
|
+
}
|
|
465
|
+
],
|
|
466
|
+
"examples": [
|
|
467
|
+
{
|
|
468
|
+
"title": "Swap keys and values",
|
|
469
|
+
"description": "Returns a new object with keys and values swapped.",
|
|
470
|
+
"code": "invert({ a: 'x', b: 'y', c: 'z' })\n// => { x: 'a', y: 'b', z: 'c' }"
|
|
471
|
+
},
|
|
472
|
+
{
|
|
473
|
+
"title": "Build a reverse lookup map",
|
|
474
|
+
"description": "Useful when you have a code-to-label map and need label-to-code.",
|
|
475
|
+
"code": "const STATUS_LABELS = { 200: 'OK', 404: 'Not Found', 500: 'Internal Server Error' };\nconst LABEL_TO_CODE = invert(STATUS_LABELS);\n\nLABEL_TO_CODE['OK']; // => '200'"
|
|
476
|
+
}
|
|
477
|
+
],
|
|
478
|
+
"sourceFile": "invert.ts"
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
"name": "map",
|
|
482
|
+
"kind": "function",
|
|
483
|
+
"description": "Transforms the values and/or keys of a plain object in a single pass.\n\nBoth callbacks are optional and default to identity (no transformation).\nWhen `mapValue` is omitted the original values are preserved;\nwhen `mapKey` is omitted the original keys are preserved.\n\nNote: if two different keys map to the same output key the last one wins\n(insertion order).",
|
|
484
|
+
"since": "2.0.0",
|
|
485
|
+
"signatures": [
|
|
486
|
+
{
|
|
487
|
+
"signature": "map<TObj extends Record<string, unknown>, TVal = indexedAccess, TKey extends PropertyKey = keyof TObj>(obj: TObj, mapValue?: function, mapKey?: function): Record<TKey, TVal>",
|
|
488
|
+
"description": "Transforms the values and/or keys of a plain object in a single pass.\n\nBoth callbacks are optional and default to identity (no transformation).\nWhen `mapValue` is omitted the original values are preserved;\nwhen `mapKey` is omitted the original keys are preserved.\n\nNote: if two different keys map to the same output key the last one wins\n(insertion order).",
|
|
489
|
+
"params": [
|
|
490
|
+
{
|
|
491
|
+
"name": "obj",
|
|
492
|
+
"type": "TObj",
|
|
493
|
+
"description": "The source object"
|
|
494
|
+
},
|
|
495
|
+
{
|
|
496
|
+
"name": "mapValue",
|
|
497
|
+
"type": "function",
|
|
498
|
+
"description": "Callback called with `(value, key)` for each entry.\n Defaults to identity.",
|
|
499
|
+
"optional": true
|
|
500
|
+
},
|
|
501
|
+
{
|
|
502
|
+
"name": "mapKey",
|
|
503
|
+
"type": "function",
|
|
504
|
+
"description": "Callback called with `(key, value)` for each entry.\n Defaults to identity.",
|
|
505
|
+
"optional": true
|
|
506
|
+
}
|
|
507
|
+
],
|
|
508
|
+
"returns": {
|
|
509
|
+
"type": "Record<TKey, TVal>",
|
|
510
|
+
"description": "A new object with transformed keys and/or values"
|
|
511
|
+
},
|
|
512
|
+
"typeParameters": [
|
|
513
|
+
{
|
|
514
|
+
"name": "TObj",
|
|
515
|
+
"constraint": "Record<string, unknown>"
|
|
516
|
+
},
|
|
517
|
+
{
|
|
518
|
+
"name": "TVal",
|
|
519
|
+
"default": "indexedAccess"
|
|
520
|
+
},
|
|
521
|
+
{
|
|
522
|
+
"name": "TKey",
|
|
523
|
+
"constraint": "PropertyKey",
|
|
524
|
+
"default": "keyof TObj"
|
|
525
|
+
}
|
|
526
|
+
]
|
|
527
|
+
}
|
|
528
|
+
],
|
|
529
|
+
"examples": [
|
|
530
|
+
{
|
|
531
|
+
"title": "Transform values",
|
|
532
|
+
"description": "Maps each value of an object through a transform function.",
|
|
533
|
+
"code": "map({ a: 1, b: 2 }, v => v * 10)\n// => { a: 10, b: 20 }"
|
|
534
|
+
},
|
|
535
|
+
{
|
|
536
|
+
"title": "Transform keys",
|
|
537
|
+
"description": "Maps each key of an object through a transform function.",
|
|
538
|
+
"code": "map({ a: 1, b: 2 }, undefined, k => k.toUpperCase())\n// => { A: 1, B: 2 }"
|
|
539
|
+
},
|
|
540
|
+
{
|
|
541
|
+
"title": "Transform both keys and values in a single pass",
|
|
542
|
+
"description": "Provide both a value mapper and a key mapper to rewrite the whole object.",
|
|
543
|
+
"code": "map(\n { price: 100, discount: 20 },\n v => v / 100,\n k => `${k}Ratio`\n)\n// => { priceRatio: 1, discountRatio: 0.2 }"
|
|
544
|
+
}
|
|
545
|
+
],
|
|
546
|
+
"sourceFile": "map.ts"
|
|
547
|
+
},
|
|
296
548
|
{
|
|
297
549
|
"name": "omit",
|
|
298
550
|
"kind": "function",
|
|
@@ -546,7 +798,7 @@
|
|
|
546
798
|
"name": "safeJsonParse",
|
|
547
799
|
"kind": "function",
|
|
548
800
|
"description": "Parses a JSON string, returning `null` (or a fallback) on any parse failure.\n\nUnlike `JSON.parse`, this never throws. Invalid JSON strings and other\nparsing edge-cases resolve to `null` or the provided `fallback`.",
|
|
549
|
-
"since": "
|
|
801
|
+
"since": "2.0.0",
|
|
550
802
|
"signatures": [
|
|
551
803
|
{
|
|
552
804
|
"signature": "safeJsonParse<T>(input: string): T | null",
|
|
@@ -653,42 +905,6 @@
|
|
|
653
905
|
}
|
|
654
906
|
],
|
|
655
907
|
"sourceFile": "set.ts"
|
|
656
|
-
},
|
|
657
|
-
{
|
|
658
|
-
"name": "shallowEquals",
|
|
659
|
-
"kind": "function",
|
|
660
|
-
"description": "Quick comparison of two objects using JSON.stringify.\nThis is a fast but simple comparison that may not work for all edge cases.",
|
|
661
|
-
"since": "2.0.0",
|
|
662
|
-
"signatures": [
|
|
663
|
-
{
|
|
664
|
-
"signature": "shallowEquals(objA: unknown, objB: unknown): boolean",
|
|
665
|
-
"description": "Quick comparison of two objects using JSON.stringify.\nThis is a fast but simple comparison that may not work for all edge cases.",
|
|
666
|
-
"params": [
|
|
667
|
-
{
|
|
668
|
-
"name": "objA",
|
|
669
|
-
"type": "unknown",
|
|
670
|
-
"description": "First object to compare"
|
|
671
|
-
},
|
|
672
|
-
{
|
|
673
|
-
"name": "objB",
|
|
674
|
-
"type": "unknown",
|
|
675
|
-
"description": "Second object to compare"
|
|
676
|
-
}
|
|
677
|
-
],
|
|
678
|
-
"returns": {
|
|
679
|
-
"type": "boolean",
|
|
680
|
-
"description": "`true` if objects are identical according to JSON.stringify, `false` otherwise"
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
],
|
|
684
|
-
"examples": [
|
|
685
|
-
{
|
|
686
|
-
"title": "Compare two equal objects",
|
|
687
|
-
"description": "Uses JSON.stringify for a fast comparison.",
|
|
688
|
-
"code": "shallowEquals({ a: 1, b: 2 }, { a: 1, b: 2 })\n// => true"
|
|
689
|
-
}
|
|
690
|
-
],
|
|
691
|
-
"sourceFile": "shallowEquals.ts"
|
|
692
908
|
}
|
|
693
909
|
]
|
|
694
910
|
}
|
package/meta/examples.json
CHANGED
|
@@ -27,27 +27,52 @@
|
|
|
27
27
|
]
|
|
28
28
|
},
|
|
29
29
|
{
|
|
30
|
-
"name": "
|
|
30
|
+
"name": "deepMerge",
|
|
31
|
+
"examples": [
|
|
32
|
+
{
|
|
33
|
+
"title": "Merge two objects deeply",
|
|
34
|
+
"description": "Recursively merges source properties into the target object.",
|
|
35
|
+
"code": "deepMerge({ a: 1, b: { c: 2 } }, { b: { d: 3 }, e: 4 })\n// => { a: 1, b: { c: 2, d: 3 }, e: 4 }"
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"name": "diff",
|
|
31
41
|
"examples": [
|
|
32
42
|
{
|
|
33
43
|
"title": "Compare nested objects",
|
|
34
44
|
"description": "Deeply compares two objects, returning true when they are structurally equal.",
|
|
35
|
-
"code": "
|
|
45
|
+
"code": "diff({ a: { b: 1 } }, { a: { b: 1 } })\n// => true"
|
|
36
46
|
},
|
|
37
47
|
{
|
|
38
48
|
"title": "Detect deep differences",
|
|
39
49
|
"description": "Returns a detailed diff object when nested values differ.",
|
|
40
|
-
"code": "
|
|
50
|
+
"code": "diff({ a: { b: 1 } }, { a: { b: 2 } })\n// => { a: { b: false } }"
|
|
41
51
|
}
|
|
42
52
|
]
|
|
43
53
|
},
|
|
44
54
|
{
|
|
45
|
-
"name": "
|
|
55
|
+
"name": "equalsDeep",
|
|
46
56
|
"examples": [
|
|
47
57
|
{
|
|
48
|
-
"title": "
|
|
49
|
-
"description": "
|
|
50
|
-
"code": "
|
|
58
|
+
"title": "Compare nested objects",
|
|
59
|
+
"description": "Recursive structural equality. Returns true when the two values are deeply equal.",
|
|
60
|
+
"code": "equalsDeep({ a: { b: 1 } }, { a: { b: 1 } })\n// => true"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"title": "Detect deep differences",
|
|
64
|
+
"description": "Returns false when nested values differ.",
|
|
65
|
+
"code": "equalsDeep({ a: { b: 1 } }, { a: { b: 2 } })\n// => false"
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"name": "equalsShallow",
|
|
71
|
+
"examples": [
|
|
72
|
+
{
|
|
73
|
+
"title": "Compare two equal objects",
|
|
74
|
+
"description": "Uses JSON.stringify for a fast comparison.",
|
|
75
|
+
"code": "equalsShallow({ a: 1, b: 2 }, { a: 1, b: 2 })\n// => true"
|
|
51
76
|
}
|
|
52
77
|
]
|
|
53
78
|
},
|
|
@@ -66,6 +91,56 @@
|
|
|
66
91
|
}
|
|
67
92
|
]
|
|
68
93
|
},
|
|
94
|
+
{
|
|
95
|
+
"name": "groupBy",
|
|
96
|
+
"examples": [
|
|
97
|
+
{
|
|
98
|
+
"title": "Group numbers by parity",
|
|
99
|
+
"description": "Groups elements by the string key returned by the callback.",
|
|
100
|
+
"code": "groupBy([1, 2, 3, 4], n => n % 2 === 0 ? 'even' : 'odd')\n// => { odd: [1, 3], even: [2, 4] }"
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"title": "Group objects by a property",
|
|
104
|
+
"description": "Use a property accessor as the grouping key.",
|
|
105
|
+
"code": "const users = [\n { name: 'Alice', role: 'admin' },\n { name: 'Bob', role: 'user' },\n { name: 'Carol', role: 'admin' },\n];\ngroupBy(users, u => u.role)\n// => { admin: [{...Alice}, {...Carol}], user: [{...Bob}] }"
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"name": "invert",
|
|
111
|
+
"examples": [
|
|
112
|
+
{
|
|
113
|
+
"title": "Swap keys and values",
|
|
114
|
+
"description": "Returns a new object with keys and values swapped.",
|
|
115
|
+
"code": "invert({ a: 'x', b: 'y', c: 'z' })\n// => { x: 'a', y: 'b', z: 'c' }"
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"title": "Build a reverse lookup map",
|
|
119
|
+
"description": "Useful when you have a code-to-label map and need label-to-code.",
|
|
120
|
+
"code": "const STATUS_LABELS = { 200: 'OK', 404: 'Not Found', 500: 'Internal Server Error' };\nconst LABEL_TO_CODE = invert(STATUS_LABELS);\n\nLABEL_TO_CODE['OK']; // => '200'"
|
|
121
|
+
}
|
|
122
|
+
]
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"name": "map",
|
|
126
|
+
"examples": [
|
|
127
|
+
{
|
|
128
|
+
"title": "Transform values",
|
|
129
|
+
"description": "Maps each value of an object through a transform function.",
|
|
130
|
+
"code": "map({ a: 1, b: 2 }, v => v * 10)\n// => { a: 10, b: 20 }"
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"title": "Transform keys",
|
|
134
|
+
"description": "Maps each key of an object through a transform function.",
|
|
135
|
+
"code": "map({ a: 1, b: 2 }, undefined, k => k.toUpperCase())\n// => { A: 1, B: 2 }"
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
"title": "Transform both keys and values in a single pass",
|
|
139
|
+
"description": "Provide both a value mapper and a key mapper to rewrite the whole object.",
|
|
140
|
+
"code": "map(\n { price: 100, discount: 20 },\n v => v / 100,\n k => `${k}Ratio`\n)\n// => { priceRatio: 1, discountRatio: 0.2 }"
|
|
141
|
+
}
|
|
142
|
+
]
|
|
143
|
+
},
|
|
69
144
|
{
|
|
70
145
|
"name": "omit",
|
|
71
146
|
"examples": [
|
|
@@ -135,16 +210,6 @@
|
|
|
135
210
|
"code": "set({}, 'a.b.c', 42)\n// => { a: { b: { c: 42 } } }"
|
|
136
211
|
}
|
|
137
212
|
]
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
"name": "shallowEquals",
|
|
141
|
-
"examples": [
|
|
142
|
-
{
|
|
143
|
-
"title": "Compare two equal objects",
|
|
144
|
-
"description": "Uses JSON.stringify for a fast comparison.",
|
|
145
|
-
"code": "shallowEquals({ a: 1, b: 2 }, { a: 1, b: 2 })\n// => true"
|
|
146
|
-
}
|
|
147
|
-
]
|
|
148
213
|
}
|
|
149
214
|
]
|
|
150
215
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helpers4/object",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "A set of helpers in TS/JS, compatible with tree-shaking, for object.",
|
|
5
5
|
"author": "baxyz <baxy@etik.com>",
|
|
6
6
|
"license": "LGPL-3.0",
|
|
@@ -29,15 +29,19 @@
|
|
|
29
29
|
"object",
|
|
30
30
|
"compact",
|
|
31
31
|
"deepClone",
|
|
32
|
-
"deepCompare",
|
|
33
32
|
"deepMerge",
|
|
33
|
+
"diff",
|
|
34
|
+
"equalsDeep",
|
|
35
|
+
"equalsShallow",
|
|
34
36
|
"get",
|
|
37
|
+
"groupBy",
|
|
38
|
+
"invert",
|
|
39
|
+
"map",
|
|
35
40
|
"omit",
|
|
36
41
|
"pick",
|
|
37
42
|
"removeUndefinedNull",
|
|
38
43
|
"safeJsonParse",
|
|
39
|
-
"set"
|
|
40
|
-
"shallowEquals"
|
|
44
|
+
"set"
|
|
41
45
|
],
|
|
42
46
|
"files": [
|
|
43
47
|
"lib/index.js",
|