@bemoje/iter 1.2.2 → 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 +41 -15
- package/package.json +13 -333
package/README.md
CHANGED
|
@@ -2,8 +2,47 @@
|
|
|
2
2
|
|
|
3
3
|
Utility functions for working with iterables, especially map-like key-value pair structures.
|
|
4
4
|
|
|
5
|
-
[](https://www.typescriptlang.org/)
|
|
6
|
-
|
|
5
|
+
[](https://www.typescriptlang.org/) [](https://nodejs.org/api/esm.html)
|
|
6
|
+
|
|
7
|
+
## Exports
|
|
8
|
+
|
|
9
|
+
<!-- EXPORTS_START -->
|
|
10
|
+
|
|
11
|
+
- **filterArray**: Filter an array based on a predicate function.
|
|
12
|
+
- **filterIterable**: Filter an iterable based on a predicate function.
|
|
13
|
+
- **filterIterableEntries**: Filter an iterable of key-value entries based on a predicate function.
|
|
14
|
+
- **filterIterableKeys**: Filter an iterable of key-value entries based on a predicate function that tests keys.
|
|
15
|
+
- **filterIterableValues**: Filter an iterable of key-value entries based on a predicate function that tests values.
|
|
16
|
+
- **filterMap**: Filter a Map based on a predicate function.
|
|
17
|
+
- **filterObject**: Filter an object's properties based on a predicate function.
|
|
18
|
+
- **filterSet**: Filter a Set based on a predicate function.
|
|
19
|
+
- **forEachArray**: Execute a callback function for each element in an array.
|
|
20
|
+
- **forEachIterable**: Execute a callback function for each element in an iterable.
|
|
21
|
+
- **forEachIterableEntries**: Execute a callback function for each entry in a map-like iterable.
|
|
22
|
+
- **forEachIterableKeys**: Execute a callback function for each key in an iterable of key-value pairs.
|
|
23
|
+
- **forEachIterableValues**: Execute a callback function for each value in an iterable of key-value pairs.
|
|
24
|
+
- **forEachMap**: Execute a callback function for each entry in a Map.
|
|
25
|
+
- **forEachObject**: Execute a callback function for each property in an object.
|
|
26
|
+
- **forEachSet**: Execute a callback function for each value in a Set.
|
|
27
|
+
- **mapArray**: Transform each element in an array using a mapper function.
|
|
28
|
+
- **mapIterable**: Transform each element in an iterable using a mapper function.
|
|
29
|
+
- **mapIterableEntries**: Transform each entry in an iterable of key-value pairs using a mapper function.
|
|
30
|
+
- **mapIterableKeys**: Transform the keys in an iterable of key-value pairs using a mapper function.
|
|
31
|
+
- **mapIterableValues**: Transform the values in an iterable of key-value pairs using a mapper function.
|
|
32
|
+
- **mapMap**: Transform the values in a Map using a mapper function.
|
|
33
|
+
- **mapObject**: Transform the values in an object using a mapper function.
|
|
34
|
+
- **mapSet**: Transform each value in a Set using a mapper function.
|
|
35
|
+
- **reduceArray**: Reduce an array to a single value using a reducer function.
|
|
36
|
+
- **reduceIterable**: Reduce an iterable to a single value using a reducer function.
|
|
37
|
+
- **reduceIterableEntries**: Reduce an iterable of key-value entries to a single value using a reducer function.
|
|
38
|
+
- **reduceIterableKeys**: Reduce an iterable of key-value entries based on keys using a reducer function.
|
|
39
|
+
- **reduceIterableValues**: Reduce an iterable of key-value entries based on values using a reducer function.
|
|
40
|
+
- **reduceMap**: Reduce a Map to a single value using a reducer function.
|
|
41
|
+
- **reduceObject**: Reduce an object to a single value using a reducer function.
|
|
42
|
+
- **reduceSet**: Reduce a Set to a single value using a reducer function.
|
|
43
|
+
- **toObjectIterable**: Convert a map-like iterable to a regular object.
|
|
44
|
+
|
|
45
|
+
<!-- EXPORTS_END -->
|
|
7
46
|
|
|
8
47
|
## Installation
|
|
9
48
|
|
|
@@ -81,16 +120,3 @@ const entries: Iterable<[string, number]> = [
|
|
|
81
120
|
const obj = toObjectIterable(entries)
|
|
82
121
|
// { a: 1, b: 2 }
|
|
83
122
|
```
|
|
84
|
-
|
|
85
|
-
## API Reference
|
|
86
|
-
|
|
87
|
-
| Export | Description |
|
|
88
|
-
| ------------------- | ------------------------------------------------------- |
|
|
89
|
-
| `mapIterable` | Transform both keys and values of map-like entries |
|
|
90
|
-
| `mapIterableKeys` | Transform keys while preserving values |
|
|
91
|
-
| `mapIterableValues` | Transform values while preserving keys |
|
|
92
|
-
| `filterIterable` | Filter map entries by predicate |
|
|
93
|
-
| `reduceIterable` | Reduce a map-like iterable to a single value |
|
|
94
|
-
| `forEachIterable` | Execute a callback for each entry |
|
|
95
|
-
| `countUniques` | Count unique values in an iterable, sorted by frequency |
|
|
96
|
-
| `toObjectIterable` | Convert key-value iterable to a plain object |
|
package/package.json
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bemoje/iter",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Utility functions for working with iterables, especially map-like key-value pair structures.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"iter-tools": "^7.5.4"
|
|
12
|
+
},
|
|
7
13
|
"keywords": [
|
|
8
14
|
"iter",
|
|
9
15
|
"iterable",
|
|
@@ -33,327 +39,7 @@
|
|
|
33
39
|
"default": "./lib/index.cjs"
|
|
34
40
|
}
|
|
35
41
|
},
|
|
36
|
-
"
|
|
37
|
-
"import": {
|
|
38
|
-
"types": "./lib/index.d.ts",
|
|
39
|
-
"default": "./lib/index.js"
|
|
40
|
-
},
|
|
41
|
-
"require": {
|
|
42
|
-
"types": "./lib/index.d.cts",
|
|
43
|
-
"default": "./lib/index.cjs"
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
"./filterIterable": {
|
|
47
|
-
"import": {
|
|
48
|
-
"types": "./lib/index.d.ts",
|
|
49
|
-
"default": "./lib/index.js"
|
|
50
|
-
},
|
|
51
|
-
"require": {
|
|
52
|
-
"types": "./lib/index.d.cts",
|
|
53
|
-
"default": "./lib/index.cjs"
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
"./filterIterableEntries": {
|
|
57
|
-
"import": {
|
|
58
|
-
"types": "./lib/index.d.ts",
|
|
59
|
-
"default": "./lib/index.js"
|
|
60
|
-
},
|
|
61
|
-
"require": {
|
|
62
|
-
"types": "./lib/index.d.cts",
|
|
63
|
-
"default": "./lib/index.cjs"
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
"./filterIterableKeys": {
|
|
67
|
-
"import": {
|
|
68
|
-
"types": "./lib/index.d.ts",
|
|
69
|
-
"default": "./lib/index.js"
|
|
70
|
-
},
|
|
71
|
-
"require": {
|
|
72
|
-
"types": "./lib/index.d.cts",
|
|
73
|
-
"default": "./lib/index.cjs"
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
"./filterIterableValues": {
|
|
77
|
-
"import": {
|
|
78
|
-
"types": "./lib/index.d.ts",
|
|
79
|
-
"default": "./lib/index.js"
|
|
80
|
-
},
|
|
81
|
-
"require": {
|
|
82
|
-
"types": "./lib/index.d.cts",
|
|
83
|
-
"default": "./lib/index.cjs"
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
"./filterMap": {
|
|
87
|
-
"import": {
|
|
88
|
-
"types": "./lib/index.d.ts",
|
|
89
|
-
"default": "./lib/index.js"
|
|
90
|
-
},
|
|
91
|
-
"require": {
|
|
92
|
-
"types": "./lib/index.d.cts",
|
|
93
|
-
"default": "./lib/index.cjs"
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
"./filterObject": {
|
|
97
|
-
"import": {
|
|
98
|
-
"types": "./lib/index.d.ts",
|
|
99
|
-
"default": "./lib/index.js"
|
|
100
|
-
},
|
|
101
|
-
"require": {
|
|
102
|
-
"types": "./lib/index.d.cts",
|
|
103
|
-
"default": "./lib/index.cjs"
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
"./filterSet": {
|
|
107
|
-
"import": {
|
|
108
|
-
"types": "./lib/index.d.ts",
|
|
109
|
-
"default": "./lib/index.js"
|
|
110
|
-
},
|
|
111
|
-
"require": {
|
|
112
|
-
"types": "./lib/index.d.cts",
|
|
113
|
-
"default": "./lib/index.cjs"
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
"./forEachArray": {
|
|
117
|
-
"import": {
|
|
118
|
-
"types": "./lib/index.d.ts",
|
|
119
|
-
"default": "./lib/index.js"
|
|
120
|
-
},
|
|
121
|
-
"require": {
|
|
122
|
-
"types": "./lib/index.d.cts",
|
|
123
|
-
"default": "./lib/index.cjs"
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
"./forEachIterable": {
|
|
127
|
-
"import": {
|
|
128
|
-
"types": "./lib/index.d.ts",
|
|
129
|
-
"default": "./lib/index.js"
|
|
130
|
-
},
|
|
131
|
-
"require": {
|
|
132
|
-
"types": "./lib/index.d.cts",
|
|
133
|
-
"default": "./lib/index.cjs"
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
"./forEachIterableEntries": {
|
|
137
|
-
"import": {
|
|
138
|
-
"types": "./lib/index.d.ts",
|
|
139
|
-
"default": "./lib/index.js"
|
|
140
|
-
},
|
|
141
|
-
"require": {
|
|
142
|
-
"types": "./lib/index.d.cts",
|
|
143
|
-
"default": "./lib/index.cjs"
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
"./forEachIterableKeys": {
|
|
147
|
-
"import": {
|
|
148
|
-
"types": "./lib/index.d.ts",
|
|
149
|
-
"default": "./lib/index.js"
|
|
150
|
-
},
|
|
151
|
-
"require": {
|
|
152
|
-
"types": "./lib/index.d.cts",
|
|
153
|
-
"default": "./lib/index.cjs"
|
|
154
|
-
}
|
|
155
|
-
},
|
|
156
|
-
"./forEachIterableValues": {
|
|
157
|
-
"import": {
|
|
158
|
-
"types": "./lib/index.d.ts",
|
|
159
|
-
"default": "./lib/index.js"
|
|
160
|
-
},
|
|
161
|
-
"require": {
|
|
162
|
-
"types": "./lib/index.d.cts",
|
|
163
|
-
"default": "./lib/index.cjs"
|
|
164
|
-
}
|
|
165
|
-
},
|
|
166
|
-
"./forEachMap": {
|
|
167
|
-
"import": {
|
|
168
|
-
"types": "./lib/index.d.ts",
|
|
169
|
-
"default": "./lib/index.js"
|
|
170
|
-
},
|
|
171
|
-
"require": {
|
|
172
|
-
"types": "./lib/index.d.cts",
|
|
173
|
-
"default": "./lib/index.cjs"
|
|
174
|
-
}
|
|
175
|
-
},
|
|
176
|
-
"./forEachObject": {
|
|
177
|
-
"import": {
|
|
178
|
-
"types": "./lib/index.d.ts",
|
|
179
|
-
"default": "./lib/index.js"
|
|
180
|
-
},
|
|
181
|
-
"require": {
|
|
182
|
-
"types": "./lib/index.d.cts",
|
|
183
|
-
"default": "./lib/index.cjs"
|
|
184
|
-
}
|
|
185
|
-
},
|
|
186
|
-
"./forEachSet": {
|
|
187
|
-
"import": {
|
|
188
|
-
"types": "./lib/index.d.ts",
|
|
189
|
-
"default": "./lib/index.js"
|
|
190
|
-
},
|
|
191
|
-
"require": {
|
|
192
|
-
"types": "./lib/index.d.cts",
|
|
193
|
-
"default": "./lib/index.cjs"
|
|
194
|
-
}
|
|
195
|
-
},
|
|
196
|
-
"./mapArray": {
|
|
197
|
-
"import": {
|
|
198
|
-
"types": "./lib/index.d.ts",
|
|
199
|
-
"default": "./lib/index.js"
|
|
200
|
-
},
|
|
201
|
-
"require": {
|
|
202
|
-
"types": "./lib/index.d.cts",
|
|
203
|
-
"default": "./lib/index.cjs"
|
|
204
|
-
}
|
|
205
|
-
},
|
|
206
|
-
"./mapIterable": {
|
|
207
|
-
"import": {
|
|
208
|
-
"types": "./lib/index.d.ts",
|
|
209
|
-
"default": "./lib/index.js"
|
|
210
|
-
},
|
|
211
|
-
"require": {
|
|
212
|
-
"types": "./lib/index.d.cts",
|
|
213
|
-
"default": "./lib/index.cjs"
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
"./mapIterableEntries": {
|
|
217
|
-
"import": {
|
|
218
|
-
"types": "./lib/index.d.ts",
|
|
219
|
-
"default": "./lib/index.js"
|
|
220
|
-
},
|
|
221
|
-
"require": {
|
|
222
|
-
"types": "./lib/index.d.cts",
|
|
223
|
-
"default": "./lib/index.cjs"
|
|
224
|
-
}
|
|
225
|
-
},
|
|
226
|
-
"./mapIterableKeys": {
|
|
227
|
-
"import": {
|
|
228
|
-
"types": "./lib/index.d.ts",
|
|
229
|
-
"default": "./lib/index.js"
|
|
230
|
-
},
|
|
231
|
-
"require": {
|
|
232
|
-
"types": "./lib/index.d.cts",
|
|
233
|
-
"default": "./lib/index.cjs"
|
|
234
|
-
}
|
|
235
|
-
},
|
|
236
|
-
"./mapIterableValues": {
|
|
237
|
-
"import": {
|
|
238
|
-
"types": "./lib/index.d.ts",
|
|
239
|
-
"default": "./lib/index.js"
|
|
240
|
-
},
|
|
241
|
-
"require": {
|
|
242
|
-
"types": "./lib/index.d.cts",
|
|
243
|
-
"default": "./lib/index.cjs"
|
|
244
|
-
}
|
|
245
|
-
},
|
|
246
|
-
"./mapMap": {
|
|
247
|
-
"import": {
|
|
248
|
-
"types": "./lib/index.d.ts",
|
|
249
|
-
"default": "./lib/index.js"
|
|
250
|
-
},
|
|
251
|
-
"require": {
|
|
252
|
-
"types": "./lib/index.d.cts",
|
|
253
|
-
"default": "./lib/index.cjs"
|
|
254
|
-
}
|
|
255
|
-
},
|
|
256
|
-
"./mapObject": {
|
|
257
|
-
"import": {
|
|
258
|
-
"types": "./lib/index.d.ts",
|
|
259
|
-
"default": "./lib/index.js"
|
|
260
|
-
},
|
|
261
|
-
"require": {
|
|
262
|
-
"types": "./lib/index.d.cts",
|
|
263
|
-
"default": "./lib/index.cjs"
|
|
264
|
-
}
|
|
265
|
-
},
|
|
266
|
-
"./mapSet": {
|
|
267
|
-
"import": {
|
|
268
|
-
"types": "./lib/index.d.ts",
|
|
269
|
-
"default": "./lib/index.js"
|
|
270
|
-
},
|
|
271
|
-
"require": {
|
|
272
|
-
"types": "./lib/index.d.cts",
|
|
273
|
-
"default": "./lib/index.cjs"
|
|
274
|
-
}
|
|
275
|
-
},
|
|
276
|
-
"./reduceArray": {
|
|
277
|
-
"import": {
|
|
278
|
-
"types": "./lib/index.d.ts",
|
|
279
|
-
"default": "./lib/index.js"
|
|
280
|
-
},
|
|
281
|
-
"require": {
|
|
282
|
-
"types": "./lib/index.d.cts",
|
|
283
|
-
"default": "./lib/index.cjs"
|
|
284
|
-
}
|
|
285
|
-
},
|
|
286
|
-
"./reduceIterable": {
|
|
287
|
-
"import": {
|
|
288
|
-
"types": "./lib/index.d.ts",
|
|
289
|
-
"default": "./lib/index.js"
|
|
290
|
-
},
|
|
291
|
-
"require": {
|
|
292
|
-
"types": "./lib/index.d.cts",
|
|
293
|
-
"default": "./lib/index.cjs"
|
|
294
|
-
}
|
|
295
|
-
},
|
|
296
|
-
"./reduceIterableEntries": {
|
|
297
|
-
"import": {
|
|
298
|
-
"types": "./lib/index.d.ts",
|
|
299
|
-
"default": "./lib/index.js"
|
|
300
|
-
},
|
|
301
|
-
"require": {
|
|
302
|
-
"types": "./lib/index.d.cts",
|
|
303
|
-
"default": "./lib/index.cjs"
|
|
304
|
-
}
|
|
305
|
-
},
|
|
306
|
-
"./reduceIterableKeys": {
|
|
307
|
-
"import": {
|
|
308
|
-
"types": "./lib/index.d.ts",
|
|
309
|
-
"default": "./lib/index.js"
|
|
310
|
-
},
|
|
311
|
-
"require": {
|
|
312
|
-
"types": "./lib/index.d.cts",
|
|
313
|
-
"default": "./lib/index.cjs"
|
|
314
|
-
}
|
|
315
|
-
},
|
|
316
|
-
"./reduceIterableValues": {
|
|
317
|
-
"import": {
|
|
318
|
-
"types": "./lib/index.d.ts",
|
|
319
|
-
"default": "./lib/index.js"
|
|
320
|
-
},
|
|
321
|
-
"require": {
|
|
322
|
-
"types": "./lib/index.d.cts",
|
|
323
|
-
"default": "./lib/index.cjs"
|
|
324
|
-
}
|
|
325
|
-
},
|
|
326
|
-
"./reduceMap": {
|
|
327
|
-
"import": {
|
|
328
|
-
"types": "./lib/index.d.ts",
|
|
329
|
-
"default": "./lib/index.js"
|
|
330
|
-
},
|
|
331
|
-
"require": {
|
|
332
|
-
"types": "./lib/index.d.cts",
|
|
333
|
-
"default": "./lib/index.cjs"
|
|
334
|
-
}
|
|
335
|
-
},
|
|
336
|
-
"./reduceObject": {
|
|
337
|
-
"import": {
|
|
338
|
-
"types": "./lib/index.d.ts",
|
|
339
|
-
"default": "./lib/index.js"
|
|
340
|
-
},
|
|
341
|
-
"require": {
|
|
342
|
-
"types": "./lib/index.d.cts",
|
|
343
|
-
"default": "./lib/index.cjs"
|
|
344
|
-
}
|
|
345
|
-
},
|
|
346
|
-
"./reduceSet": {
|
|
347
|
-
"import": {
|
|
348
|
-
"types": "./lib/index.d.ts",
|
|
349
|
-
"default": "./lib/index.js"
|
|
350
|
-
},
|
|
351
|
-
"require": {
|
|
352
|
-
"types": "./lib/index.d.cts",
|
|
353
|
-
"default": "./lib/index.cjs"
|
|
354
|
-
}
|
|
355
|
-
},
|
|
356
|
-
"./toObjectIterable": {
|
|
42
|
+
"./*": {
|
|
357
43
|
"import": {
|
|
358
44
|
"types": "./lib/index.d.ts",
|
|
359
45
|
"default": "./lib/index.js"
|
|
@@ -364,21 +50,15 @@
|
|
|
364
50
|
}
|
|
365
51
|
}
|
|
366
52
|
},
|
|
367
|
-
"
|
|
368
|
-
"
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
"access": "public"
|
|
53
|
+
"repository": {
|
|
54
|
+
"type": "git",
|
|
55
|
+
"url": "git+https://github.com/bemoje/mono.git",
|
|
56
|
+
"directory": "libs/iter"
|
|
372
57
|
},
|
|
373
|
-
"license": "MIT",
|
|
374
58
|
"author": {
|
|
375
59
|
"name": "Benjamin Møller Jensen",
|
|
376
60
|
"email": "bemoje@bemoje.net",
|
|
377
61
|
"url": "https://github.com/bemoje/"
|
|
378
62
|
},
|
|
379
|
-
"
|
|
380
|
-
"type": "git",
|
|
381
|
-
"url": "git+https://github.com/bemoje/mono.git",
|
|
382
|
-
"directory": "libs/iter"
|
|
383
|
-
}
|
|
63
|
+
"license": "MIT"
|
|
384
64
|
}
|