@bemoje/iter 1.2.1 → 1.2.3

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.
Files changed (138) hide show
  1. package/README.md +41 -15
  2. package/lib/index.cjs +5 -18
  3. package/lib/index.d.cts +524 -33
  4. package/lib/index.d.ts +524 -33
  5. package/lib/index.js +1 -14
  6. package/package.json +20 -472
  7. package/lib/filterArray.cjs +0 -20
  8. package/lib/filterArray.d.cts +0 -18
  9. package/lib/filterArray.d.ts +0 -18
  10. package/lib/filterArray.js +0 -18
  11. package/lib/filterIterable.cjs +0 -14
  12. package/lib/filterIterable.d.cts +0 -18
  13. package/lib/filterIterable.d.ts +0 -18
  14. package/lib/filterIterable.js +0 -12
  15. package/lib/filterIterableEntries.cjs +0 -12
  16. package/lib/filterIterableEntries.d.cts +0 -18
  17. package/lib/filterIterableEntries.d.ts +0 -18
  18. package/lib/filterIterableEntries.js +0 -10
  19. package/lib/filterIterableKeys.cjs +0 -14
  20. package/lib/filterIterableKeys.d.cts +0 -18
  21. package/lib/filterIterableKeys.d.ts +0 -18
  22. package/lib/filterIterableKeys.js +0 -12
  23. package/lib/filterIterableValues.cjs +0 -14
  24. package/lib/filterIterableValues.d.cts +0 -18
  25. package/lib/filterIterableValues.d.ts +0 -18
  26. package/lib/filterIterableValues.js +0 -12
  27. package/lib/filterMap.cjs +0 -18
  28. package/lib/filterMap.d.cts +0 -18
  29. package/lib/filterMap.d.ts +0 -18
  30. package/lib/filterMap.js +0 -16
  31. package/lib/filterObject.cjs +0 -24
  32. package/lib/filterObject.d.cts +0 -18
  33. package/lib/filterObject.d.ts +0 -18
  34. package/lib/filterObject.js +0 -22
  35. package/lib/filterSet.cjs +0 -18
  36. package/lib/filterSet.d.cts +0 -18
  37. package/lib/filterSet.d.ts +0 -18
  38. package/lib/filterSet.js +0 -16
  39. package/lib/forEachArray.cjs +0 -16
  40. package/lib/forEachArray.d.cts +0 -17
  41. package/lib/forEachArray.d.ts +0 -17
  42. package/lib/forEachArray.js +0 -14
  43. package/lib/forEachIterable.cjs +0 -14
  44. package/lib/forEachIterable.d.cts +0 -17
  45. package/lib/forEachIterable.d.ts +0 -17
  46. package/lib/forEachIterable.js +0 -12
  47. package/lib/forEachIterableEntries.cjs +0 -14
  48. package/lib/forEachIterableEntries.d.cts +0 -6
  49. package/lib/forEachIterableEntries.d.ts +0 -6
  50. package/lib/forEachIterableEntries.js +0 -12
  51. package/lib/forEachIterableKeys.cjs +0 -14
  52. package/lib/forEachIterableKeys.d.cts +0 -17
  53. package/lib/forEachIterableKeys.d.ts +0 -17
  54. package/lib/forEachIterableKeys.js +0 -12
  55. package/lib/forEachIterableValues.cjs +0 -14
  56. package/lib/forEachIterableValues.d.cts +0 -17
  57. package/lib/forEachIterableValues.d.ts +0 -17
  58. package/lib/forEachIterableValues.js +0 -12
  59. package/lib/forEachMap.cjs +0 -14
  60. package/lib/forEachMap.d.cts +0 -17
  61. package/lib/forEachMap.d.ts +0 -17
  62. package/lib/forEachMap.js +0 -12
  63. package/lib/forEachObject.cjs +0 -20
  64. package/lib/forEachObject.d.cts +0 -17
  65. package/lib/forEachObject.d.ts +0 -17
  66. package/lib/forEachObject.js +0 -18
  67. package/lib/forEachSet.cjs +0 -14
  68. package/lib/forEachSet.d.cts +0 -17
  69. package/lib/forEachSet.d.ts +0 -17
  70. package/lib/forEachSet.js +0 -12
  71. package/lib/mapArray.cjs +0 -18
  72. package/lib/mapArray.d.cts +0 -17
  73. package/lib/mapArray.d.ts +0 -17
  74. package/lib/mapArray.js +0 -16
  75. package/lib/mapIterable.cjs +0 -14
  76. package/lib/mapIterable.d.cts +0 -17
  77. package/lib/mapIterable.d.ts +0 -17
  78. package/lib/mapIterable.js +0 -12
  79. package/lib/mapIterableEntries.cjs +0 -12
  80. package/lib/mapIterableEntries.d.cts +0 -17
  81. package/lib/mapIterableEntries.d.ts +0 -17
  82. package/lib/mapIterableEntries.js +0 -10
  83. package/lib/mapIterableKeys.cjs +0 -17
  84. package/lib/mapIterableKeys.d.cts +0 -17
  85. package/lib/mapIterableKeys.d.ts +0 -17
  86. package/lib/mapIterableKeys.js +0 -15
  87. package/lib/mapIterableValues.cjs +0 -17
  88. package/lib/mapIterableValues.d.cts +0 -17
  89. package/lib/mapIterableValues.d.ts +0 -17
  90. package/lib/mapIterableValues.js +0 -15
  91. package/lib/mapMap.cjs +0 -16
  92. package/lib/mapMap.d.cts +0 -17
  93. package/lib/mapMap.d.ts +0 -17
  94. package/lib/mapMap.js +0 -14
  95. package/lib/mapObject.cjs +0 -22
  96. package/lib/mapObject.d.cts +0 -17
  97. package/lib/mapObject.d.ts +0 -17
  98. package/lib/mapObject.js +0 -20
  99. package/lib/mapSet.cjs +0 -16
  100. package/lib/mapSet.d.cts +0 -17
  101. package/lib/mapSet.d.ts +0 -17
  102. package/lib/mapSet.js +0 -14
  103. package/lib/reduceArray.cjs +0 -18
  104. package/lib/reduceArray.d.cts +0 -18
  105. package/lib/reduceArray.d.ts +0 -18
  106. package/lib/reduceArray.js +0 -16
  107. package/lib/reduceIterable.cjs +0 -16
  108. package/lib/reduceIterable.d.cts +0 -18
  109. package/lib/reduceIterable.d.ts +0 -18
  110. package/lib/reduceIterable.js +0 -14
  111. package/lib/reduceIterableEntries.cjs +0 -16
  112. package/lib/reduceIterableEntries.d.cts +0 -18
  113. package/lib/reduceIterableEntries.d.ts +0 -18
  114. package/lib/reduceIterableEntries.js +0 -14
  115. package/lib/reduceIterableKeys.cjs +0 -16
  116. package/lib/reduceIterableKeys.d.cts +0 -18
  117. package/lib/reduceIterableKeys.d.ts +0 -18
  118. package/lib/reduceIterableKeys.js +0 -14
  119. package/lib/reduceIterableValues.cjs +0 -16
  120. package/lib/reduceIterableValues.d.cts +0 -18
  121. package/lib/reduceIterableValues.d.ts +0 -18
  122. package/lib/reduceIterableValues.js +0 -14
  123. package/lib/reduceMap.cjs +0 -16
  124. package/lib/reduceMap.d.cts +0 -18
  125. package/lib/reduceMap.d.ts +0 -18
  126. package/lib/reduceMap.js +0 -14
  127. package/lib/reduceObject.cjs +0 -22
  128. package/lib/reduceObject.d.cts +0 -18
  129. package/lib/reduceObject.d.ts +0 -18
  130. package/lib/reduceObject.js +0 -20
  131. package/lib/reduceSet.cjs +0 -16
  132. package/lib/reduceSet.d.cts +0 -18
  133. package/lib/reduceSet.d.ts +0 -18
  134. package/lib/reduceSet.js +0 -14
  135. package/lib/toObjectIterable.cjs +0 -20
  136. package/lib/toObjectIterable.d.cts +0 -7
  137. package/lib/toObjectIterable.d.ts +0 -7
  138. package/lib/toObjectIterable.js +0 -18
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
- [![TypeScript](https://img.shields.io/badge/TypeScript-5-blue)](https://www.typescriptlang.org/)
6
- [![Module](https://img.shields.io/badge/Module-ESM-yellow)](https://nodejs.org/api/esm.html)
5
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5-blue)](https://www.typescriptlang.org/) [![Module](https://img.shields.io/badge/Module-ESM-yellow)](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/lib/index.cjs CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var iterTools = require('iter-tools');
4
+ var entriesOf = require('@mono/object/entriesOf');
4
5
 
5
6
  var __defProp = Object.defineProperty;
6
7
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
@@ -52,17 +53,9 @@ function filterMap(map5, predicate) {
52
53
  return result;
53
54
  }
54
55
  __name(filterMap, "filterMap");
55
-
56
- // ../object/src/entriesOf.ts
57
- function entriesOf(obj) {
58
- return Object.entries(obj);
59
- }
60
- __name(entriesOf, "entriesOf");
61
-
62
- // src/filterObject.ts
63
56
  function filterObject(object, predicate) {
64
57
  const result = {};
65
- for (const [key, value] of entriesOf(object)) {
58
+ for (const [key, value] of entriesOf.entriesOf(object)) {
66
59
  if (predicate(value, key)) {
67
60
  result[key] = value;
68
61
  }
@@ -124,10 +117,8 @@ function forEachMap(map5, callback) {
124
117
  }
125
118
  }
126
119
  __name(forEachMap, "forEachMap");
127
-
128
- // src/forEachObject.ts
129
120
  function forEachObject(object, callback) {
130
- for (const [key, value] of entriesOf(object)) {
121
+ for (const [key, value] of entriesOf.entriesOf(object)) {
131
122
  callback(value, key);
132
123
  }
133
124
  }
@@ -190,11 +181,9 @@ function mapMap(map5, mapper) {
190
181
  return result;
191
182
  }
192
183
  __name(mapMap, "mapMap");
193
-
194
- // src/mapObject.ts
195
184
  function mapObject(object, mapper) {
196
185
  const result = {};
197
- for (const [key, value] of entriesOf(object)) {
186
+ for (const [key, value] of entriesOf.entriesOf(object)) {
198
187
  result[key] = mapper(value, key);
199
188
  }
200
189
  return result;
@@ -272,11 +261,9 @@ function reduceMap(map5, reducer, initial) {
272
261
  return accumulator;
273
262
  }
274
263
  __name(reduceMap, "reduceMap");
275
-
276
- // src/reduceObject.ts
277
264
  function reduceObject(object, reducer, initial) {
278
265
  let accumulator = initial;
279
- for (const [key, value] of entriesOf(object)) {
266
+ for (const [key, value] of entriesOf.entriesOf(object)) {
280
267
  accumulator = reducer(accumulator, value, key);
281
268
  }
282
269
  return accumulator;