@bemoje/iter 1.0.1 → 1.2.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.
Files changed (139) hide show
  1. package/lib/filterArray.cjs +18 -0
  2. package/lib/filterArray.d.cts +18 -0
  3. package/lib/filterArray.d.ts +18 -0
  4. package/lib/filterArray.js +16 -0
  5. package/lib/filterIterable.cjs +14 -0
  6. package/lib/filterIterable.d.cts +18 -0
  7. package/lib/filterIterable.d.ts +18 -0
  8. package/lib/filterIterable.js +11 -0
  9. package/lib/filterIterableEntries.cjs +12 -0
  10. package/lib/filterIterableEntries.d.cts +18 -0
  11. package/lib/filterIterableEntries.d.ts +18 -0
  12. package/lib/filterIterableEntries.js +9 -0
  13. package/lib/filterIterableKeys.cjs +14 -0
  14. package/lib/filterIterableKeys.d.cts +18 -0
  15. package/lib/filterIterableKeys.d.ts +18 -0
  16. package/lib/filterIterableKeys.js +11 -0
  17. package/lib/filterIterableValues.cjs +14 -0
  18. package/lib/filterIterableValues.d.cts +18 -0
  19. package/lib/filterIterableValues.d.ts +18 -0
  20. package/lib/filterIterableValues.js +11 -0
  21. package/lib/filterMap.cjs +16 -0
  22. package/lib/filterMap.d.cts +18 -0
  23. package/lib/filterMap.d.ts +18 -0
  24. package/lib/filterMap.js +14 -0
  25. package/lib/filterObject.cjs +18 -0
  26. package/lib/filterObject.d.cts +18 -0
  27. package/lib/filterObject.d.ts +18 -0
  28. package/lib/filterObject.js +15 -0
  29. package/lib/filterSet.cjs +16 -0
  30. package/lib/filterSet.d.cts +18 -0
  31. package/lib/filterSet.d.ts +18 -0
  32. package/lib/filterSet.js +14 -0
  33. package/lib/forEachArray.cjs +14 -0
  34. package/lib/forEachArray.d.cts +17 -0
  35. package/lib/forEachArray.d.ts +17 -0
  36. package/lib/forEachArray.js +12 -0
  37. package/lib/forEachIterable.cjs +14 -0
  38. package/lib/forEachIterable.d.cts +17 -0
  39. package/lib/forEachIterable.d.ts +17 -0
  40. package/lib/forEachIterable.js +11 -0
  41. package/lib/forEachIterableEntries.cjs +14 -0
  42. package/lib/forEachIterableEntries.d.cts +6 -0
  43. package/lib/forEachIterableEntries.d.ts +6 -0
  44. package/lib/forEachIterableEntries.js +11 -0
  45. package/lib/forEachIterableKeys.cjs +14 -0
  46. package/lib/forEachIterableKeys.d.cts +17 -0
  47. package/lib/forEachIterableKeys.d.ts +17 -0
  48. package/lib/forEachIterableKeys.js +11 -0
  49. package/lib/forEachIterableValues.cjs +14 -0
  50. package/lib/forEachIterableValues.d.cts +17 -0
  51. package/lib/forEachIterableValues.d.ts +17 -0
  52. package/lib/forEachIterableValues.js +11 -0
  53. package/lib/forEachMap.cjs +12 -0
  54. package/lib/forEachMap.d.cts +17 -0
  55. package/lib/forEachMap.d.ts +17 -0
  56. package/lib/forEachMap.js +10 -0
  57. package/lib/forEachObject.cjs +14 -0
  58. package/lib/forEachObject.d.cts +17 -0
  59. package/lib/forEachObject.d.ts +17 -0
  60. package/lib/forEachObject.js +11 -0
  61. package/lib/forEachSet.cjs +12 -0
  62. package/lib/forEachSet.d.cts +17 -0
  63. package/lib/forEachSet.d.ts +17 -0
  64. package/lib/forEachSet.js +10 -0
  65. package/lib/index.cjs +236 -0
  66. package/lib/index.d.cts +33 -0
  67. package/lib/index.d.ts +33 -0
  68. package/lib/index.js +33 -0
  69. package/lib/mapArray.cjs +16 -0
  70. package/lib/mapArray.d.cts +17 -0
  71. package/lib/mapArray.d.ts +17 -0
  72. package/lib/mapArray.js +14 -0
  73. package/lib/mapIterable.cjs +14 -0
  74. package/lib/mapIterable.d.cts +17 -0
  75. package/lib/mapIterable.d.ts +17 -0
  76. package/lib/mapIterable.js +11 -0
  77. package/lib/mapIterableEntries.cjs +12 -0
  78. package/lib/mapIterableEntries.d.cts +17 -0
  79. package/lib/mapIterableEntries.d.ts +17 -0
  80. package/lib/mapIterableEntries.js +9 -0
  81. package/lib/mapIterableKeys.cjs +17 -0
  82. package/lib/mapIterableKeys.d.cts +17 -0
  83. package/lib/mapIterableKeys.d.ts +17 -0
  84. package/lib/mapIterableKeys.js +14 -0
  85. package/lib/mapIterableValues.cjs +17 -0
  86. package/lib/mapIterableValues.d.cts +17 -0
  87. package/lib/mapIterableValues.d.ts +17 -0
  88. package/lib/mapIterableValues.js +14 -0
  89. package/lib/mapMap.cjs +14 -0
  90. package/lib/mapMap.d.cts +17 -0
  91. package/lib/mapMap.d.ts +17 -0
  92. package/lib/mapMap.js +12 -0
  93. package/lib/mapObject.cjs +16 -0
  94. package/lib/mapObject.d.cts +17 -0
  95. package/lib/mapObject.d.ts +17 -0
  96. package/lib/mapObject.js +13 -0
  97. package/lib/mapSet.cjs +14 -0
  98. package/lib/mapSet.d.cts +17 -0
  99. package/lib/mapSet.d.ts +17 -0
  100. package/lib/mapSet.js +12 -0
  101. package/lib/reduceArray.cjs +16 -0
  102. package/lib/reduceArray.d.cts +18 -0
  103. package/lib/reduceArray.d.ts +18 -0
  104. package/lib/reduceArray.js +14 -0
  105. package/lib/reduceIterable.cjs +14 -0
  106. package/lib/reduceIterable.d.cts +18 -0
  107. package/lib/reduceIterable.d.ts +18 -0
  108. package/lib/reduceIterable.js +12 -0
  109. package/lib/reduceIterableEntries.cjs +14 -0
  110. package/lib/reduceIterableEntries.d.cts +18 -0
  111. package/lib/reduceIterableEntries.d.ts +18 -0
  112. package/lib/reduceIterableEntries.js +12 -0
  113. package/lib/reduceIterableKeys.cjs +14 -0
  114. package/lib/reduceIterableKeys.d.cts +18 -0
  115. package/lib/reduceIterableKeys.d.ts +18 -0
  116. package/lib/reduceIterableKeys.js +12 -0
  117. package/lib/reduceIterableValues.cjs +14 -0
  118. package/lib/reduceIterableValues.d.cts +18 -0
  119. package/lib/reduceIterableValues.d.ts +18 -0
  120. package/lib/reduceIterableValues.js +12 -0
  121. package/lib/reduceMap.cjs +14 -0
  122. package/lib/reduceMap.d.cts +18 -0
  123. package/lib/reduceMap.d.ts +18 -0
  124. package/lib/reduceMap.js +12 -0
  125. package/lib/reduceObject.cjs +16 -0
  126. package/lib/reduceObject.d.cts +18 -0
  127. package/lib/reduceObject.d.ts +18 -0
  128. package/lib/reduceObject.js +13 -0
  129. package/lib/reduceSet.cjs +14 -0
  130. package/lib/reduceSet.d.cts +18 -0
  131. package/lib/reduceSet.d.ts +18 -0
  132. package/lib/reduceSet.js +12 -0
  133. package/lib/toObjectIterable.cjs +18 -0
  134. package/lib/toObjectIterable.d.cts +7 -0
  135. package/lib/toObjectIterable.d.ts +7 -0
  136. package/lib/toObjectIterable.js +16 -0
  137. package/package.json +500 -18
  138. package/index.d.ts +0 -109
  139. package/index.mjs +0 -227
