@helpers4/object 2.0.0-alpha.10 → 2.0.0-alpha.14
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 +3 -0
- package/lib/index.d.ts +62 -4
- package/lib/index.js +94 -16
- package/lib/index.js.map +1 -1
- package/llms.txt +520 -0
- package/meta/api.json +305 -11
- package/meta/examples.json +45 -0
- package/meta/licenses.json +1 -8
- package/package.json +6 -4
package/meta/api.json
CHANGED
|
@@ -1,7 +1,79 @@
|
|
|
1
1
|
{
|
|
2
2
|
"category": "object",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.14",
|
|
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",
|
|
@@ -95,7 +167,7 @@
|
|
|
95
167
|
"since": "1.9.0",
|
|
96
168
|
"signatures": [
|
|
97
169
|
{
|
|
98
|
-
"signature": "deepMerge<T extends Record<string,
|
|
170
|
+
"signature": "deepMerge<T extends Record<string, unknown>>(target: T, sources: Record<string, unknown>[]): T",
|
|
99
171
|
"description": "Merges two or more objects deeply",
|
|
100
172
|
"params": [
|
|
101
173
|
{
|
|
@@ -105,7 +177,7 @@
|
|
|
105
177
|
},
|
|
106
178
|
{
|
|
107
179
|
"name": "sources",
|
|
108
|
-
"type": "Record<string,
|
|
180
|
+
"type": "Record<string, unknown>[]",
|
|
109
181
|
"description": "The source objects to merge"
|
|
110
182
|
}
|
|
111
183
|
],
|
|
@@ -116,9 +188,49 @@
|
|
|
116
188
|
"typeParameters": [
|
|
117
189
|
{
|
|
118
190
|
"name": "T",
|
|
119
|
-
"constraint": "Record<string,
|
|
191
|
+
"constraint": "Record<string, unknown>"
|
|
120
192
|
}
|
|
121
193
|
]
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
"signature": "deepMerge(target: undefined, sources: Record<string, unknown>[]): undefined",
|
|
197
|
+
"description": "Merges two or more objects deeply",
|
|
198
|
+
"params": [
|
|
199
|
+
{
|
|
200
|
+
"name": "target",
|
|
201
|
+
"type": "undefined",
|
|
202
|
+
"description": "The target object"
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
"name": "sources",
|
|
206
|
+
"type": "Record<string, unknown>[]",
|
|
207
|
+
"description": "The source objects to merge"
|
|
208
|
+
}
|
|
209
|
+
],
|
|
210
|
+
"returns": {
|
|
211
|
+
"type": "undefined",
|
|
212
|
+
"description": "The merged object"
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
"signature": "deepMerge(target: null, sources: Record<string, unknown>[]): null",
|
|
217
|
+
"description": "Merges two or more objects deeply",
|
|
218
|
+
"params": [
|
|
219
|
+
{
|
|
220
|
+
"name": "target",
|
|
221
|
+
"type": "null",
|
|
222
|
+
"description": "The target object"
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
"name": "sources",
|
|
226
|
+
"type": "Record<string, unknown>[]",
|
|
227
|
+
"description": "The source objects to merge"
|
|
228
|
+
}
|
|
229
|
+
],
|
|
230
|
+
"returns": {
|
|
231
|
+
"type": "null",
|
|
232
|
+
"description": "The merged object"
|
|
233
|
+
}
|
|
122
234
|
}
|
|
123
235
|
],
|
|
124
236
|
"examples": [
|
|
@@ -137,12 +249,12 @@
|
|
|
137
249
|
"since": "1.9.0",
|
|
138
250
|
"signatures": [
|
|
139
251
|
{
|
|
140
|
-
"signature": "get<T =
|
|
252
|
+
"signature": "get<T = unknown>(obj: unknown, path: string, defaultValue?: T): T | undefined",
|
|
141
253
|
"description": "Gets a value from an object using a dot-notated path",
|
|
142
254
|
"params": [
|
|
143
255
|
{
|
|
144
256
|
"name": "obj",
|
|
145
|
-
"type": "
|
|
257
|
+
"type": "unknown",
|
|
146
258
|
"description": "The object to get value from"
|
|
147
259
|
},
|
|
148
260
|
{
|
|
@@ -164,7 +276,7 @@
|
|
|
164
276
|
"typeParameters": [
|
|
165
277
|
{
|
|
166
278
|
"name": "T",
|
|
167
|
-
"default": "
|
|
279
|
+
"default": "unknown"
|
|
168
280
|
}
|
|
169
281
|
]
|
|
170
282
|
}
|
|
@@ -183,6 +295,188 @@
|
|
|
183
295
|
],
|
|
184
296
|
"sourceFile": "get.ts"
|
|
185
297
|
},
|
|
298
|
+
{
|
|
299
|
+
"name": "omit",
|
|
300
|
+
"kind": "function",
|
|
301
|
+
"description": "Creates a new object without the specified keys.",
|
|
302
|
+
"since": "2.0.0",
|
|
303
|
+
"signatures": [
|
|
304
|
+
{
|
|
305
|
+
"signature": "omit<T extends Record<string, unknown>, K extends string | number | symbol>(obj: T, keys: readonly K[]): Omit<T, K>",
|
|
306
|
+
"description": "Creates a new object without the specified keys.",
|
|
307
|
+
"params": [
|
|
308
|
+
{
|
|
309
|
+
"name": "obj",
|
|
310
|
+
"type": "T",
|
|
311
|
+
"description": "The source object"
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
"name": "keys",
|
|
315
|
+
"type": "readonly K[]",
|
|
316
|
+
"description": "The keys to omit"
|
|
317
|
+
}
|
|
318
|
+
],
|
|
319
|
+
"returns": {
|
|
320
|
+
"type": "Omit<T, K>",
|
|
321
|
+
"description": "A new object without the omitted keys"
|
|
322
|
+
},
|
|
323
|
+
"typeParameters": [
|
|
324
|
+
{
|
|
325
|
+
"name": "T",
|
|
326
|
+
"constraint": "Record<string, unknown>"
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
"name": "K",
|
|
330
|
+
"constraint": "string | number | symbol"
|
|
331
|
+
}
|
|
332
|
+
]
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
"signature": "omit(obj: undefined, keys: readonly string[]): undefined",
|
|
336
|
+
"description": "Creates a new object without the specified keys.",
|
|
337
|
+
"params": [
|
|
338
|
+
{
|
|
339
|
+
"name": "obj",
|
|
340
|
+
"type": "undefined",
|
|
341
|
+
"description": "The source object"
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
"name": "keys",
|
|
345
|
+
"type": "readonly string[]",
|
|
346
|
+
"description": "The keys to omit"
|
|
347
|
+
}
|
|
348
|
+
],
|
|
349
|
+
"returns": {
|
|
350
|
+
"type": "undefined",
|
|
351
|
+
"description": "A new object without the omitted keys"
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
"signature": "omit(obj: null, keys: readonly string[]): null",
|
|
356
|
+
"description": "Creates a new object without the specified keys.",
|
|
357
|
+
"params": [
|
|
358
|
+
{
|
|
359
|
+
"name": "obj",
|
|
360
|
+
"type": "null",
|
|
361
|
+
"description": "The source object"
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
"name": "keys",
|
|
365
|
+
"type": "readonly string[]",
|
|
366
|
+
"description": "The keys to omit"
|
|
367
|
+
}
|
|
368
|
+
],
|
|
369
|
+
"returns": {
|
|
370
|
+
"type": "null",
|
|
371
|
+
"description": "A new object without the omitted keys"
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
],
|
|
375
|
+
"examples": [
|
|
376
|
+
{
|
|
377
|
+
"title": "Omit specific keys",
|
|
378
|
+
"description": "Creates a new object without the specified keys.",
|
|
379
|
+
"code": "omit({ a: 1, b: 2, c: 3 }, ['b'])\n// => { a: 1, c: 3 }"
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
"title": "Remove sensitive fields",
|
|
383
|
+
"description": "Useful to strip sensitive data before sending to client.",
|
|
384
|
+
"code": "const user = { id: 1, name: 'Alice', password: 'secret', token: 'abc123' };\nomit(user, ['password', 'token'])\n// => { id: 1, name: 'Alice' }"
|
|
385
|
+
}
|
|
386
|
+
],
|
|
387
|
+
"sourceFile": "omit.ts"
|
|
388
|
+
},
|
|
389
|
+
{
|
|
390
|
+
"name": "pick",
|
|
391
|
+
"kind": "function",
|
|
392
|
+
"description": "Creates a new object with only the specified keys.",
|
|
393
|
+
"since": "2.0.0",
|
|
394
|
+
"signatures": [
|
|
395
|
+
{
|
|
396
|
+
"signature": "pick<T extends Record<string, unknown>, K extends string | number | symbol>(obj: T, keys: readonly K[]): Pick<T, K>",
|
|
397
|
+
"description": "Creates a new object with only the specified keys.",
|
|
398
|
+
"params": [
|
|
399
|
+
{
|
|
400
|
+
"name": "obj",
|
|
401
|
+
"type": "T",
|
|
402
|
+
"description": "The source object"
|
|
403
|
+
},
|
|
404
|
+
{
|
|
405
|
+
"name": "keys",
|
|
406
|
+
"type": "readonly K[]",
|
|
407
|
+
"description": "The keys to pick"
|
|
408
|
+
}
|
|
409
|
+
],
|
|
410
|
+
"returns": {
|
|
411
|
+
"type": "Pick<T, K>",
|
|
412
|
+
"description": "A new object with only the picked keys"
|
|
413
|
+
},
|
|
414
|
+
"typeParameters": [
|
|
415
|
+
{
|
|
416
|
+
"name": "T",
|
|
417
|
+
"constraint": "Record<string, unknown>"
|
|
418
|
+
},
|
|
419
|
+
{
|
|
420
|
+
"name": "K",
|
|
421
|
+
"constraint": "string | number | symbol"
|
|
422
|
+
}
|
|
423
|
+
]
|
|
424
|
+
},
|
|
425
|
+
{
|
|
426
|
+
"signature": "pick(obj: undefined, keys: readonly string[]): undefined",
|
|
427
|
+
"description": "Creates a new object with only the specified keys.",
|
|
428
|
+
"params": [
|
|
429
|
+
{
|
|
430
|
+
"name": "obj",
|
|
431
|
+
"type": "undefined",
|
|
432
|
+
"description": "The source object"
|
|
433
|
+
},
|
|
434
|
+
{
|
|
435
|
+
"name": "keys",
|
|
436
|
+
"type": "readonly string[]",
|
|
437
|
+
"description": "The keys to pick"
|
|
438
|
+
}
|
|
439
|
+
],
|
|
440
|
+
"returns": {
|
|
441
|
+
"type": "undefined",
|
|
442
|
+
"description": "A new object with only the picked keys"
|
|
443
|
+
}
|
|
444
|
+
},
|
|
445
|
+
{
|
|
446
|
+
"signature": "pick(obj: null, keys: readonly string[]): null",
|
|
447
|
+
"description": "Creates a new object with only the specified keys.",
|
|
448
|
+
"params": [
|
|
449
|
+
{
|
|
450
|
+
"name": "obj",
|
|
451
|
+
"type": "null",
|
|
452
|
+
"description": "The source object"
|
|
453
|
+
},
|
|
454
|
+
{
|
|
455
|
+
"name": "keys",
|
|
456
|
+
"type": "readonly string[]",
|
|
457
|
+
"description": "The keys to pick"
|
|
458
|
+
}
|
|
459
|
+
],
|
|
460
|
+
"returns": {
|
|
461
|
+
"type": "null",
|
|
462
|
+
"description": "A new object with only the picked keys"
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
],
|
|
466
|
+
"examples": [
|
|
467
|
+
{
|
|
468
|
+
"title": "Pick specific keys",
|
|
469
|
+
"description": "Creates a new object with only the specified keys.",
|
|
470
|
+
"code": "pick({ a: 1, b: 2, c: 3 }, ['a', 'c'])\n// => { a: 1, c: 3 }"
|
|
471
|
+
},
|
|
472
|
+
{
|
|
473
|
+
"title": "Extract user fields",
|
|
474
|
+
"description": "Useful to select only the fields you need from an object.",
|
|
475
|
+
"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' }"
|
|
476
|
+
}
|
|
477
|
+
],
|
|
478
|
+
"sourceFile": "pick.ts"
|
|
479
|
+
},
|
|
186
480
|
{
|
|
187
481
|
"name": "removeUndefinedNull",
|
|
188
482
|
"kind": "function",
|
|
@@ -257,12 +551,12 @@
|
|
|
257
551
|
"since": "1.9.0",
|
|
258
552
|
"signatures": [
|
|
259
553
|
{
|
|
260
|
-
"signature": "set(obj: Record<string,
|
|
554
|
+
"signature": "set(obj: Record<string, unknown>, path: string, value: unknown): Record<string, unknown>",
|
|
261
555
|
"description": "Sets a value in an object using a dot-notated path",
|
|
262
556
|
"params": [
|
|
263
557
|
{
|
|
264
558
|
"name": "obj",
|
|
265
|
-
"type": "Record<string,
|
|
559
|
+
"type": "Record<string, unknown>",
|
|
266
560
|
"description": "The object to set value in"
|
|
267
561
|
},
|
|
268
562
|
{
|
|
@@ -272,12 +566,12 @@
|
|
|
272
566
|
},
|
|
273
567
|
{
|
|
274
568
|
"name": "value",
|
|
275
|
-
"type": "
|
|
569
|
+
"type": "unknown",
|
|
276
570
|
"description": "The value to set"
|
|
277
571
|
}
|
|
278
572
|
],
|
|
279
573
|
"returns": {
|
|
280
|
-
"type": "Record<string,
|
|
574
|
+
"type": "Record<string, unknown>",
|
|
281
575
|
"description": "The modified object"
|
|
282
576
|
}
|
|
283
577
|
}
|
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": [
|
|
@@ -51,6 +66,36 @@
|
|
|
51
66
|
}
|
|
52
67
|
]
|
|
53
68
|
},
|
|
69
|
+
{
|
|
70
|
+
"name": "omit",
|
|
71
|
+
"examples": [
|
|
72
|
+
{
|
|
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' }"
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
},
|
|
54
99
|
{
|
|
55
100
|
"name": "removeUndefinedNull",
|
|
56
101
|
"examples": [
|
package/meta/licenses.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helpers4/object",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.14",
|
|
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",
|
|
@@ -21,15 +21,19 @@
|
|
|
21
21
|
"./meta/api.json": "./meta/api.json",
|
|
22
22
|
"./meta/examples.json": "./meta/examples.json",
|
|
23
23
|
"./meta/licenses.json": "./meta/licenses.json",
|
|
24
|
+
"./llms.txt": "./llms.txt",
|
|
24
25
|
"./package.json": "./package.json"
|
|
25
26
|
},
|
|
26
27
|
"keywords": [
|
|
27
28
|
"helpers",
|
|
28
29
|
"object",
|
|
30
|
+
"compact",
|
|
29
31
|
"deepClone",
|
|
30
32
|
"deepCompare",
|
|
31
33
|
"deepMerge",
|
|
32
34
|
"get",
|
|
35
|
+
"omit",
|
|
36
|
+
"pick",
|
|
33
37
|
"removeUndefinedNull",
|
|
34
38
|
"set",
|
|
35
39
|
"shallowEquals"
|
|
@@ -39,14 +43,12 @@
|
|
|
39
43
|
"lib/index.d.ts",
|
|
40
44
|
"lib/index.js.map",
|
|
41
45
|
"meta/",
|
|
46
|
+
"llms.txt",
|
|
42
47
|
"LICENSE.md",
|
|
43
48
|
"package.json",
|
|
44
49
|
"README.md"
|
|
45
50
|
],
|
|
46
51
|
"engines": {
|
|
47
52
|
"node": ">=18.0.0"
|
|
48
|
-
},
|
|
49
|
-
"peerDependencies": {
|
|
50
|
-
"radashi": "^12.7.2"
|
|
51
53
|
}
|
|
52
54
|
}
|