@helpers4/map 3.0.2-alpha.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/meta/api.json ADDED
@@ -0,0 +1,547 @@
1
+ {
2
+ "category": "map",
3
+ "version": "3.0.2",
4
+ "functions": [
5
+ {
6
+ "name": "countBy",
7
+ "kind": "function",
8
+ "description": "Groups the entries of a Map by a derived key and counts how many fall into each group.",
9
+ "since": "next",
10
+ "signatures": [
11
+ {
12
+ "signature": "countBy<K, V, R>(map: ReadonlyMap<K, V>, fn: function): Map<R, number>",
13
+ "description": "Groups the entries of a Map by a derived key and counts how many fall into each group.",
14
+ "params": [
15
+ {
16
+ "name": "map",
17
+ "type": "ReadonlyMap<K, V>",
18
+ "description": "The Map to summarize"
19
+ },
20
+ {
21
+ "name": "fn",
22
+ "type": "function",
23
+ "description": "Function deriving the grouping key from (value, key)"
24
+ }
25
+ ],
26
+ "returns": {
27
+ "type": "Map<R, number>",
28
+ "description": "A Map from derived key to the number of entries in that group"
29
+ },
30
+ "typeParameters": [
31
+ {
32
+ "name": "K"
33
+ },
34
+ {
35
+ "name": "V"
36
+ },
37
+ {
38
+ "name": "R"
39
+ }
40
+ ]
41
+ }
42
+ ],
43
+ "examples": [
44
+ {
45
+ "title": "Count entries by parity",
46
+ "description": "Groups values by a derived key and counts how many fall into each group.",
47
+ "code": "countBy(new Map([['a', 1], ['b', 2], ['c', 3], ['d', 4]]), v => v % 2 === 0 ? 'even' : 'odd')\n// => Map(2) { 'odd' => 2, 'even' => 2 }"
48
+ }
49
+ ],
50
+ "sourceFile": "countBy.ts"
51
+ },
52
+ {
53
+ "name": "every",
54
+ "kind": "function",
55
+ "description": "Checks if every entry of a Map satisfies the predicate. Short-circuits on the first mismatch.",
56
+ "since": "next",
57
+ "signatures": [
58
+ {
59
+ "signature": "every<K, V>(map: ReadonlyMap<K, V>, predicate: function): boolean",
60
+ "description": "Checks if every entry of a Map satisfies the predicate. Short-circuits on the first mismatch.",
61
+ "params": [
62
+ {
63
+ "name": "map",
64
+ "type": "ReadonlyMap<K, V>",
65
+ "description": "The Map to check"
66
+ },
67
+ {
68
+ "name": "predicate",
69
+ "type": "function",
70
+ "description": "Function invoked with (value, key)"
71
+ }
72
+ ],
73
+ "returns": {
74
+ "type": "boolean",
75
+ "description": "`true` if all entries match (vacuously `true` for an empty map), `false` otherwise"
76
+ },
77
+ "typeParameters": [
78
+ {
79
+ "name": "K"
80
+ },
81
+ {
82
+ "name": "V"
83
+ }
84
+ ]
85
+ }
86
+ ],
87
+ "examples": [
88
+ {
89
+ "title": "Check that all values are positive",
90
+ "description": "Returns false as soon as one entry fails the predicate.",
91
+ "code": "every(new Map([['a', 1], ['b', 2]]), value => value > 0)\n// => true"
92
+ },
93
+ {
94
+ "title": "Empty map",
95
+ "description": "Vacuously true for an empty map.",
96
+ "code": "every(new Map(), () => false)\n// => true"
97
+ }
98
+ ],
99
+ "sourceFile": "every.ts"
100
+ },
101
+ {
102
+ "name": "filter",
103
+ "kind": "function",
104
+ "description": "Creates a new Map containing only the entries for which the predicate returns true.",
105
+ "since": "next",
106
+ "signatures": [
107
+ {
108
+ "signature": "filter<K, V>(map: ReadonlyMap<K, V>, predicate: function): Map<K, V>",
109
+ "description": "Creates a new Map containing only the entries for which the predicate returns true.",
110
+ "params": [
111
+ {
112
+ "name": "map",
113
+ "type": "ReadonlyMap<K, V>",
114
+ "description": "The Map to filter"
115
+ },
116
+ {
117
+ "name": "predicate",
118
+ "type": "function",
119
+ "description": "Function invoked with (value, key) — return true to keep the entry"
120
+ }
121
+ ],
122
+ "returns": {
123
+ "type": "Map<K, V>",
124
+ "description": "A new Map with only the matching entries"
125
+ },
126
+ "typeParameters": [
127
+ {
128
+ "name": "K"
129
+ },
130
+ {
131
+ "name": "V"
132
+ }
133
+ ]
134
+ }
135
+ ],
136
+ "examples": [
137
+ {
138
+ "title": "Keep only even values",
139
+ "description": "Creates a new Map with only the entries whose value satisfies the predicate.",
140
+ "code": "filter(new Map([['a', 1], ['b', 2], ['c', 3]]), value => value % 2 === 0)\n// => Map(1) { 'b' => 2 }"
141
+ },
142
+ {
143
+ "title": "No matches",
144
+ "description": "Returns an empty Map when nothing matches.",
145
+ "code": "filter(new Map([['a', 1]]), () => false)\n// => Map(0) {}"
146
+ }
147
+ ],
148
+ "sourceFile": "filter.ts"
149
+ },
150
+ {
151
+ "name": "findKey",
152
+ "kind": "function",
153
+ "description": "Returns the first key of a Map whose entry satisfies the predicate, in insertion order.",
154
+ "since": "next",
155
+ "signatures": [
156
+ {
157
+ "signature": "findKey<K, V>(map: ReadonlyMap<K, V>, predicate: function): K | undefined",
158
+ "description": "Returns the first key of a Map whose entry satisfies the predicate, in insertion order.",
159
+ "params": [
160
+ {
161
+ "name": "map",
162
+ "type": "ReadonlyMap<K, V>",
163
+ "description": "The Map to search"
164
+ },
165
+ {
166
+ "name": "predicate",
167
+ "type": "function",
168
+ "description": "Function invoked with (value, key)"
169
+ }
170
+ ],
171
+ "returns": {
172
+ "type": "K | undefined",
173
+ "description": "The matching key, or `undefined` if none matches"
174
+ },
175
+ "typeParameters": [
176
+ {
177
+ "name": "K"
178
+ },
179
+ {
180
+ "name": "V"
181
+ }
182
+ ]
183
+ }
184
+ ],
185
+ "examples": [
186
+ {
187
+ "title": "Find the key of the first matching entry",
188
+ "description": "Searches in insertion order and returns the key of the first match.",
189
+ "code": "findKey(new Map([['a', 1], ['b', 2]]), value => value > 1)\n// => 'b'"
190
+ },
191
+ {
192
+ "title": "No match",
193
+ "description": "Returns undefined when nothing satisfies the predicate.",
194
+ "code": "findKey(new Map([['a', 1]]), value => value > 10)\n// => undefined"
195
+ }
196
+ ],
197
+ "sourceFile": "findKey.ts"
198
+ },
199
+ {
200
+ "name": "findValue",
201
+ "kind": "function",
202
+ "description": "Returns the first value of a Map whose entry satisfies the predicate, in insertion order.",
203
+ "since": "next",
204
+ "signatures": [
205
+ {
206
+ "signature": "findValue<K, V>(map: ReadonlyMap<K, V>, predicate: function): V | undefined",
207
+ "description": "Returns the first value of a Map whose entry satisfies the predicate, in insertion order.",
208
+ "params": [
209
+ {
210
+ "name": "map",
211
+ "type": "ReadonlyMap<K, V>",
212
+ "description": "The Map to search"
213
+ },
214
+ {
215
+ "name": "predicate",
216
+ "type": "function",
217
+ "description": "Function invoked with (value, key)"
218
+ }
219
+ ],
220
+ "returns": {
221
+ "type": "V | undefined",
222
+ "description": "The matching value, or `undefined` if none matches"
223
+ },
224
+ "typeParameters": [
225
+ {
226
+ "name": "K"
227
+ },
228
+ {
229
+ "name": "V"
230
+ }
231
+ ]
232
+ }
233
+ ],
234
+ "examples": [
235
+ {
236
+ "title": "Find the first matching value",
237
+ "description": "Searches in insertion order and returns the value of the first match.",
238
+ "code": "findValue(new Map([['a', 1], ['b', 2]]), value => value > 1)\n// => 2"
239
+ },
240
+ {
241
+ "title": "No match",
242
+ "description": "Returns undefined when nothing satisfies the predicate.",
243
+ "code": "findValue(new Map([['a', 1]]), value => value > 10)\n// => undefined"
244
+ }
245
+ ],
246
+ "sourceFile": "findValue.ts"
247
+ },
248
+ {
249
+ "name": "hasValue",
250
+ "kind": "function",
251
+ "description": "Checks whether a value exists anywhere in a Map (`Map.prototype.has` checks keys, not values).\nUses `Object.is`-style equality (via `===`, with `NaN` matching `NaN`).",
252
+ "since": "next",
253
+ "signatures": [
254
+ {
255
+ "signature": "hasValue<K, V>(map: ReadonlyMap<K, V>, value: V): boolean",
256
+ "description": "Checks whether a value exists anywhere in a Map (`Map.prototype.has` checks keys, not values).\nUses `Object.is`-style equality (via `===`, with `NaN` matching `NaN`).",
257
+ "params": [
258
+ {
259
+ "name": "map",
260
+ "type": "ReadonlyMap<K, V>",
261
+ "description": "The Map to search"
262
+ },
263
+ {
264
+ "name": "value",
265
+ "type": "V",
266
+ "description": "The value to look for"
267
+ }
268
+ ],
269
+ "returns": {
270
+ "type": "boolean",
271
+ "description": "`true` if the value is found in at least one entry"
272
+ },
273
+ "typeParameters": [
274
+ {
275
+ "name": "K"
276
+ },
277
+ {
278
+ "name": "V"
279
+ }
280
+ ]
281
+ }
282
+ ],
283
+ "examples": [
284
+ {
285
+ "title": "Check whether a value exists in a Map",
286
+ "description": "Unlike Map.prototype.has (which checks keys), this checks values.",
287
+ "code": "hasValue(new Map([['a', 1], ['b', 2]]), 2)\n// => true"
288
+ },
289
+ {
290
+ "title": "Value absent",
291
+ "description": "Returns false when no entry has that value.",
292
+ "code": "hasValue(new Map([['a', 1]]), 99)\n// => false"
293
+ }
294
+ ],
295
+ "sourceFile": "hasValue.ts"
296
+ },
297
+ {
298
+ "name": "mapKeys",
299
+ "kind": "function",
300
+ "description": "Creates a new Map with the same values but with each key transformed by a function.\nIf two entries derive the same new key, the later one (in insertion order) wins.",
301
+ "since": "next",
302
+ "signatures": [
303
+ {
304
+ "signature": "mapKeys<K, V, R>(map: ReadonlyMap<K, V>, fn: function): Map<R, V>",
305
+ "description": "Creates a new Map with the same values but with each key transformed by a function.\nIf two entries derive the same new key, the later one (in insertion order) wins.",
306
+ "params": [
307
+ {
308
+ "name": "map",
309
+ "type": "ReadonlyMap<K, V>",
310
+ "description": "The Map to transform"
311
+ },
312
+ {
313
+ "name": "fn",
314
+ "type": "function",
315
+ "description": "Function invoked with (key, value) that returns the new key"
316
+ }
317
+ ],
318
+ "returns": {
319
+ "type": "Map<R, V>",
320
+ "description": "A new Map with transformed keys"
321
+ },
322
+ "typeParameters": [
323
+ {
324
+ "name": "K"
325
+ },
326
+ {
327
+ "name": "V"
328
+ },
329
+ {
330
+ "name": "R"
331
+ }
332
+ ]
333
+ }
334
+ ],
335
+ "examples": [
336
+ {
337
+ "title": "Uppercase every key",
338
+ "description": "Creates a new Map with transformed keys and unchanged values.",
339
+ "code": "mapKeys(new Map([['a', 1], ['b', 2]]), key => key.toUpperCase())\n// => Map(2) { 'A' => 1, 'B' => 2 }"
340
+ }
341
+ ],
342
+ "sourceFile": "mapKeys.ts"
343
+ },
344
+ {
345
+ "name": "mapValues",
346
+ "kind": "function",
347
+ "description": "Creates a new Map with the same keys but with each value transformed by a function.",
348
+ "since": "next",
349
+ "signatures": [
350
+ {
351
+ "signature": "mapValues<K, V, R>(map: ReadonlyMap<K, V>, fn: function): Map<K, R>",
352
+ "description": "Creates a new Map with the same keys but with each value transformed by a function.",
353
+ "params": [
354
+ {
355
+ "name": "map",
356
+ "type": "ReadonlyMap<K, V>",
357
+ "description": "The Map to transform"
358
+ },
359
+ {
360
+ "name": "fn",
361
+ "type": "function",
362
+ "description": "Function invoked with (value, key) that returns the new value"
363
+ }
364
+ ],
365
+ "returns": {
366
+ "type": "Map<K, R>",
367
+ "description": "A new Map with transformed values"
368
+ },
369
+ "typeParameters": [
370
+ {
371
+ "name": "K"
372
+ },
373
+ {
374
+ "name": "V"
375
+ },
376
+ {
377
+ "name": "R"
378
+ }
379
+ ]
380
+ }
381
+ ],
382
+ "examples": [
383
+ {
384
+ "title": "Scale every value",
385
+ "description": "Creates a new Map with transformed values and unchanged keys.",
386
+ "code": "mapValues(new Map([['a', 1], ['b', 2]]), value => value * 10)\n// => Map(2) { 'a' => 10, 'b' => 20 }"
387
+ }
388
+ ],
389
+ "sourceFile": "mapValues.ts"
390
+ },
391
+ {
392
+ "name": "reduce",
393
+ "kind": "function",
394
+ "description": "Reduces a Map to a single value by applying a function to each entry, in insertion order.",
395
+ "since": "next",
396
+ "signatures": [
397
+ {
398
+ "signature": "reduce<K, V, R>(map: ReadonlyMap<K, V>, fn: function, initial: R): R",
399
+ "description": "Reduces a Map to a single value by applying a function to each entry, in insertion order.",
400
+ "params": [
401
+ {
402
+ "name": "map",
403
+ "type": "ReadonlyMap<K, V>",
404
+ "description": "The Map to reduce"
405
+ },
406
+ {
407
+ "name": "fn",
408
+ "type": "function",
409
+ "description": "Function invoked with (accumulator, value, key)"
410
+ },
411
+ {
412
+ "name": "initial",
413
+ "type": "R",
414
+ "description": "Initial accumulator value"
415
+ }
416
+ ],
417
+ "returns": {
418
+ "type": "R",
419
+ "description": "The final accumulator value"
420
+ },
421
+ "typeParameters": [
422
+ {
423
+ "name": "K"
424
+ },
425
+ {
426
+ "name": "V"
427
+ },
428
+ {
429
+ "name": "R"
430
+ }
431
+ ]
432
+ }
433
+ ],
434
+ "examples": [
435
+ {
436
+ "title": "Sum all values",
437
+ "description": "Reduces a Map of numbers to their total.",
438
+ "code": "reduce(new Map([['a', 1], ['b', 2], ['c', 3]]), (acc, value) => acc + value, 0)\n// => 6"
439
+ },
440
+ {
441
+ "title": "Build an array of keys",
442
+ "description": "Reduce can produce a completely different shape than the map values.",
443
+ "code": "reduce(new Map([['a', 1], ['b', 2]]), (acc: string[], _v, key) => [...acc, key], [])\n// => ['a', 'b']"
444
+ }
445
+ ],
446
+ "sourceFile": "reduce.ts"
447
+ },
448
+ {
449
+ "name": "some",
450
+ "kind": "function",
451
+ "description": "Checks if at least one entry of a Map satisfies the predicate. Short-circuits on the first match.",
452
+ "since": "next",
453
+ "signatures": [
454
+ {
455
+ "signature": "some<K, V>(map: ReadonlyMap<K, V>, predicate: function): boolean",
456
+ "description": "Checks if at least one entry of a Map satisfies the predicate. Short-circuits on the first match.",
457
+ "params": [
458
+ {
459
+ "name": "map",
460
+ "type": "ReadonlyMap<K, V>",
461
+ "description": "The Map to check"
462
+ },
463
+ {
464
+ "name": "predicate",
465
+ "type": "function",
466
+ "description": "Function invoked with (value, key)"
467
+ }
468
+ ],
469
+ "returns": {
470
+ "type": "boolean",
471
+ "description": "`true` if at least one entry matches, `false` otherwise (including for an empty map)"
472
+ },
473
+ "typeParameters": [
474
+ {
475
+ "name": "K"
476
+ },
477
+ {
478
+ "name": "V"
479
+ }
480
+ ]
481
+ }
482
+ ],
483
+ "examples": [
484
+ {
485
+ "title": "Check if any value exceeds a threshold",
486
+ "description": "Returns true as soon as one entry satisfies the predicate.",
487
+ "code": "some(new Map([['a', 1], ['b', 2]]), value => value > 1)\n// => true"
488
+ },
489
+ {
490
+ "title": "Empty map",
491
+ "description": "Always returns false for an empty map.",
492
+ "code": "some(new Map(), () => true)\n// => false"
493
+ }
494
+ ],
495
+ "sourceFile": "some.ts"
496
+ },
497
+ {
498
+ "name": "toMapByKey",
499
+ "kind": "function",
500
+ "description": "Builds a Map from an iterable of items, keyed by a derived key. When two items derive the\nsame key, the later item wins (last-write-wins, matching `Map.prototype.set` semantics).\n\nNamed `toMapByKey`, not `keyBy` (lodash's name for the same idea) — lodash's `_.keyBy`\nreturns a plain object, not a `Map`; the `to<Type>` prefix (matching `toSorted`/`toReversed`)\nmakes the actual return type unambiguous.",
501
+ "since": "next",
502
+ "signatures": [
503
+ {
504
+ "signature": "toMapByKey<T, K>(items: Iterable<T>, fn: function): Map<K, T>",
505
+ "description": "Builds a Map from an iterable of items, keyed by a derived key. When two items derive the\nsame key, the later item wins (last-write-wins, matching `Map.prototype.set` semantics).\n\nNamed `toMapByKey`, not `keyBy` (lodash's name for the same idea) — lodash's `_.keyBy`\nreturns a plain object, not a `Map`; the `to<Type>` prefix (matching `toSorted`/`toReversed`)\nmakes the actual return type unambiguous.",
506
+ "params": [
507
+ {
508
+ "name": "items",
509
+ "type": "Iterable<T>",
510
+ "description": "The items to index"
511
+ },
512
+ {
513
+ "name": "fn",
514
+ "type": "function",
515
+ "description": "Function deriving the key for each item"
516
+ }
517
+ ],
518
+ "returns": {
519
+ "type": "Map<K, T>",
520
+ "description": "A Map from derived key to item"
521
+ },
522
+ "typeParameters": [
523
+ {
524
+ "name": "T"
525
+ },
526
+ {
527
+ "name": "K"
528
+ }
529
+ ]
530
+ }
531
+ ],
532
+ "examples": [
533
+ {
534
+ "title": "Index an array of records by id",
535
+ "description": "Builds a Map keyed by a derived value, for O(1) lookup by that key.",
536
+ "code": "toMapByKey([{ id: 'a', n: 1 }, { id: 'b', n: 2 }], item => item.id)\n// => Map(2) { 'a' => {...}, 'b' => {...} }"
537
+ },
538
+ {
539
+ "title": "Last item wins on collision",
540
+ "description": "When two items derive the same key, the later one overwrites the earlier one.",
541
+ "code": "toMapByKey([{ id: 'a', n: 1 }, { id: 'a', n: 2 }], item => item.id).get('a')\n// => { id: 'a', n: 2 }"
542
+ }
543
+ ],
544
+ "sourceFile": "toMapByKey.ts"
545
+ }
546
+ ]
547
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "category": "map",
3
+ "label": "Map",
4
+ "smallDescription": "Native Map manipulation utilities",
5
+ "description": "Utilities for working with native Map instances: iteration, filtering, transforming keys/values, and building Maps from arrays"
6
+ }