package/index.mjs DELETED
@@ -1,227 +0,0 @@
1
- import { filter as filter$1, forEach, map as map$1 } from 'iter-tools';
2
-
3
- var __defProp = Object.defineProperty;
4
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
-
6
- // src/filter.ts
7
- function filter(target, predicate) {
8
- if (Symbol.iterator in target) {
9
- if (target instanceof Map) {
10
- const result3 = /* @__PURE__ */ new Map();
11
- for (const [key, value] of target) {
12
- if (predicate(value, key)) {
13
- result3.set(key, value);
14
- }
15
- }
16
- return result3;
17
- }
18
- if (target instanceof Set) {
19
- const result3 = /* @__PURE__ */ new Set();
20
- for (const value of target) {
21
- if (predicate(value)) {
22
- result3.add(value);
23
- }
24
- }
25
- return result3;
26
- }
27
- if (Array.isArray(target)) {
28
- return target.filter(predicate);
29
- }
30
- const result2 = [];
31
- for (const value of target) {
32
- if (predicate(value)) {
33
- result2.push(value);
34
- }
35
- }
36
- return result2;
37
- }
38
- const result = {};
39
- for (const [key, value] of Object.entries(target)) {
40
- if (predicate(value, key)) {
41
- result[key] = value;
42
- }
43
- }
44
- return result;
45
- }
46
- __name(filter, "filter");
47
- function filterIterable(set, predicate) {
48
- return filter$1((value) => {
49
- return predicate(value);
50
- }, set);
51
- }
52
- __name(filterIterable, "filterIterable");
53
- function filterIterableEntries(mapLike, predicate) {
54
- return filter$1(([k, v]) => {
55
- return predicate(v, k);
56
- }, mapLike);
57
- }
58
- __name(filterIterableEntries, "filterIterableEntries");
59
- function forEachIterableEntries(mapLike, callback) {
60
- return forEach(([k, v]) => {
61
- return callback(v, k);
62
- }, mapLike);
63
- }
64
- __name(forEachIterableEntries, "forEachIterableEntries");
65
-
66
- // src/forEach.ts
67
- function forEach2(target, callback) {
68
- if (Symbol.iterator in target) {
69
- if (target instanceof Map) {
70
- return target.forEach(callback);
71
- }
72
- if (target instanceof Set) {
73
- return target.forEach(callback);
74
- }
75
- if (Array.isArray(target)) {
76
- return target.forEach(callback);
77
- }
78
- for (const value of target) {
79
- callback(value);
80
- }
81
- return;
82
- }
83
- return forEachIterableEntries(Object.entries(target), callback);
84
- }
85
- __name(forEach2, "forEach");
86
- function forEachIterable(set, callback) {
87
- return forEach((value) => {
88
- return callback(value);
89
- }, set);
90
- }
91
- __name(forEachIterable, "forEachIterable");
92
-
93
- // src/map.ts
94
- function map(target, transform) {
95
- if (target instanceof Map) {
96
- const result2 = /* @__PURE__ */ new Map();
97
- for (const [key, value] of target) {
98
- result2.set(key, transform(value, key));
99
- }
100
- return result2;
101
- }
102
- if (target instanceof Set) {
103
- const result2 = /* @__PURE__ */ new Set();
104
- for (const value of target) {
105
- result2.add(transform(value));
106
- }
107
- return result2;
108
- }
109
- if (Array.isArray(target)) {
110
- return target.map(transform);
111
- }
112
- if (Symbol.iterator in target) {
113
- const result2 = [];
114
- for (const value of target) {
115
- result2.push(transform(value));
116
- }
117
- return result2;
118
- }
119
- const result = {};
120
- for (const [key, value] of Object.entries(target)) {
121
- result[key] = transform(value, key);
122
- }
123
- return result;
124
- }
125
- __name(map, "map");
126
- function mapIterable(set, transform) {
127
- return map$1((value) => {
128
- return transform(value);
129
- }, set);
130
- }
131
- __name(mapIterable, "mapIterable");
132
- function mapIterableEntries(mapLike, transform) {
133
- return map$1(([k, v]) => {
134
- return transform(v, k);
135
- }, mapLike);
136
- }
137
- __name(mapIterableEntries, "mapIterableEntries");
138
- function mapIterableKeys(mapLike, transform) {
139
- return map$1(([k, v]) => {
140
- return [
141
- transform(k, v),
142
- v
143
- ];
144
- }, mapLike);
145
- }
146
- __name(mapIterableKeys, "mapIterableKeys");
147
- function mapIterableValues(mapLike, transform) {
148
- return map$1(([k, v]) => {
149
- return [
150
- k,
151
- transform(v, k)
152
- ];
153
- }, mapLike);
154
- }
155
- __name(mapIterableValues, "mapIterableValues");
156
-
157
- // src/reduce.ts
158
- function reduce(target, reducer, initialValue) {
159
- if (Symbol.iterator in target) {
160
- if (target instanceof Map) {
161
- let acc3 = initialValue;
162
- for (const [key, value] of target.entries()) {
163
- acc3 = reducer(acc3, value, key);
164
- }
165
- return acc3;
166
- }
167
- if (target instanceof Set) {
168
- let acc3 = initialValue;
169
- for (const value of target.values()) {
170
- acc3 = reducer(acc3, value);
171
- }
172
- return acc3;
173
- }
174
- if (Array.isArray(target)) {
175
- let acc3 = initialValue;
176
- for (let i = 0; i < target.length; i++) {
177
- acc3 = reducer(acc3, target[i], i);
178
- }
179
- return acc3;
180
- }
181
- let acc2 = initialValue;
182
- for (const value of target) {
183
- acc2 = reducer(acc2, value);
184
- }
185
- return acc2;
186
- }
187
- let acc = initialValue;
188
- for (const [key, value] of Object.entries(target)) {
189
- acc = reducer(acc, value, key);
190
- }
191
- return acc;
192
- }
193
- __name(reduce, "reduce");
194
-
195
- // src/reduceIterable.ts
196
- function reduceIterable(iterable, reducer, initialValue) {
197
- for (const value of iterable) {
198
- initialValue = reducer(initialValue, value);
199
- }
200
- return initialValue;
201
- }
202
- __name(reduceIterable, "reduceIterable");
203
-
204
- // src/reduceIterableEntries.ts
205
- function reduceIterableEntries(mapLike, reducer, initialValue) {
206
- for (const [key, value] of mapLike) {
207
- initialValue = reducer(initialValue, value, key);
208
- }
209
- return initialValue;
210
- }
211
- __name(reduceIterableEntries, "reduceIterableEntries");
212
-
213
- // src/toObjectIterable.ts
214
- function toObjectIterable(mapLike) {
215
- const object = {};
216
- for (const [key, value] of mapLike) {
217
- if (typeof key !== "string" && typeof key !== "number" && typeof key !== "symbol") {
218
- object[String(key)] = value;
219
- } else {
220
- object[key] = value;
221
- }
222
- }
223
- return object;
224
- }
225
- __name(toObjectIterable, "toObjectIterable");
226
-
227
- export { filter, filterIterable, filterIterableEntries, forEach2 as forEach, forEachIterable, forEachIterableEntries, map, mapIterable, mapIterableEntries, mapIterableKeys, mapIterableValues, reduce, reduceIterable, reduceIterableEntries, toObjectIterable };