@bemoje/map 1.2.1 → 1.2.2

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 (65) hide show
  1. package/lib/index.cjs +33 -122
  2. package/lib/index.d.cts +364 -17
  3. package/lib/index.d.ts +364 -17
  4. package/lib/index.js +15 -104
  5. package/package.json +81 -141
  6. package/lib/ExtMap.cjs +0 -354
  7. package/lib/ExtMap.d.cts +0 -110
  8. package/lib/ExtMap.d.ts +0 -110
  9. package/lib/ExtMap.js +0 -352
  10. package/lib/TimeoutWeakMap.cjs +0 -122
  11. package/lib/TimeoutWeakMap.d.cts +0 -75
  12. package/lib/TimeoutWeakMap.d.ts +0 -75
  13. package/lib/TimeoutWeakMap.js +0 -120
  14. package/lib/countUniques.cjs +0 -363
  15. package/lib/countUniques.d.cts +0 -9
  16. package/lib/countUniques.d.ts +0 -9
  17. package/lib/countUniques.js +0 -361
  18. package/lib/entriesArray.cjs +0 -12
  19. package/lib/entriesArray.d.cts +0 -19
  20. package/lib/entriesArray.d.ts +0 -19
  21. package/lib/entriesArray.js +0 -10
  22. package/lib/isGenericMap.cjs +0 -18
  23. package/lib/isGenericMap.d.cts +0 -6
  24. package/lib/isGenericMap.d.ts +0 -6
  25. package/lib/isGenericMap.js +0 -16
  26. package/lib/keysArray.cjs +0 -12
  27. package/lib/keysArray.d.cts +0 -19
  28. package/lib/keysArray.d.ts +0 -19
  29. package/lib/keysArray.js +0 -10
  30. package/lib/mapGetOrDefault.cjs +0 -18
  31. package/lib/mapGetOrDefault.d.cts +0 -8
  32. package/lib/mapGetOrDefault.d.ts +0 -8
  33. package/lib/mapGetOrDefault.js +0 -16
  34. package/lib/mapLoad.cjs +0 -15
  35. package/lib/mapLoad.d.cts +0 -11
  36. package/lib/mapLoad.d.ts +0 -11
  37. package/lib/mapLoad.js +0 -13
  38. package/lib/mapReverse.cjs +0 -24
  39. package/lib/mapReverse.d.cts +0 -15
  40. package/lib/mapReverse.d.ts +0 -15
  41. package/lib/mapReverse.js +0 -22
  42. package/lib/mapUpdate.cjs +0 -14
  43. package/lib/mapUpdate.d.cts +0 -13
  44. package/lib/mapUpdate.d.ts +0 -13
  45. package/lib/mapUpdate.js +0 -12
  46. package/lib/sort.cjs +0 -17
  47. package/lib/sort.d.cts +0 -25
  48. package/lib/sort.d.ts +0 -25
  49. package/lib/sort.js +0 -15
  50. package/lib/sortByKeys.cjs +0 -19
  51. package/lib/sortByKeys.d.cts +0 -24
  52. package/lib/sortByKeys.d.ts +0 -24
  53. package/lib/sortByKeys.js +0 -17
  54. package/lib/sortByValues.cjs +0 -19
  55. package/lib/sortByValues.d.cts +0 -25
  56. package/lib/sortByValues.d.ts +0 -25
  57. package/lib/sortByValues.js +0 -17
  58. package/lib/toMap.cjs +0 -12
  59. package/lib/toMap.d.cts +0 -20
  60. package/lib/toMap.d.ts +0 -20
  61. package/lib/toMap.js +0 -10
  62. package/lib/valuesArray.cjs +0 -12
  63. package/lib/valuesArray.d.cts +0 -19
  64. package/lib/valuesArray.d.ts +0 -19
  65. package/lib/valuesArray.js +0 -10
