@bemoje/map 1.2.0 → 1.2.1

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/lib/ExtMap.js CHANGED
@@ -1,29 +1,280 @@
1
- import { __name } from './chunk-SHUYVCID.js';
2
- import { View, inheritProxifiedPrototype } from '@mono/composition';
3
- import { defineMethod } from '@mono/object/defineMethod';
4
- import { entriesArray } from './entriesArray';
5
- import { entriesOf } from '@mono/object/entriesOf';
6
- import { filterIterableValues } from '@mono/iter/filterIterableValues';
1
+ import { isIterable, map, filter } from 'iter-tools';
7
2
  import { inspect } from 'util';
8
- import { isIterable } from 'iter-tools';
9
- import { keysArray } from './keysArray';
10
- import { mapGetOrDefault } from './mapGetOrDefault';
11
- import { mapIterableKeys } from '@mono/iter/mapIterableKeys';
12
- import { mapIterableValues } from '@mono/iter/mapIterableValues';
13
- import { mapLoad } from './mapLoad';
14
- import { mapReverse } from './mapReverse';
15
- import { mapUpdate } from './mapUpdate';
16
- import { reduceIterableValues } from '@mono/iter/reduceIterableValues';
17
- import { sort } from './sort';
18
- import { sortByKeys } from './sortByKeys';
19
- import { sortByValues } from './sortByValues';
20
- import { thisify } from '@mono/fn/thisify';
21
- import { toMap } from './toMap';
22
- import { toObjectIterable } from '@mono/iter/toObjectIterable';
23
- import { transformReturnValue } from '@mono/fn/transformReturnValue';
24
- import { valuesArray } from './valuesArray';
25
-
26
- class ExtMap extends View {
3
+
4
+ var __defProp = Object.defineProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+
7
+ // ../object/src/defineMethod.ts
8
+ function defineMethod(obj, key, value, des = {}) {
9
+ return Object.defineProperty(obj, key, {
10
+ value,
11
+ configurable: true,
12
+ writable: true,
13
+ enumerable: false,
14
+ ...des
15
+ });
16
+ }
17
+ __name(defineMethod, "defineMethod");
18
+
19
+ // ../object/src/entriesOf.ts
20
+ function entriesOf(obj) {
21
+ return Object.entries(obj);
22
+ }
23
+ __name(entriesOf, "entriesOf");
24
+
25
+ // ../composition/src/View.ts
26
+ var TARGET_SYMBOL = /* @__PURE__ */ Symbol("target");
27
+ var View = class {
28
+ static {
29
+ __name(this, "View");
30
+ }
31
+ [TARGET_SYMBOL];
32
+ constructor(target) {
33
+ this[TARGET_SYMBOL] = target;
34
+ }
35
+ get [Symbol.toStringTag]() {
36
+ return this.constructor.name;
37
+ }
38
+ get target() {
39
+ return this[TARGET_SYMBOL];
40
+ }
41
+ };
42
+
43
+ // ../composition/src/inheritProxifiedPrototypeProperty.ts
44
+ function inheritProxifiedPrototypeProperty(ViewerClass, TargetClass, key) {
45
+ const des = Reflect.getOwnPropertyDescriptor(TargetClass.prototype, key);
46
+ if (!des) {
47
+ return;
48
+ }
49
+ if (des.value && typeof des.value === "function") {
50
+ return Object.defineProperty(ViewerClass.prototype, key, {
51
+ value(...args) {
52
+ return this.target[key](...args);
53
+ },
54
+ writable: true,
55
+ configurable: true,
56
+ enumerable: false
57
+ });
58
+ } else if (des && !des.get && !des.set) {
59
+ return Object.defineProperty(ViewerClass.prototype, key, {
60
+ get() {
61
+ return this.target[key];
62
+ },
63
+ set: des.writable ? /* @__PURE__ */ __name(function set(value) {
64
+ this.target[key] = value;
65
+ }, "set") : void 0,
66
+ configurable: true,
67
+ enumerable: false
68
+ });
69
+ } else {
70
+ Object.defineProperty(ViewerClass.prototype, key, {
71
+ get: des.get ? function() {
72
+ return this.target[key];
73
+ } : void 0,
74
+ set: des.set ? function(value) {
75
+ this.target[key] = value;
76
+ } : void 0,
77
+ configurable: true,
78
+ enumerable: false
79
+ });
80
+ }
81
+ }
82
+ __name(inheritProxifiedPrototypeProperty, "inheritProxifiedPrototypeProperty");
83
+
84
+ // ../composition/src/inheritProxifiedPrototype.ts
85
+ function inheritProxifiedPrototype(ViewerClass, TargetClass, omitKeys) {
86
+ Reflect.ownKeys(TargetClass.prototype).filter((k) => {
87
+ return k !== "constructor" && k !== Symbol.toStringTag;
88
+ }).filter((k) => {
89
+ return omitKeys ? !omitKeys.includes(k) : true;
90
+ }).forEach((k) => {
91
+ return inheritProxifiedPrototypeProperty(ViewerClass, TargetClass, k);
92
+ });
93
+ return ViewerClass;
94
+ }
95
+ __name(inheritProxifiedPrototype, "inheritProxifiedPrototype");
96
+
97
+ // src/entriesArray.ts
98
+ function entriesArray(ins) {
99
+ return Array.from(ins);
100
+ }
101
+ __name(entriesArray, "entriesArray");
102
+ function filterIterableValues(mapLike, predicate) {
103
+ return filter(([k, v]) => {
104
+ return predicate(v, k);
105
+ }, mapLike);
106
+ }
107
+ __name(filterIterableValues, "filterIterableValues");
108
+
109
+ // src/keysArray.ts
110
+ function keysArray(ins) {
111
+ return Array.from(ins.keys());
112
+ }
113
+ __name(keysArray, "keysArray");
114
+
115
+ // src/mapGetOrDefault.ts
116
+ function mapGetOrDefault(map3, key, factory) {
117
+ let value = map3.get(key);
118
+ if (value !== void 0 || map3.has(key)) {
119
+ return value;
120
+ }
121
+ value = factory(key, map3);
122
+ map3.set(key, value);
123
+ return value;
124
+ }
125
+ __name(mapGetOrDefault, "mapGetOrDefault");
126
+ function mapIterableKeys(mapLike, mapper) {
127
+ return map(([k, v]) => {
128
+ return [
129
+ mapper(k, v),
130
+ v
131
+ ];
132
+ }, mapLike);
133
+ }
134
+ __name(mapIterableKeys, "mapIterableKeys");
135
+ function mapIterableValues(mapLike, mapper) {
136
+ return map(([k, v]) => {
137
+ return [
138
+ k,
139
+ mapper(v, k)
140
+ ];
141
+ }, mapLike);
142
+ }
143
+ __name(mapIterableValues, "mapIterableValues");
144
+
145
+ // src/mapLoad.ts
146
+ function mapLoad(ins, entries) {
147
+ for (const [key, value] of entries) {
148
+ ins.set(key, value);
149
+ }
150
+ return ins;
151
+ }
152
+ __name(mapLoad, "mapLoad");
153
+
154
+ // src/mapReverse.ts
155
+ function mapReverse(ins) {
156
+ const entries = Array.from(ins).reverse();
157
+ ins.clear();
158
+ mapLoad(ins, entries);
159
+ return ins;
160
+ }
161
+ __name(mapReverse, "mapReverse");
162
+
163
+ // src/mapUpdate.ts
164
+ function mapUpdate(ins, key, update) {
165
+ const newValue = update(ins.get(key), key, ins);
166
+ ins.set(key, newValue);
167
+ return ins;
168
+ }
169
+ __name(mapUpdate, "mapUpdate");
170
+
171
+ // ../iter/src/reduceIterableValues.ts
172
+ function reduceIterableValues(mapLike, reducer, initial) {
173
+ let accumulator = initial;
174
+ for (const [k, v] of mapLike) {
175
+ accumulator = reducer(accumulator, v, k);
176
+ }
177
+ return accumulator;
178
+ }
179
+ __name(reduceIterableValues, "reduceIterableValues");
180
+
181
+ // src/sort.ts
182
+ function sort(ins, compare) {
183
+ const entries = Array.from(ins).sort(compare);
184
+ ins.clear();
185
+ for (const [k, v] of entries) {
186
+ ins.set(k, v);
187
+ }
188
+ return ins;
189
+ }
190
+ __name(sort, "sort");
191
+
192
+ // src/sortByKeys.ts
193
+ function sortByKeys(ins, compare) {
194
+ const entries = Array.from(ins).sort((a, b) => {
195
+ return compare(a[0], b[0]);
196
+ });
197
+ ins.clear();
198
+ for (const [k, v] of entries) {
199
+ ins.set(k, v);
200
+ }
201
+ return ins;
202
+ }
203
+ __name(sortByKeys, "sortByKeys");
204
+
205
+ // src/sortByValues.ts
206
+ function sortByValues(ins, compare) {
207
+ const entries = Array.from(ins).sort((a, b) => {
208
+ return compare(a[1], b[1]);
209
+ });
210
+ ins.clear();
211
+ for (const [k, v] of entries) {
212
+ ins.set(k, v);
213
+ }
214
+ return ins;
215
+ }
216
+ __name(sortByValues, "sortByValues");
217
+
218
+ // ../fn/src/setNameAndLength.ts
219
+ function setNameAndLength(source, target, lengthDelta = 0) {
220
+ return Object.defineProperties(target, {
221
+ name: {
222
+ configurable: true,
223
+ value: source.name
224
+ },
225
+ length: {
226
+ configurable: true,
227
+ value: source.length + lengthDelta
228
+ }
229
+ });
230
+ }
231
+ __name(setNameAndLength, "setNameAndLength");
232
+
233
+ // ../fn/src/thisify.ts
234
+ function thisify(fn) {
235
+ return setNameAndLength(fn, /* @__PURE__ */ __name(function f(...args) {
236
+ return fn(this, ...args);
237
+ }, "f"), -1);
238
+ }
239
+ __name(thisify, "thisify");
240
+
241
+ // src/toMap.ts
242
+ function toMap(ins) {
243
+ return new Map(ins);
244
+ }
245
+ __name(toMap, "toMap");
246
+
247
+ // ../iter/src/toObjectIterable.ts
248
+ function toObjectIterable(mapLike) {
249
+ const object = {};
250
+ for (const [key, value] of mapLike) {
251
+ if (typeof key !== "string" && typeof key !== "number" && typeof key !== "symbol") {
252
+ object[String(key)] = value;
253
+ } else {
254
+ object[key] = value;
255
+ }
256
+ }
257
+ return object;
258
+ }
259
+ __name(toObjectIterable, "toObjectIterable");
260
+
261
+ // ../fn/src/transformReturnValue.ts
262
+ function transformReturnValue(fn, transform) {
263
+ return setNameAndLength(fn, function(...args) {
264
+ const result = fn.apply(this, args);
265
+ return transform(result);
266
+ });
267
+ }
268
+ __name(transformReturnValue, "transformReturnValue");
269
+
270
+ // src/valuesArray.ts
271
+ function valuesArray(ins) {
272
+ return Array.from(ins.values());
273
+ }
274
+ __name(valuesArray, "valuesArray");
275
+
276
+ // src/ExtMap.ts
277
+ var ExtMap = class _ExtMap extends View {
27
278
  static {
28
279
  __name(this, "ExtMap");
29
280
  }
@@ -37,7 +288,7 @@ class ExtMap extends View {
37
288
  * @returns A new ExtMap instance containing the entries from the object
38
289
  */
39
290
  static fromObject(obj) {
40
- return new ExtMap(Object.entries(obj));
291
+ return new _ExtMap(Object.entries(obj));
41
292
  }
42
293
  /**
43
294
  * Creates a new ExtMap instance from an iterable of key-value pairs.
@@ -46,7 +297,7 @@ class ExtMap extends View {
46
297
  * @returns A new ExtMap instance containing the provided entries
47
298
  */
48
299
  static fromIterable(entries) {
49
- return new ExtMap(entries);
300
+ return new _ExtMap(entries);
50
301
  }
51
302
  /**
52
303
  * Creates a shallow copy of the map.
@@ -54,7 +305,7 @@ class ExtMap extends View {
54
305
  * @returns A new ExtMap instance with the same entries
55
306
  */
56
307
  clone() {
57
- return new ExtMap(this);
308
+ return new _ExtMap(this);
58
309
  }
59
310
  /**
60
311
  * Converts the map to a JSON-serializable format.
@@ -78,7 +329,7 @@ class ExtMap extends View {
78
329
  breakLength: 50
79
330
  });
80
331
  }
81
- }
332
+ };
82
333
  inheritProxifiedPrototype(ExtMap, Map, []);
83
334
  defineMethod(ExtMap.prototype, "load", thisify(mapLoad));
84
335
  defineMethod(ExtMap.prototype, "sort", thisify(sort));
@@ -2,7 +2,9 @@
2
2
 
3
3
  var __defProp = Object.defineProperty;
4
4
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
- class TimeoutWeakMap {
5
+
6
+ // src/TimeoutWeakMap.ts
7
+ var TimeoutWeakMap = class {
6
8
  static {
7
9
  __name(this, "TimeoutWeakMap");
8
10
  }
@@ -115,6 +117,6 @@ class TimeoutWeakMap {
115
117
  return value;
116
118
  }
117
119
  }
118
- }
120
+ };
119
121
 
120
122
  exports.TimeoutWeakMap = TimeoutWeakMap;
@@ -1,6 +1,8 @@
1
- import { __name } from './chunk-SHUYVCID.js';
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
2
3
 
3
- class TimeoutWeakMap {
4
+ // src/TimeoutWeakMap.ts
5
+ var TimeoutWeakMap = class {
4
6
  static {
5
7
  __name(this, "TimeoutWeakMap");
6
8
  }
@@ -113,6 +115,6 @@ class TimeoutWeakMap {
113
115
  return value;
114
116
  }
115
117
  }
116
- }
118
+ };
117
119
 
118
120
  export { TimeoutWeakMap };