@helpers4/object 2.0.0-alpha.9 → 2.0.0-beta.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 +11 -5
- package/lib/index.d.ts +92 -11
- package/lib/index.js +227 -45
- package/lib/index.js.map +1 -1
- package/llms.txt +577 -0
- package/meta/api.json +400 -37
- package/meta/category.json +6 -0
- package/meta/examples.json +69 -4
- package/meta/licenses.json +1 -8
- package/meta/native-alternatives.json +50 -0
- package/package.json +9 -6
package/meta/api.json
CHANGED
|
@@ -1,7 +1,79 @@
|
|
|
1
1
|
{
|
|
2
2
|
"category": "object",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-beta.0",
|
|
4
4
|
"functions": [
|
|
5
|
+
{
|
|
6
|
+
"name": "compact",
|
|
7
|
+
"kind": "function",
|
|
8
|
+
"description": "Removes all entries with falsy values (`false`, `null`, `undefined`, `0`, `\"\"`, `NaN`) from an object.",
|
|
9
|
+
"since": "2.0.0",
|
|
10
|
+
"signatures": [
|
|
11
|
+
{
|
|
12
|
+
"signature": "compact<T extends Record<string, unknown>>(obj: T): Partial<T>",
|
|
13
|
+
"description": "Removes all entries with falsy values (`false`, `null`, `undefined`, `0`, `\"\"`, `NaN`) from an object.",
|
|
14
|
+
"params": [
|
|
15
|
+
{
|
|
16
|
+
"name": "obj",
|
|
17
|
+
"type": "T",
|
|
18
|
+
"description": "The source object"
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"returns": {
|
|
22
|
+
"type": "Partial<T>",
|
|
23
|
+
"description": "A new object containing only entries with truthy values"
|
|
24
|
+
},
|
|
25
|
+
"typeParameters": [
|
|
26
|
+
{
|
|
27
|
+
"name": "T",
|
|
28
|
+
"constraint": "Record<string, unknown>"
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"signature": "compact(obj: undefined): undefined",
|
|
34
|
+
"description": "Removes all entries with falsy values (`false`, `null`, `undefined`, `0`, `\"\"`, `NaN`) from an object.",
|
|
35
|
+
"params": [
|
|
36
|
+
{
|
|
37
|
+
"name": "obj",
|
|
38
|
+
"type": "undefined",
|
|
39
|
+
"description": "The source object"
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
"returns": {
|
|
43
|
+
"type": "undefined",
|
|
44
|
+
"description": "A new object containing only entries with truthy values"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"signature": "compact(obj: null): null",
|
|
49
|
+
"description": "Removes all entries with falsy values (`false`, `null`, `undefined`, `0`, `\"\"`, `NaN`) from an object.",
|
|
50
|
+
"params": [
|
|
51
|
+
{
|
|
52
|
+
"name": "obj",
|
|
53
|
+
"type": "null",
|
|
54
|
+
"description": "The source object"
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
|
+
"returns": {
|
|
58
|
+
"type": "null",
|
|
59
|
+
"description": "A new object containing only entries with truthy values"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
],
|
|
63
|
+
"examples": [
|
|
64
|
+
{
|
|
65
|
+
"title": "Remove falsy values from object",
|
|
66
|
+
"description": "Removes all entries with falsy values (false, null, undefined, 0, \"\", NaN).",
|
|
67
|
+
"code": "compact({ a: 1, b: null, c: '', d: 0, e: 'hello' })\n// => { a: 1, e: 'hello' }"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"title": "Clean up API response",
|
|
71
|
+
"description": "Useful to strip empty or missing fields before sending data.",
|
|
72
|
+
"code": "compact({ name: 'Alice', email: '', age: 0, role: 'admin' })\n// => { name: 'Alice', role: 'admin' }"
|
|
73
|
+
}
|
|
74
|
+
],
|
|
75
|
+
"sourceFile": "compact.ts"
|
|
76
|
+
},
|
|
5
77
|
{
|
|
6
78
|
"name": "deepClone",
|
|
7
79
|
"kind": "function",
|
|
@@ -77,16 +149,14 @@
|
|
|
77
149
|
"code": "deepCompare({ a: { b: 1 } }, { a: { b: 2 } })\n// => { a: { b: false } }"
|
|
78
150
|
}
|
|
79
151
|
],
|
|
80
|
-
"sourceFile": "deepCompare.ts"
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
"examples": [],
|
|
89
|
-
"sourceFile": "deepCompare.ts"
|
|
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
|
+
]
|
|
90
160
|
},
|
|
91
161
|
{
|
|
92
162
|
"name": "deepMerge",
|
|
@@ -95,7 +165,7 @@
|
|
|
95
165
|
"since": "1.9.0",
|
|
96
166
|
"signatures": [
|
|
97
167
|
{
|
|
98
|
-
"signature": "deepMerge<T extends Record<string,
|
|
168
|
+
"signature": "deepMerge<T extends Record<string, unknown>>(target: T, sources: Record<string, unknown>[]): T",
|
|
99
169
|
"description": "Merges two or more objects deeply",
|
|
100
170
|
"params": [
|
|
101
171
|
{
|
|
@@ -105,7 +175,7 @@
|
|
|
105
175
|
},
|
|
106
176
|
{
|
|
107
177
|
"name": "sources",
|
|
108
|
-
"type": "Record<string,
|
|
178
|
+
"type": "Record<string, unknown>[]",
|
|
109
179
|
"description": "The source objects to merge"
|
|
110
180
|
}
|
|
111
181
|
],
|
|
@@ -116,9 +186,49 @@
|
|
|
116
186
|
"typeParameters": [
|
|
117
187
|
{
|
|
118
188
|
"name": "T",
|
|
119
|
-
"constraint": "Record<string,
|
|
189
|
+
"constraint": "Record<string, unknown>"
|
|
120
190
|
}
|
|
121
191
|
]
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
"signature": "deepMerge(target: undefined, sources: Record<string, unknown>[]): undefined",
|
|
195
|
+
"description": "Merges two or more objects deeply",
|
|
196
|
+
"params": [
|
|
197
|
+
{
|
|
198
|
+
"name": "target",
|
|
199
|
+
"type": "undefined",
|
|
200
|
+
"description": "The target object"
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
"name": "sources",
|
|
204
|
+
"type": "Record<string, unknown>[]",
|
|
205
|
+
"description": "The source objects to merge"
|
|
206
|
+
}
|
|
207
|
+
],
|
|
208
|
+
"returns": {
|
|
209
|
+
"type": "undefined",
|
|
210
|
+
"description": "The merged object"
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
"signature": "deepMerge(target: null, sources: Record<string, unknown>[]): null",
|
|
215
|
+
"description": "Merges two or more objects deeply",
|
|
216
|
+
"params": [
|
|
217
|
+
{
|
|
218
|
+
"name": "target",
|
|
219
|
+
"type": "null",
|
|
220
|
+
"description": "The target object"
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
"name": "sources",
|
|
224
|
+
"type": "Record<string, unknown>[]",
|
|
225
|
+
"description": "The source objects to merge"
|
|
226
|
+
}
|
|
227
|
+
],
|
|
228
|
+
"returns": {
|
|
229
|
+
"type": "null",
|
|
230
|
+
"description": "The merged object"
|
|
231
|
+
}
|
|
122
232
|
}
|
|
123
233
|
],
|
|
124
234
|
"examples": [
|
|
@@ -137,12 +247,12 @@
|
|
|
137
247
|
"since": "1.9.0",
|
|
138
248
|
"signatures": [
|
|
139
249
|
{
|
|
140
|
-
"signature": "get<T =
|
|
250
|
+
"signature": "get<T = unknown>(obj: unknown, path: string, defaultValue?: T): T | undefined",
|
|
141
251
|
"description": "Gets a value from an object using a dot-notated path",
|
|
142
252
|
"params": [
|
|
143
253
|
{
|
|
144
254
|
"name": "obj",
|
|
145
|
-
"type": "
|
|
255
|
+
"type": "unknown",
|
|
146
256
|
"description": "The object to get value from"
|
|
147
257
|
},
|
|
148
258
|
{
|
|
@@ -164,7 +274,7 @@
|
|
|
164
274
|
"typeParameters": [
|
|
165
275
|
{
|
|
166
276
|
"name": "T",
|
|
167
|
-
"default": "
|
|
277
|
+
"default": "unknown"
|
|
168
278
|
}
|
|
169
279
|
]
|
|
170
280
|
}
|
|
@@ -184,40 +294,186 @@
|
|
|
184
294
|
"sourceFile": "get.ts"
|
|
185
295
|
},
|
|
186
296
|
{
|
|
187
|
-
"name": "
|
|
297
|
+
"name": "omit",
|
|
188
298
|
"kind": "function",
|
|
189
|
-
"description": "
|
|
299
|
+
"description": "Creates a new object without the specified keys.",
|
|
190
300
|
"since": "2.0.0",
|
|
191
301
|
"signatures": [
|
|
192
302
|
{
|
|
193
|
-
"signature": "
|
|
194
|
-
"description": "
|
|
303
|
+
"signature": "omit<T extends Record<string, unknown>, K extends string | number | symbol>(obj: T, keys: readonly K[]): Omit<T, K>",
|
|
304
|
+
"description": "Creates a new object without the specified keys.",
|
|
195
305
|
"params": [
|
|
196
306
|
{
|
|
197
|
-
"name": "
|
|
198
|
-
"type": "
|
|
199
|
-
"description": "
|
|
307
|
+
"name": "obj",
|
|
308
|
+
"type": "T",
|
|
309
|
+
"description": "The source object"
|
|
200
310
|
},
|
|
201
311
|
{
|
|
202
|
-
"name": "
|
|
203
|
-
"type": "
|
|
204
|
-
"description": "
|
|
312
|
+
"name": "keys",
|
|
313
|
+
"type": "readonly K[]",
|
|
314
|
+
"description": "The keys to omit"
|
|
205
315
|
}
|
|
206
316
|
],
|
|
207
317
|
"returns": {
|
|
208
|
-
"type": "
|
|
209
|
-
"description": "
|
|
318
|
+
"type": "Omit<T, K>",
|
|
319
|
+
"description": "A new object without the omitted keys"
|
|
320
|
+
},
|
|
321
|
+
"typeParameters": [
|
|
322
|
+
{
|
|
323
|
+
"name": "T",
|
|
324
|
+
"constraint": "Record<string, unknown>"
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
"name": "K",
|
|
328
|
+
"constraint": "string | number | symbol"
|
|
329
|
+
}
|
|
330
|
+
]
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
"signature": "omit(obj: undefined, keys: readonly string[]): undefined",
|
|
334
|
+
"description": "Creates a new object without the specified keys.",
|
|
335
|
+
"params": [
|
|
336
|
+
{
|
|
337
|
+
"name": "obj",
|
|
338
|
+
"type": "undefined",
|
|
339
|
+
"description": "The source object"
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
"name": "keys",
|
|
343
|
+
"type": "readonly string[]",
|
|
344
|
+
"description": "The keys to omit"
|
|
345
|
+
}
|
|
346
|
+
],
|
|
347
|
+
"returns": {
|
|
348
|
+
"type": "undefined",
|
|
349
|
+
"description": "A new object without the omitted keys"
|
|
350
|
+
}
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
"signature": "omit(obj: null, keys: readonly string[]): null",
|
|
354
|
+
"description": "Creates a new object without the specified keys.",
|
|
355
|
+
"params": [
|
|
356
|
+
{
|
|
357
|
+
"name": "obj",
|
|
358
|
+
"type": "null",
|
|
359
|
+
"description": "The source object"
|
|
360
|
+
},
|
|
361
|
+
{
|
|
362
|
+
"name": "keys",
|
|
363
|
+
"type": "readonly string[]",
|
|
364
|
+
"description": "The keys to omit"
|
|
365
|
+
}
|
|
366
|
+
],
|
|
367
|
+
"returns": {
|
|
368
|
+
"type": "null",
|
|
369
|
+
"description": "A new object without the omitted keys"
|
|
210
370
|
}
|
|
211
371
|
}
|
|
212
372
|
],
|
|
213
373
|
"examples": [
|
|
214
374
|
{
|
|
215
|
-
"title": "
|
|
216
|
-
"description": "
|
|
217
|
-
"code": "
|
|
375
|
+
"title": "Omit specific keys",
|
|
376
|
+
"description": "Creates a new object without the specified keys.",
|
|
377
|
+
"code": "omit({ a: 1, b: 2, c: 3 }, ['b'])\n// => { a: 1, c: 3 }"
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
"title": "Remove sensitive fields",
|
|
381
|
+
"description": "Useful to strip sensitive data before sending to client.",
|
|
382
|
+
"code": "const user = { id: 1, name: 'Alice', password: 'secret', token: 'abc123' };\nomit(user, ['password', 'token'])\n// => { id: 1, name: 'Alice' }"
|
|
218
383
|
}
|
|
219
384
|
],
|
|
220
|
-
"sourceFile": "
|
|
385
|
+
"sourceFile": "omit.ts"
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
"name": "pick",
|
|
389
|
+
"kind": "function",
|
|
390
|
+
"description": "Creates a new object with only the specified keys.",
|
|
391
|
+
"since": "2.0.0",
|
|
392
|
+
"signatures": [
|
|
393
|
+
{
|
|
394
|
+
"signature": "pick<T extends Record<string, unknown>, K extends string | number | symbol>(obj: T, keys: readonly K[]): Pick<T, K>",
|
|
395
|
+
"description": "Creates a new object with only the specified keys.",
|
|
396
|
+
"params": [
|
|
397
|
+
{
|
|
398
|
+
"name": "obj",
|
|
399
|
+
"type": "T",
|
|
400
|
+
"description": "The source object"
|
|
401
|
+
},
|
|
402
|
+
{
|
|
403
|
+
"name": "keys",
|
|
404
|
+
"type": "readonly K[]",
|
|
405
|
+
"description": "The keys to pick"
|
|
406
|
+
}
|
|
407
|
+
],
|
|
408
|
+
"returns": {
|
|
409
|
+
"type": "Pick<T, K>",
|
|
410
|
+
"description": "A new object with only the picked keys"
|
|
411
|
+
},
|
|
412
|
+
"typeParameters": [
|
|
413
|
+
{
|
|
414
|
+
"name": "T",
|
|
415
|
+
"constraint": "Record<string, unknown>"
|
|
416
|
+
},
|
|
417
|
+
{
|
|
418
|
+
"name": "K",
|
|
419
|
+
"constraint": "string | number | symbol"
|
|
420
|
+
}
|
|
421
|
+
]
|
|
422
|
+
},
|
|
423
|
+
{
|
|
424
|
+
"signature": "pick(obj: undefined, keys: readonly string[]): undefined",
|
|
425
|
+
"description": "Creates a new object with only the specified keys.",
|
|
426
|
+
"params": [
|
|
427
|
+
{
|
|
428
|
+
"name": "obj",
|
|
429
|
+
"type": "undefined",
|
|
430
|
+
"description": "The source object"
|
|
431
|
+
},
|
|
432
|
+
{
|
|
433
|
+
"name": "keys",
|
|
434
|
+
"type": "readonly string[]",
|
|
435
|
+
"description": "The keys to pick"
|
|
436
|
+
}
|
|
437
|
+
],
|
|
438
|
+
"returns": {
|
|
439
|
+
"type": "undefined",
|
|
440
|
+
"description": "A new object with only the picked keys"
|
|
441
|
+
}
|
|
442
|
+
},
|
|
443
|
+
{
|
|
444
|
+
"signature": "pick(obj: null, keys: readonly string[]): null",
|
|
445
|
+
"description": "Creates a new object with only the specified keys.",
|
|
446
|
+
"params": [
|
|
447
|
+
{
|
|
448
|
+
"name": "obj",
|
|
449
|
+
"type": "null",
|
|
450
|
+
"description": "The source object"
|
|
451
|
+
},
|
|
452
|
+
{
|
|
453
|
+
"name": "keys",
|
|
454
|
+
"type": "readonly string[]",
|
|
455
|
+
"description": "The keys to pick"
|
|
456
|
+
}
|
|
457
|
+
],
|
|
458
|
+
"returns": {
|
|
459
|
+
"type": "null",
|
|
460
|
+
"description": "A new object with only the picked keys"
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
],
|
|
464
|
+
"examples": [
|
|
465
|
+
{
|
|
466
|
+
"title": "Pick specific keys",
|
|
467
|
+
"description": "Creates a new object with only the specified keys.",
|
|
468
|
+
"code": "pick({ a: 1, b: 2, c: 3 }, ['a', 'c'])\n// => { a: 1, c: 3 }"
|
|
469
|
+
},
|
|
470
|
+
{
|
|
471
|
+
"title": "Extract user fields",
|
|
472
|
+
"description": "Useful to select only the fields you need from an object.",
|
|
473
|
+
"code": "const user = { id: 1, name: 'Alice', email: 'alice@example.com', password: 'secret' };\npick(user, ['id', 'name', 'email'])\n// => { id: 1, name: 'Alice', email: 'alice@example.com' }"
|
|
474
|
+
}
|
|
475
|
+
],
|
|
476
|
+
"sourceFile": "pick.ts"
|
|
221
477
|
},
|
|
222
478
|
{
|
|
223
479
|
"name": "removeUndefinedNull",
|
|
@@ -286,6 +542,77 @@
|
|
|
286
542
|
],
|
|
287
543
|
"sourceFile": "removeUndefinedNull.ts"
|
|
288
544
|
},
|
|
545
|
+
{
|
|
546
|
+
"name": "safeJsonParse",
|
|
547
|
+
"kind": "function",
|
|
548
|
+
"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": "next",
|
|
550
|
+
"signatures": [
|
|
551
|
+
{
|
|
552
|
+
"signature": "safeJsonParse<T>(input: string): T | null",
|
|
553
|
+
"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`.",
|
|
554
|
+
"params": [
|
|
555
|
+
{
|
|
556
|
+
"name": "input",
|
|
557
|
+
"type": "string",
|
|
558
|
+
"description": "The JSON string to parse."
|
|
559
|
+
}
|
|
560
|
+
],
|
|
561
|
+
"returns": {
|
|
562
|
+
"type": "T | null",
|
|
563
|
+
"description": "The parsed value typed as `T`, or `fallback` on failure."
|
|
564
|
+
},
|
|
565
|
+
"typeParameters": [
|
|
566
|
+
{
|
|
567
|
+
"name": "T"
|
|
568
|
+
}
|
|
569
|
+
]
|
|
570
|
+
},
|
|
571
|
+
{
|
|
572
|
+
"signature": "safeJsonParse<T>(input: string, fallback: T): T",
|
|
573
|
+
"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`.",
|
|
574
|
+
"params": [
|
|
575
|
+
{
|
|
576
|
+
"name": "input",
|
|
577
|
+
"type": "string",
|
|
578
|
+
"description": "The JSON string to parse."
|
|
579
|
+
},
|
|
580
|
+
{
|
|
581
|
+
"name": "fallback",
|
|
582
|
+
"type": "T",
|
|
583
|
+
"description": "Value returned on failure. Defaults to `null` when omitted."
|
|
584
|
+
}
|
|
585
|
+
],
|
|
586
|
+
"returns": {
|
|
587
|
+
"type": "T",
|
|
588
|
+
"description": "The parsed value typed as `T`, or `fallback` on failure."
|
|
589
|
+
},
|
|
590
|
+
"typeParameters": [
|
|
591
|
+
{
|
|
592
|
+
"name": "T"
|
|
593
|
+
}
|
|
594
|
+
]
|
|
595
|
+
}
|
|
596
|
+
],
|
|
597
|
+
"examples": [
|
|
598
|
+
{
|
|
599
|
+
"title": "Parse valid JSON",
|
|
600
|
+
"description": "Returns the parsed value when the input is valid JSON.",
|
|
601
|
+
"code": "safeJsonParse<{ a: number }>('{\"a\":1}')\n// => { a: 1 }"
|
|
602
|
+
},
|
|
603
|
+
{
|
|
604
|
+
"title": "Return null on invalid input",
|
|
605
|
+
"description": "Returns null instead of throwing when JSON is malformed.",
|
|
606
|
+
"code": "safeJsonParse('invalid')\n// => null"
|
|
607
|
+
},
|
|
608
|
+
{
|
|
609
|
+
"title": "Use a fallback value",
|
|
610
|
+
"description": "Returns the provided fallback when parsing fails.",
|
|
611
|
+
"code": "safeJsonParse('invalid', [])\n// => []"
|
|
612
|
+
}
|
|
613
|
+
],
|
|
614
|
+
"sourceFile": "safeJsonParse.ts"
|
|
615
|
+
},
|
|
289
616
|
{
|
|
290
617
|
"name": "set",
|
|
291
618
|
"kind": "function",
|
|
@@ -293,12 +620,12 @@
|
|
|
293
620
|
"since": "1.9.0",
|
|
294
621
|
"signatures": [
|
|
295
622
|
{
|
|
296
|
-
"signature": "set(obj: Record<string,
|
|
623
|
+
"signature": "set(obj: Record<string, unknown>, path: string, value: unknown): Record<string, unknown>",
|
|
297
624
|
"description": "Sets a value in an object using a dot-notated path",
|
|
298
625
|
"params": [
|
|
299
626
|
{
|
|
300
627
|
"name": "obj",
|
|
301
|
-
"type": "Record<string,
|
|
628
|
+
"type": "Record<string, unknown>",
|
|
302
629
|
"description": "The object to set value in"
|
|
303
630
|
},
|
|
304
631
|
{
|
|
@@ -308,12 +635,12 @@
|
|
|
308
635
|
},
|
|
309
636
|
{
|
|
310
637
|
"name": "value",
|
|
311
|
-
"type": "
|
|
638
|
+
"type": "unknown",
|
|
312
639
|
"description": "The value to set"
|
|
313
640
|
}
|
|
314
641
|
],
|
|
315
642
|
"returns": {
|
|
316
|
-
"type": "Record<string,
|
|
643
|
+
"type": "Record<string, unknown>",
|
|
317
644
|
"description": "The modified object"
|
|
318
645
|
}
|
|
319
646
|
}
|
|
@@ -326,6 +653,42 @@
|
|
|
326
653
|
}
|
|
327
654
|
],
|
|
328
655
|
"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"
|
|
329
692
|
}
|
|
330
693
|
]
|
|
331
694
|
}
|
package/meta/examples.json
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"category": "object",
|
|
3
3
|
"functions": [
|
|
4
|
+
{
|
|
5
|
+
"name": "compact",
|
|
6
|
+
"examples": [
|
|
7
|
+
{
|
|
8
|
+
"title": "Remove falsy values from object",
|
|
9
|
+
"description": "Removes all entries with falsy values (false, null, undefined, 0, \"\", NaN).",
|
|
10
|
+
"code": "compact({ a: 1, b: null, c: '', d: 0, e: 'hello' })\n// => { a: 1, e: 'hello' }"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"title": "Clean up API response",
|
|
14
|
+
"description": "Useful to strip empty or missing fields before sending data.",
|
|
15
|
+
"code": "compact({ name: 'Alice', email: '', age: 0, role: 'admin' })\n// => { name: 'Alice', role: 'admin' }"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
},
|
|
4
19
|
{
|
|
5
20
|
"name": "deepClone",
|
|
6
21
|
"examples": [
|
|
@@ -52,12 +67,32 @@
|
|
|
52
67
|
]
|
|
53
68
|
},
|
|
54
69
|
{
|
|
55
|
-
"name": "
|
|
70
|
+
"name": "omit",
|
|
56
71
|
"examples": [
|
|
57
72
|
{
|
|
58
|
-
"title": "
|
|
59
|
-
"description": "
|
|
60
|
-
"code": "
|
|
73
|
+
"title": "Omit specific keys",
|
|
74
|
+
"description": "Creates a new object without the specified keys.",
|
|
75
|
+
"code": "omit({ a: 1, b: 2, c: 3 }, ['b'])\n// => { a: 1, c: 3 }"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"title": "Remove sensitive fields",
|
|
79
|
+
"description": "Useful to strip sensitive data before sending to client.",
|
|
80
|
+
"code": "const user = { id: 1, name: 'Alice', password: 'secret', token: 'abc123' };\nomit(user, ['password', 'token'])\n// => { id: 1, name: 'Alice' }"
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"name": "pick",
|
|
86
|
+
"examples": [
|
|
87
|
+
{
|
|
88
|
+
"title": "Pick specific keys",
|
|
89
|
+
"description": "Creates a new object with only the specified keys.",
|
|
90
|
+
"code": "pick({ a: 1, b: 2, c: 3 }, ['a', 'c'])\n// => { a: 1, c: 3 }"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"title": "Extract user fields",
|
|
94
|
+
"description": "Useful to select only the fields you need from an object.",
|
|
95
|
+
"code": "const user = { id: 1, name: 'Alice', email: 'alice@example.com', password: 'secret' };\npick(user, ['id', 'name', 'email'])\n// => { id: 1, name: 'Alice', email: 'alice@example.com' }"
|
|
61
96
|
}
|
|
62
97
|
]
|
|
63
98
|
},
|
|
@@ -71,6 +106,26 @@
|
|
|
71
106
|
}
|
|
72
107
|
]
|
|
73
108
|
},
|
|
109
|
+
{
|
|
110
|
+
"name": "safeJsonParse",
|
|
111
|
+
"examples": [
|
|
112
|
+
{
|
|
113
|
+
"title": "Parse valid JSON",
|
|
114
|
+
"description": "Returns the parsed value when the input is valid JSON.",
|
|
115
|
+
"code": "safeJsonParse<{ a: number }>('{\"a\":1}')\n// => { a: 1 }"
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"title": "Return null on invalid input",
|
|
119
|
+
"description": "Returns null instead of throwing when JSON is malformed.",
|
|
120
|
+
"code": "safeJsonParse('invalid')\n// => null"
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
"title": "Use a fallback value",
|
|
124
|
+
"description": "Returns the provided fallback when parsing fails.",
|
|
125
|
+
"code": "safeJsonParse('invalid', [])\n// => []"
|
|
126
|
+
}
|
|
127
|
+
]
|
|
128
|
+
},
|
|
74
129
|
{
|
|
75
130
|
"name": "set",
|
|
76
131
|
"examples": [
|
|
@@ -80,6 +135,16 @@
|
|
|
80
135
|
"code": "set({}, 'a.b.c', 42)\n// => { a: { b: { c: 42 } } }"
|
|
81
136
|
}
|
|
82
137
|
]
|
|
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
|
+
]
|
|
83
148
|
}
|
|
84
149
|
]
|
|
85
150
|
}
|
package/meta/licenses.json
CHANGED