package/lib/ExtMap.d.cts DELETED
@@ -1,110 +0,0 @@
1
- import { inspect, InspectOptions } from 'util';
2
-
3
- /**
4
- * Interface for a View that wraps a target object.
5
- * View methods are redirected to the wrapped object which acts as
6
- * a surrogate 'this'.
7
- *
8
- * To create a method that redirects to 'target', @see {@link defineProxifiedPrototypeProperty}
9
- */
10
- interface IView<T extends object> {
11
- readonly target: T;
12
- }
13
-
14
- declare const TARGET_SYMBOL: unique symbol;
15
- /**
16
- * Base class providing view functionality over a target object using the Composition pattern.
17
- */
18
- declare class View<Target extends object> implements IView<Target> {
19
- private [TARGET_SYMBOL];
20
- constructor(target: Target);
21
- get [Symbol.toStringTag](): string;
22
- get target(): Target;
23
- }
24
-
25
- declare module './ExtMap' {
26
- interface ExtMap<K = any, V = any> extends Map<K, V> {
27
- load(entries: Iterable<[K, V]>): this;
28
- sort(compare: (a: [K, V], b: [K, V]) => number): this;
29
- sortByKeys(compare: (a: K, b: K) => number): this;
30
- sortByValues(compare: (a: V, b: V) => number): this;
31
- reverse(): this;
32
- update(key: K, update: (value: V | undefined, key: K, map: this) => V): this;
33
- getOrDefault(key: K, factory: (key: K, map: this) => V): V;
34
- keysArray(): K[];
35
- valuesArray(): V[];
36
- entriesArray(): [K, V][];
37
- toMap(): Map<K, V>;
38
- toObject<K extends string, V>(): Record<K, V>;
39
- toObject<K, V>(): Record<Extract<K, PropertyKey> | string, V>;
40
- reduce<R>(reducer: (accumulator: R, value: V, key: K) => R, initialValue: R): R;
41
- map<NewK, NewV>(mapper: (value: V, key: K) => [NewK, NewV]): ExtMap<NewK, NewV>;
42
- mapKeys<NewK>(mapper: (key: K, value: V) => NewK): ExtMap<NewK, V>;
43
- mapValues<NewV>(mapper: (value: V, key: K) => NewV): ExtMap<K, NewV>;
44
- filter(predicate: (value: V, key: K) => boolean): ExtMap<K, V>;
45
- }
46
- }
47
- /**
48
- * Minimal Extended Map class focused only on Map-specific utilities.
49
- *
50
- * @template K - The type of keys in the map
51
- * @template V - The type of values in the map
52
- *
53
- * @example
54
- * ```typescript
55
- * import { map as iterMap, filter } from 'iter-tools'
56
- *
57
- * const extMap = new ExtMap<string, number>()
58
- * .load([['a', 1], ['b', 2], ['c', 3]])
59
- * .update('a', v => (v ?? 0) + 10)
60
- * .sortByValues((a, b) => a - b)
61
- *
62
- * // Use iter-tools for transformations
63
- * const doubled = new ExtMap<string, number>()
64
- * .load(iterMap(([k, v]) => [k, v * 2], extMap))
65
- *
66
- * // Use iter-tools for filtering
67
- * const filtered = new ExtMap<string, number>()
68
- * .load(filter(([k, v]) => v > 5, extMap))
69
- * ```
70
- */
71
- declare class ExtMap<K = any, V = any> extends View<Map<K, V>> implements Map<K, V> {
72
- constructor(iterable?: Iterable<readonly [K, V]> | null | undefined);
73
- constructor(obj?: Record<Extract<K, PropertyKey>, V>);
74
- /**
75
- * Creates a new ExtMap instance from a regular object.
76
- *
77
- * @param obj - An object whose key-value pairs will be used to initialize the map
78
- * @returns A new ExtMap instance containing the entries from the object
79
- */
80
- static fromObject<K extends PropertyKey, V>(obj: Record<K, V>): ExtMap<K, V>;
81
- /**
82
- * Creates a new ExtMap instance from an iterable of key-value pairs.
83
- *
84
- * @param entries - An iterable of key-value pairs to initialize the map
85
- * @returns A new ExtMap instance containing the provided entries
86
- */
87
- static fromIterable<K, V>(entries: Iterable<readonly [K, V]>): ExtMap<K, V>;
88
- /**
89
- * Creates a shallow copy of the map.
90
- *
91
- * @returns A new ExtMap instance with the same entries
92
- */
93
- clone(): ExtMap<K, V>;
94
- /**
95
- * Converts the map to a JSON-serializable format.
96
- *
97
- * @returns Array of key-value pairs suitable for JSON serialization
98
- */
99
- toJSON(): [K, V][];
100
- /**
101
- * Custom inspection method for better debugging output.
102
- *
103
- * @param _depth - The depth of inspection
104
- * @param _options - Options for inspection
105
- * @returns A string representation of the map
106
- */
107
- [inspect.custom](_depth: number, _options: InspectOptions): string;
108
- }
109
-
110
- export { ExtMap };
package/lib/ExtMap.d.ts DELETED
@@ -1,110 +0,0 @@
1
- import { inspect, InspectOptions } from 'util';
2
-
3
- /**
4
- * Interface for a View that wraps a target object.
5
- * View methods are redirected to the wrapped object which acts as
6
- * a surrogate 'this'.
7
- *
8
- * To create a method that redirects to 'target', @see {@link defineProxifiedPrototypeProperty}
9
- */
10
- interface IView<T extends object> {
11
- readonly target: T;
12
- }
13
-
14
- declare const TARGET_SYMBOL: unique symbol;
15
- /**
16
- * Base class providing view functionality over a target object using the Composition pattern.
17
- */
18
- declare class View<Target extends object> implements IView<Target> {
19
- private [TARGET_SYMBOL];
20
- constructor(target: Target);
21
- get [Symbol.toStringTag](): string;
22
- get target(): Target;
23
- }
24
-
25
- declare module './ExtMap' {
26
- interface ExtMap<K = any, V = any> extends Map<K, V> {
27
- load(entries: Iterable<[K, V]>): this;
28
- sort(compare: (a: [K, V], b: [K, V]) => number): this;
29
- sortByKeys(compare: (a: K, b: K) => number): this;
30
- sortByValues(compare: (a: V, b: V) => number): this;
31
- reverse(): this;
32
- update(key: K, update: (value: V | undefined, key: K, map: this) => V): this;
33
- getOrDefault(key: K, factory: (key: K, map: this) => V): V;
34
- keysArray(): K[];
35
- valuesArray(): V[];
36
- entriesArray(): [K, V][];
37
- toMap(): Map<K, V>;
38
- toObject<K extends string, V>(): Record<K, V>;
39
- toObject<K, V>(): Record<Extract<K, PropertyKey> | string, V>;
40
- reduce<R>(reducer: (accumulator: R, value: V, key: K) => R, initialValue: R): R;
41
- map<NewK, NewV>(mapper: (value: V, key: K) => [NewK, NewV]): ExtMap<NewK, NewV>;
42
- mapKeys<NewK>(mapper: (key: K, value: V) => NewK): ExtMap<NewK, V>;
43
- mapValues<NewV>(mapper: (value: V, key: K) => NewV): ExtMap<K, NewV>;
44
- filter(predicate: (value: V, key: K) => boolean): ExtMap<K, V>;
45
- }
46
- }
47
- /**
48
- * Minimal Extended Map class focused only on Map-specific utilities.
49
- *
50
- * @template K - The type of keys in the map
51
- * @template V - The type of values in the map
52
- *
53
- * @example
54
- * ```typescript
55
- * import { map as iterMap, filter } from 'iter-tools'
56
- *
57
- * const extMap = new ExtMap<string, number>()
58
- * .load([['a', 1], ['b', 2], ['c', 3]])
59
- * .update('a', v => (v ?? 0) + 10)
60
- * .sortByValues((a, b) => a - b)
61
- *
62
- * // Use iter-tools for transformations
63
- * const doubled = new ExtMap<string, number>()
64
- * .load(iterMap(([k, v]) => [k, v * 2], extMap))
65
- *
66
- * // Use iter-tools for filtering
67
- * const filtered = new ExtMap<string, number>()
68
- * .load(filter(([k, v]) => v > 5, extMap))
69
- * ```
70
- */
71
- declare class ExtMap<K = any, V = any> extends View<Map<K, V>> implements Map<K, V> {
72
- constructor(iterable?: Iterable<readonly [K, V]> | null | undefined);
73
- constructor(obj?: Record<Extract<K, PropertyKey>, V>);
74
- /**
75
- * Creates a new ExtMap instance from a regular object.
76
- *
77
- * @param obj - An object whose key-value pairs will be used to initialize the map
78
- * @returns A new ExtMap instance containing the entries from the object
79
- */
80
- static fromObject<K extends PropertyKey, V>(obj: Record<K, V>): ExtMap<K, V>;
81
- /**
82
- * Creates a new ExtMap instance from an iterable of key-value pairs.
83
- *
84
- * @param entries - An iterable of key-value pairs to initialize the map
85
- * @returns A new ExtMap instance containing the provided entries
86
- */
87
- static fromIterable<K, V>(entries: Iterable<readonly [K, V]>): ExtMap<K, V>;
88
- /**
89
- * Creates a shallow copy of the map.
90
- *
91
- * @returns A new ExtMap instance with the same entries
92
- */
93
- clone(): ExtMap<K, V>;
94
- /**
95
- * Converts the map to a JSON-serializable format.
96
- *
97
- * @returns Array of key-value pairs suitable for JSON serialization
98
- */
99
- toJSON(): [K, V][];
100
- /**
101
- * Custom inspection method for better debugging output.
102
- *
103
- * @param _depth - The depth of inspection
104
- * @param _options - Options for inspection
105
- * @returns A string representation of the map
106
- */
107
- [inspect.custom](_depth: number, _options: InspectOptions): string;
108
- }
109
-
110
- export { ExtMap };
package/lib/ExtMap.js DELETED
@@ -1,352 +0,0 @@
1
- import { isIterable, map, filter } from 'iter-tools';
2
- import { inspect } from 'util';
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 {
278
- static {
279
- __name(this, "ExtMap");
280
- }
281
- constructor(arg) {
282
- super(new Map(isIterable(arg) ? arg : arg ? entriesOf(arg) : void 0));
283
- }
284
- /**
285
- * Creates a new ExtMap instance from a regular object.
286
- *
287
- * @param obj - An object whose key-value pairs will be used to initialize the map
288
- * @returns A new ExtMap instance containing the entries from the object
289
- */
290
- static fromObject(obj) {
291
- return new _ExtMap(Object.entries(obj));
292
- }
293
- /**
294
- * Creates a new ExtMap instance from an iterable of key-value pairs.
295
- *
296
- * @param entries - An iterable of key-value pairs to initialize the map
297
- * @returns A new ExtMap instance containing the provided entries
298
- */
299
- static fromIterable(entries) {
300
- return new _ExtMap(entries);
301
- }
302
- /**
303
- * Creates a shallow copy of the map.
304
- *
305
- * @returns A new ExtMap instance with the same entries
306
- */
307
- clone() {
308
- return new _ExtMap(this);
309
- }
310
- /**
311
- * Converts the map to a JSON-serializable format.
312
- *
313
- * @returns Array of key-value pairs suitable for JSON serialization
314
- */
315
- toJSON() {
316
- return [
317
- ...this.entries()
318
- ];
319
- }
320
- /**
321
- * Custom inspection method for better debugging output.
322
- *
323
- * @param _depth - The depth of inspection
324
- * @param _options - Options for inspection
325
- * @returns A string representation of the map
326
- */
327
- [inspect.custom](_depth, _options) {
328
- return inspect(this.target, {
329
- breakLength: 50
330
- });
331
- }
332
- };
333
- inheritProxifiedPrototype(ExtMap, Map, []);
334
- defineMethod(ExtMap.prototype, "load", thisify(mapLoad));
335
- defineMethod(ExtMap.prototype, "sort", thisify(sort));
336
- defineMethod(ExtMap.prototype, "sortByKeys", thisify(sortByKeys));
337
- defineMethod(ExtMap.prototype, "sortByValues", thisify(sortByValues));
338
- defineMethod(ExtMap.prototype, "reverse", thisify(mapReverse));
339
- defineMethod(ExtMap.prototype, "update", thisify(mapUpdate));
340
- defineMethod(ExtMap.prototype, "getOrDefault", thisify(mapGetOrDefault));
341
- defineMethod(ExtMap.prototype, "keysArray", thisify(keysArray));
342
- defineMethod(ExtMap.prototype, "valuesArray", thisify(valuesArray));
343
- defineMethod(ExtMap.prototype, "entriesArray", thisify(entriesArray));
344
- defineMethod(ExtMap.prototype, "toObject", thisify(toObjectIterable));
345
- defineMethod(ExtMap.prototype, "toMap", thisify(toMap));
346
- defineMethod(ExtMap.prototype, "reduce", thisify(reduceIterableValues));
347
- defineMethod(ExtMap.prototype, "map", thisify(transformReturnValue(mapIterableValues, ExtMap.fromIterable)));
348
- defineMethod(ExtMap.prototype, "mapKeys", thisify(transformReturnValue(mapIterableKeys, ExtMap.fromIterable)));
349
- defineMethod(ExtMap.prototype, "mapValues", thisify(transformReturnValue(mapIterableValues, ExtMap.fromIterable)));
350
- defineMethod(ExtMap.prototype, "filter", thisify(transformReturnValue(filterIterableValues, ExtMap.fromIterable)));
351
-
352
- export { ExtMap };
@@ -1,122 +0,0 @@
1
- 'use strict';
2
-
3
- var __defProp = Object.defineProperty;
4
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
-
6
- // src/TimeoutWeakMap.ts
7
- var TimeoutWeakMap = class {
8
- static {
9
- __name(this, "TimeoutWeakMap");
10
- }
11
- timeoutMs;
12
- wmap = /* @__PURE__ */ new WeakMap();
13
- /**
14
- * @param timeoutMs Default timeout in milliseconds for entries
15
- */
16
- constructor(timeoutMs) {
17
- this.timeoutMs = timeoutMs;
18
- }
19
- /**
20
- * Retrieves the value for the given key and refreshes its timeout.
21
- *
22
- * @param key The key to retrieve
23
- * @returns The value if found, undefined otherwise
24
- */
25
- get(key) {
26
- const vt = this.wmap.get(key);
27
- if (!vt) {
28
- return void 0;
29
- }
30
- const [value, timeout] = vt;
31
- timeout.refresh();
32
- return value;
33
- }
34
- /**
35
- * Sets a key-value pair with an optional custom timeout.
36
- *
37
- * @param key The key to set
38
- * @param value The value to associate with the key
39
- * @param timeoutMs Optional timeout override for this entry
40
- * @returns This instance for chaining
41
- */
42
- set(key, value, timeoutMs) {
43
- this.wmap.set(key, [
44
- value,
45
- setTimeout(() => {
46
- this.delete(key);
47
- }, timeoutMs ?? this.timeoutMs).unref()
48
- ]);
49
- return this;
50
- }
51
- /**
52
- * Removes a key-value pair and clears its timeout.
53
- *
54
- * @param key The key to delete
55
- * @returns True if the key existed and was deleted, false otherwise
56
- */
57
- delete(key) {
58
- const vt = this.wmap.get(key);
59
- if (!vt) {
60
- return false;
61
- }
62
- const timeout = vt[1];
63
- clearTimeout(timeout);
64
- return this.wmap.delete(key);
65
- }
66
- /**
67
- * Checks if a key exists in the map.
68
- * Does not refresh the timeout.
69
- *
70
- * @param key The key to check
71
- * @returns True if the key exists, false otherwise
72
- */
73
- has(key) {
74
- return this.wmap.has(key);
75
- }
76
- /**
77
- * Loads multiple key-value pairs into the map.
78
- *
79
- * @param entries Iterable of key-value pairs to load
80
- * @param timeoutMs Optional timeout override for all entries
81
- * @returns This instance for chaining
82
- */
83
- load(entries, timeoutMs) {
84
- for (const [key, value] of entries) {
85
- this.set(key, value, timeoutMs);
86
- }
87
- return this;
88
- }
89
- /**
90
- * Updates an existing value or creates a new one using an update function.
91
- *
92
- * @param key The key to update
93
- * @param update Function that receives the current value and returns the new value
94
- * @returns This instance for chaining
95
- */
96
- update(key, update) {
97
- return this.set(key, update(this.get(key), key, this));
98
- }
99
- /**
100
- * Gets a value or creates it using a factory function if it doesn't exist.
101
- * Refreshes timeout if the value exists.
102
- *
103
- * @param key The key to get or create
104
- * @param factory Function to create the value if it doesn't exist
105
- * @param timeoutMs Optional timeout override for new entries
106
- * @returns The existing or newly created value
107
- */
108
- getOrDefault(key, factory, timeoutMs) {
109
- const vt = this.wmap.get(key);
110
- if (vt) {
111
- const [value, timeout] = vt;
112
- timeout.refresh();
113
- return value;
114
- } else {
115
- const value = factory(key, this);
116
- this.set(key, value, timeoutMs);
117
- return value;
118
- }
119
- }
120
- };
121
-
122
- exports.TimeoutWeakMap = TimeoutWeakMap;