@bemoje/map 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 (66) hide show
  1. package/README.md +23 -21
  2. package/lib/index.cjs +33 -122
  3. package/lib/index.d.cts +364 -17
  4. package/lib/index.d.ts +364 -17
  5. package/lib/index.js +15 -104
  6. package/package.json +21 -221
  7. package/lib/ExtMap.cjs +0 -354
  8. package/lib/ExtMap.d.cts +0 -110
  9. package/lib/ExtMap.d.ts +0 -110
  10. package/lib/ExtMap.js +0 -352
  11. package/lib/TimeoutWeakMap.cjs +0 -122
  12. package/lib/TimeoutWeakMap.d.cts +0 -75
  13. package/lib/TimeoutWeakMap.d.ts +0 -75
  14. package/lib/TimeoutWeakMap.js +0 -120
  15. package/lib/countUniques.cjs +0 -363
  16. package/lib/countUniques.d.cts +0 -9
  17. package/lib/countUniques.d.ts +0 -9
  18. package/lib/countUniques.js +0 -361
  19. package/lib/entriesArray.cjs +0 -12
  20. package/lib/entriesArray.d.cts +0 -19
  21. package/lib/entriesArray.d.ts +0 -19
  22. package/lib/entriesArray.js +0 -10
  23. package/lib/isGenericMap.cjs +0 -18
  24. package/lib/isGenericMap.d.cts +0 -6
  25. package/lib/isGenericMap.d.ts +0 -6
  26. package/lib/isGenericMap.js +0 -16
  27. package/lib/keysArray.cjs +0 -12
  28. package/lib/keysArray.d.cts +0 -19
  29. package/lib/keysArray.d.ts +0 -19
  30. package/lib/keysArray.js +0 -10
  31. package/lib/mapGetOrDefault.cjs +0 -18
  32. package/lib/mapGetOrDefault.d.cts +0 -8
  33. package/lib/mapGetOrDefault.d.ts +0 -8
  34. package/lib/mapGetOrDefault.js +0 -16
  35. package/lib/mapLoad.cjs +0 -15
  36. package/lib/mapLoad.d.cts +0 -11
  37. package/lib/mapLoad.d.ts +0 -11
  38. package/lib/mapLoad.js +0 -13
  39. package/lib/mapReverse.cjs +0 -24
  40. package/lib/mapReverse.d.cts +0 -15
  41. package/lib/mapReverse.d.ts +0 -15
  42. package/lib/mapReverse.js +0 -22
  43. package/lib/mapUpdate.cjs +0 -14
  44. package/lib/mapUpdate.d.cts +0 -13
  45. package/lib/mapUpdate.d.ts +0 -13
  46. package/lib/mapUpdate.js +0 -12
  47. package/lib/sort.cjs +0 -17
  48. package/lib/sort.d.cts +0 -25
  49. package/lib/sort.d.ts +0 -25
  50. package/lib/sort.js +0 -15
  51. package/lib/sortByKeys.cjs +0 -19
  52. package/lib/sortByKeys.d.cts +0 -24
  53. package/lib/sortByKeys.d.ts +0 -24
  54. package/lib/sortByKeys.js +0 -17
  55. package/lib/sortByValues.cjs +0 -19
  56. package/lib/sortByValues.d.cts +0 -25
  57. package/lib/sortByValues.d.ts +0 -25
  58. package/lib/sortByValues.js +0 -17
  59. package/lib/toMap.cjs +0 -12
  60. package/lib/toMap.d.cts +0 -20
  61. package/lib/toMap.d.ts +0 -20
  62. package/lib/toMap.js +0 -10
  63. package/lib/valuesArray.cjs +0 -12
  64. package/lib/valuesArray.d.cts +0 -19
  65. package/lib/valuesArray.d.ts +0 -19
  66. package/lib/valuesArray.js +0 -10
package/README.md CHANGED
@@ -2,8 +2,29 @@
2
2
 
3
3
  Extended Map class and utilities for sorting, filtering, mapping, and managing key-value data.
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
+ - **ExtMap**: Minimal Extended Map class focused only on Map-specific utilities.
12
+ - **TimeoutWeakMap**: A WeakMap with automatic timeout-based expiry for entries. Entries are automatically removed after a specified timeout period. Accessing an entry refreshes its timeout, extending its lifetime. This is useful for caching scenarios where you want automatic cleanup of unused entries while keeping frequently accessed ones alive.
13
+ - **countUniques**: Count unique occurrences of values in an iterable, returning a sorted map by count descending.
14
+ - **entriesArray**: Returns an array of all key-value pairs in the map. Convenience method that converts the entries iterator to an array.
15
+ - **isGenericMap**: Checks if the provided value implements the Map interface with the specified required properties.
16
+ - **keysArray**: Returns an array of all keys in the map. Convenience method that converts the keys iterator to an array.
17
+ - **mapGetOrDefault**: Gets a value from a map or creates it using a factory function if it doesn't exist.
18
+ - **mapLoad**: Loads multiple entries into the map from an iterable.
19
+ - **mapReverse**: Reverses the order of entries in a Map.
20
+ - **mapUpdate**: Updates a value in the map using an update function.
21
+ - **sort**: Sorts the map entries using a custom comparison function and updates the map in place. This is Map-specific because it maintains insertion order.
22
+ - **sortByKeys**: Sorts the map entries by their keys and updates the map in place.
23
+ - **sortByValues**: Sorts the map entries by their values and updates the map in place.
24
+ - **toMap**: Converts a GenericMap to a native Map.
25
+ - **valuesArray**: Returns an array of all values in the map. Convenience method that converts the values iterator to an array.
26
+
27
+ <!-- EXPORTS_END -->
7
28
 
8
29
  ## Installation
9
30
 
@@ -79,22 +100,3 @@ mapGetOrDefault(m, 'c', () => 99) // 99 (inserted into map)
79
100
  mapReverse(m) // reverses entry order in-place
80
101
  sortByValues(m, (a, b) => a - b) // sorts entries by value in-place
81
102
  ```
82
-
83
- ## API Reference
84
-
85
- | Export | Description |
86
- | ----------------- | --------------------------------------------------------- |
87
- | `ExtMap` | Extended Map with sort, filter, map, reduce, and chaining |
88
- | `TimeoutWeakMap` | WeakMap with automatic timeout-based entry expiry |
89
- | `mapGetOrDefault` | Get a value or create it with a factory function |
90
- | `mapLoad` | Load multiple entries into a map |
91
- | `mapReverse` | Reverse the order of map entries |
92
- | `mapUpdate` | Update a map value using an update function |
93
- | `sort` | Sort map entries with a custom comparator |
94
- | `sortByKeys` | Sort map entries by keys |
95
- | `sortByValues` | Sort map entries by values |
96
- | `toMap` | Convert a GenericMap to a native Map |
97
- | `keysArray` | Get all keys as an array |
98
- | `valuesArray` | Get all values as an array |
99
- | `entriesArray` | Get all entries as an array |
100
- | `isGenericMap` | Check if a value implements the Map interface |
package/lib/index.cjs CHANGED
@@ -1,30 +1,21 @@
1
1
  'use strict';
2
2
 
3
- var iterTools = require('iter-tools');
3
+ var defineMethod = require('@mono/object/defineMethod');
4
+ var entriesOf = require('@mono/object/entriesOf');
5
+ var filterIterableValues = require('@mono/iter/filterIterableValues');
4
6
  var util = require('util');
7
+ var iterTools = require('iter-tools');
8
+ var mapIterableKeys = require('@mono/iter/mapIterableKeys');
9
+ var mapIterableValues = require('@mono/iter/mapIterableValues');
10
+ var reduceIterableValues = require('@mono/iter/reduceIterableValues');
11
+ var thisify = require('@mono/fn/thisify');
12
+ var toObjectIterable = require('@mono/iter/toObjectIterable');
13
+ var transformReturnValue = require('@mono/fn/transformReturnValue');
5
14
  var mnemonist = require('mnemonist');
6
15
 
7
16
  var __defProp = Object.defineProperty;
8
17
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
18
 
10
- // ../object/src/defineMethod.ts
11
- function defineMethod(obj, key, value, des = {}) {
12
- return Object.defineProperty(obj, key, {
13
- value,
14
- configurable: true,
15
- writable: true,
16
- enumerable: false,
17
- ...des
18
- });
19
- }
20
- __name(defineMethod, "defineMethod");
21
-
22
- // ../object/src/entriesOf.ts
23
- function entriesOf(obj) {
24
- return Object.entries(obj);
25
- }
26
- __name(entriesOf, "entriesOf");
27
-
28
19
  // ../composition/src/View.ts
29
20
  var TARGET_SYMBOL = /* @__PURE__ */ Symbol("target");
30
21
  var View = class {
@@ -102,12 +93,6 @@ function entriesArray(ins) {
102
93
  return Array.from(ins);
103
94
  }
104
95
  __name(entriesArray, "entriesArray");
105
- function filterIterableValues(mapLike, predicate) {
106
- return iterTools.filter(([k, v]) => {
107
- return predicate(v, k);
108
- }, mapLike);
109
- }
110
- __name(filterIterableValues, "filterIterableValues");
111
96
 
112
97
  // src/keysArray.ts
113
98
  function keysArray(ins) {
@@ -116,34 +101,16 @@ function keysArray(ins) {
116
101
  __name(keysArray, "keysArray");
117
102
 
118
103
  // src/mapGetOrDefault.ts
119
- function mapGetOrDefault(map3, key, factory) {
120
- let value = map3.get(key);
121
- if (value !== void 0 || map3.has(key)) {
104
+ function mapGetOrDefault(map, key, factory) {
105
+ let value = map.get(key);
106
+ if (value !== void 0 || map.has(key)) {
122
107
  return value;
123
108
  }
124
- value = factory(key, map3);
125
- map3.set(key, value);
109
+ value = factory(key, map);
110
+ map.set(key, value);
126
111
  return value;
127
112
  }
128
113
  __name(mapGetOrDefault, "mapGetOrDefault");
129
- function mapIterableKeys(mapLike, mapper) {
130
- return iterTools.map(([k, v]) => {
131
- return [
132
- mapper(k, v),
133
- v
134
- ];
135
- }, mapLike);
136
- }
137
- __name(mapIterableKeys, "mapIterableKeys");
138
- function mapIterableValues(mapLike, mapper) {
139
- return iterTools.map(([k, v]) => {
140
- return [
141
- k,
142
- mapper(v, k)
143
- ];
144
- }, mapLike);
145
- }
146
- __name(mapIterableValues, "mapIterableValues");
147
114
 
148
115
  // src/mapLoad.ts
149
116
  function mapLoad(ins, entries) {
@@ -171,16 +138,6 @@ function mapUpdate(ins, key, update) {
171
138
  }
172
139
  __name(mapUpdate, "mapUpdate");
173
140
 
174
- // ../iter/src/reduceIterableValues.ts
175
- function reduceIterableValues(mapLike, reducer, initial) {
176
- let accumulator = initial;
177
- for (const [k, v] of mapLike) {
178
- accumulator = reducer(accumulator, v, k);
179
- }
180
- return accumulator;
181
- }
182
- __name(reduceIterableValues, "reduceIterableValues");
183
-
184
141
  // src/sort.ts
185
142
  function sort(ins, compare) {
186
143
  const entries = Array.from(ins).sort(compare);
@@ -218,58 +175,12 @@ function sortByValues(ins, compare) {
218
175
  }
219
176
  __name(sortByValues, "sortByValues");
220
177
 
221
- // ../fn/src/setNameAndLength.ts
222
- function setNameAndLength(source, target, lengthDelta = 0) {
223
- return Object.defineProperties(target, {
224
- name: {
225
- configurable: true,
226
- value: source.name
227
- },
228
- length: {
229
- configurable: true,
230
- value: source.length + lengthDelta
231
- }
232
- });
233
- }
234
- __name(setNameAndLength, "setNameAndLength");
235
-
236
- // ../fn/src/thisify.ts
237
- function thisify(fn) {
238
- return setNameAndLength(fn, /* @__PURE__ */ __name(function f(...args) {
239
- return fn(this, ...args);
240
- }, "f"), -1);
241
- }
242
- __name(thisify, "thisify");
243
-
244
178
  // src/toMap.ts
245
179
  function toMap(ins) {
246
180
  return new Map(ins);
247
181
  }
248
182
  __name(toMap, "toMap");
249
183
 
250
- // ../iter/src/toObjectIterable.ts
251
- function toObjectIterable(mapLike) {
252
- const object = {};
253
- for (const [key, value] of mapLike) {
254
- if (typeof key !== "string" && typeof key !== "number" && typeof key !== "symbol") {
255
- object[String(key)] = value;
256
- } else {
257
- object[key] = value;
258
- }
259
- }
260
- return object;
261
- }
262
- __name(toObjectIterable, "toObjectIterable");
263
-
264
- // ../fn/src/transformReturnValue.ts
265
- function transformReturnValue(fn, transform) {
266
- return setNameAndLength(fn, function(...args) {
267
- const result = fn.apply(this, args);
268
- return transform(result);
269
- });
270
- }
271
- __name(transformReturnValue, "transformReturnValue");
272
-
273
184
  // src/valuesArray.ts
274
185
  function valuesArray(ins) {
275
186
  return Array.from(ins.values());
@@ -282,7 +193,7 @@ var ExtMap = class _ExtMap extends View {
282
193
  __name(this, "ExtMap");
283
194
  }
284
195
  constructor(arg) {
285
- super(new Map(iterTools.isIterable(arg) ? arg : arg ? entriesOf(arg) : void 0));
196
+ super(new Map(iterTools.isIterable(arg) ? arg : arg ? entriesOf.entriesOf(arg) : void 0));
286
197
  }
287
198
  /**
288
199
  * Creates a new ExtMap instance from a regular object.
@@ -334,23 +245,23 @@ var ExtMap = class _ExtMap extends View {
334
245
  }
335
246
  };
336
247
  inheritProxifiedPrototype(ExtMap, Map, []);
337
- defineMethod(ExtMap.prototype, "load", thisify(mapLoad));
338
- defineMethod(ExtMap.prototype, "sort", thisify(sort));
339
- defineMethod(ExtMap.prototype, "sortByKeys", thisify(sortByKeys));
340
- defineMethod(ExtMap.prototype, "sortByValues", thisify(sortByValues));
341
- defineMethod(ExtMap.prototype, "reverse", thisify(mapReverse));
342
- defineMethod(ExtMap.prototype, "update", thisify(mapUpdate));
343
- defineMethod(ExtMap.prototype, "getOrDefault", thisify(mapGetOrDefault));
344
- defineMethod(ExtMap.prototype, "keysArray", thisify(keysArray));
345
- defineMethod(ExtMap.prototype, "valuesArray", thisify(valuesArray));
346
- defineMethod(ExtMap.prototype, "entriesArray", thisify(entriesArray));
347
- defineMethod(ExtMap.prototype, "toObject", thisify(toObjectIterable));
348
- defineMethod(ExtMap.prototype, "toMap", thisify(toMap));
349
- defineMethod(ExtMap.prototype, "reduce", thisify(reduceIterableValues));
350
- defineMethod(ExtMap.prototype, "map", thisify(transformReturnValue(mapIterableValues, ExtMap.fromIterable)));
351
- defineMethod(ExtMap.prototype, "mapKeys", thisify(transformReturnValue(mapIterableKeys, ExtMap.fromIterable)));
352
- defineMethod(ExtMap.prototype, "mapValues", thisify(transformReturnValue(mapIterableValues, ExtMap.fromIterable)));
353
- defineMethod(ExtMap.prototype, "filter", thisify(transformReturnValue(filterIterableValues, ExtMap.fromIterable)));
248
+ defineMethod.defineMethod(ExtMap.prototype, "load", thisify.thisify(mapLoad));
249
+ defineMethod.defineMethod(ExtMap.prototype, "sort", thisify.thisify(sort));
250
+ defineMethod.defineMethod(ExtMap.prototype, "sortByKeys", thisify.thisify(sortByKeys));
251
+ defineMethod.defineMethod(ExtMap.prototype, "sortByValues", thisify.thisify(sortByValues));
252
+ defineMethod.defineMethod(ExtMap.prototype, "reverse", thisify.thisify(mapReverse));
253
+ defineMethod.defineMethod(ExtMap.prototype, "update", thisify.thisify(mapUpdate));
254
+ defineMethod.defineMethod(ExtMap.prototype, "getOrDefault", thisify.thisify(mapGetOrDefault));
255
+ defineMethod.defineMethod(ExtMap.prototype, "keysArray", thisify.thisify(keysArray));
256
+ defineMethod.defineMethod(ExtMap.prototype, "valuesArray", thisify.thisify(valuesArray));
257
+ defineMethod.defineMethod(ExtMap.prototype, "entriesArray", thisify.thisify(entriesArray));
258
+ defineMethod.defineMethod(ExtMap.prototype, "toObject", thisify.thisify(toObjectIterable.toObjectIterable));
259
+ defineMethod.defineMethod(ExtMap.prototype, "toMap", thisify.thisify(toMap));
260
+ defineMethod.defineMethod(ExtMap.prototype, "reduce", thisify.thisify(reduceIterableValues.reduceIterableValues));
261
+ defineMethod.defineMethod(ExtMap.prototype, "map", thisify.thisify(transformReturnValue.transformReturnValue(mapIterableValues.mapIterableValues, ExtMap.fromIterable)));
262
+ defineMethod.defineMethod(ExtMap.prototype, "mapKeys", thisify.thisify(transformReturnValue.transformReturnValue(mapIterableKeys.mapIterableKeys, ExtMap.fromIterable)));
263
+ defineMethod.defineMethod(ExtMap.prototype, "mapValues", thisify.thisify(transformReturnValue.transformReturnValue(mapIterableValues.mapIterableValues, ExtMap.fromIterable)));
264
+ defineMethod.defineMethod(ExtMap.prototype, "filter", thisify.thisify(transformReturnValue.transformReturnValue(filterIterableValues.filterIterableValues, ExtMap.fromIterable)));
354
265
 
355
266
  // src/TimeoutWeakMap.ts
356
267
  var TimeoutWeakMap = class {
package/lib/index.d.cts CHANGED
@@ -1,17 +1,364 @@
1
- export { ExtMap } from './ExtMap.cjs';
2
- export { TimeoutWeakMap } from './TimeoutWeakMap.cjs';
3
- export { countUniques } from './countUniques.cjs';
4
- export { entriesArray } from './entriesArray.cjs';
5
- export { isGenericMap } from './isGenericMap.cjs';
6
- export { keysArray } from './keysArray.cjs';
7
- export { mapGetOrDefault } from './mapGetOrDefault.cjs';
8
- export { mapLoad } from './mapLoad.cjs';
9
- export { mapReverse } from './mapReverse.cjs';
10
- export { mapUpdate } from './mapUpdate.cjs';
11
- export { sort } from './sort.cjs';
12
- export { sortByKeys } from './sortByKeys.cjs';
13
- export { sortByValues } from './sortByValues.cjs';
14
- export { toMap } from './toMap.cjs';
15
- export { valuesArray } from './valuesArray.cjs';
16
- import 'util';
17
- import './GenericMap-B4OM3vGu.cjs';
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
+ type MapKeys = keyof Map<any, any>;
26
+ type GenericMap<K, V, P extends MapKeys> = {
27
+ [Method in P]: Method extends 'set' ? (key: K, value: V) => any : Method extends 'get' ? (key: K) => V | undefined : Method extends 'has' ? (key: K) => boolean : Method extends 'delete' ? (key: K) => boolean : Method extends 'clear' ? () => void : Method extends 'forEach' ? (callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any) => void : Method extends 'entries' ? () => IterableIterator<[K, V]> : Method extends 'keys' ? () => IterableIterator<K> : Method extends 'values' ? () => IterableIterator<V> : Method extends typeof Symbol.iterator ? () => IterableIterator<[K, V]> : Method extends 'size' ? number : Method extends typeof Symbol.toStringTag ? string : any;
28
+ };
29
+
30
+ declare module './ExtMap' {
31
+ interface ExtMap<K = any, V = any> extends Map<K, V> {
32
+ load(entries: Iterable<[K, V]>): this;
33
+ sort(compare: (a: [K, V], b: [K, V]) => number): this;
34
+ sortByKeys(compare: (a: K, b: K) => number): this;
35
+ sortByValues(compare: (a: V, b: V) => number): this;
36
+ reverse(): this;
37
+ update(key: K, update: (value: V | undefined, key: K, map: this) => V): this;
38
+ getOrDefault(key: K, factory: (key: K, map: this) => V): V;
39
+ keysArray(): K[];
40
+ valuesArray(): V[];
41
+ entriesArray(): [K, V][];
42
+ toMap(): Map<K, V>;
43
+ toObject<K extends string, V>(): Record<K, V>;
44
+ toObject<K, V>(): Record<Extract<K, PropertyKey> | string, V>;
45
+ reduce<R>(reducer: (accumulator: R, value: V, key: K) => R, initialValue: R): R;
46
+ map<NewK, NewV>(mapper: (value: V, key: K) => [NewK, NewV]): ExtMap<NewK, NewV>;
47
+ mapKeys<NewK>(mapper: (key: K, value: V) => NewK): ExtMap<NewK, V>;
48
+ mapValues<NewV>(mapper: (value: V, key: K) => NewV): ExtMap<K, NewV>;
49
+ filter(predicate: (value: V, key: K) => boolean): ExtMap<K, V>;
50
+ }
51
+ }
52
+ /**
53
+ * Minimal Extended Map class focused only on Map-specific utilities.
54
+ *
55
+ * @template K - The type of keys in the map
56
+ * @template V - The type of values in the map
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * import { map as iterMap, filter } from 'iter-tools'
61
+ *
62
+ * const extMap = new ExtMap<string, number>()
63
+ * .load([['a', 1], ['b', 2], ['c', 3]])
64
+ * .update('a', v => (v ?? 0) + 10)
65
+ * .sortByValues((a, b) => a - b)
66
+ *
67
+ * // Use iter-tools for transformations
68
+ * const doubled = new ExtMap<string, number>()
69
+ * .load(iterMap(([k, v]) => [k, v * 2], extMap))
70
+ *
71
+ * // Use iter-tools for filtering
72
+ * const filtered = new ExtMap<string, number>()
73
+ * .load(filter(([k, v]) => v > 5, extMap))
74
+ * ```
75
+ */
76
+ declare class ExtMap<K = any, V = any> extends View<Map<K, V>> implements Map<K, V> {
77
+ constructor(iterable?: Iterable<readonly [K, V]> | null | undefined);
78
+ constructor(obj?: Record<Extract<K, PropertyKey>, V>);
79
+ /**
80
+ * Creates a new ExtMap instance from a regular object.
81
+ *
82
+ * @param obj - An object whose key-value pairs will be used to initialize the map
83
+ * @returns A new ExtMap instance containing the entries from the object
84
+ */
85
+ static fromObject<K extends PropertyKey, V>(obj: Record<K, V>): ExtMap<K, V>;
86
+ /**
87
+ * Creates a new ExtMap instance from an iterable of key-value pairs.
88
+ *
89
+ * @param entries - An iterable of key-value pairs to initialize the map
90
+ * @returns A new ExtMap instance containing the provided entries
91
+ */
92
+ static fromIterable<K, V>(entries: Iterable<readonly [K, V]>): ExtMap<K, V>;
93
+ /**
94
+ * Creates a shallow copy of the map.
95
+ *
96
+ * @returns A new ExtMap instance with the same entries
97
+ */
98
+ clone(): ExtMap<K, V>;
99
+ /**
100
+ * Converts the map to a JSON-serializable format.
101
+ *
102
+ * @returns Array of key-value pairs suitable for JSON serialization
103
+ */
104
+ toJSON(): [K, V][];
105
+ /**
106
+ * Custom inspection method for better debugging output.
107
+ *
108
+ * @param _depth - The depth of inspection
109
+ * @param _options - Options for inspection
110
+ * @returns A string representation of the map
111
+ */
112
+ [inspect.custom](_depth: number, _options: InspectOptions): string;
113
+ }
114
+
115
+ /**
116
+ * A WeakMap with automatic timeout-based expiry for entries.
117
+ *
118
+ * Entries are automatically removed after a specified timeout period.
119
+ * Accessing an entry refreshes its timeout, extending its lifetime.
120
+ * This is useful for caching scenarios where you want automatic cleanup
121
+ * of unused entries while keeping frequently accessed ones alive.
122
+ */
123
+ declare class TimeoutWeakMap<K extends object, V> {
124
+ readonly timeoutMs: number;
125
+ protected readonly wmap: WeakMap<K, [V, NodeJS.Timeout]>;
126
+ /**
127
+ * @param timeoutMs Default timeout in milliseconds for entries
128
+ */
129
+ constructor(timeoutMs: number);
130
+ /**
131
+ * Retrieves the value for the given key and refreshes its timeout.
132
+ *
133
+ * @param key The key to retrieve
134
+ * @returns The value if found, undefined otherwise
135
+ */
136
+ get(key: K): V | undefined;
137
+ /**
138
+ * Sets a key-value pair with an optional custom timeout.
139
+ *
140
+ * @param key The key to set
141
+ * @param value The value to associate with the key
142
+ * @param timeoutMs Optional timeout override for this entry
143
+ * @returns This instance for chaining
144
+ */
145
+ set(key: K, value: V, timeoutMs?: number): this;
146
+ /**
147
+ * Removes a key-value pair and clears its timeout.
148
+ *
149
+ * @param key The key to delete
150
+ * @returns True if the key existed and was deleted, false otherwise
151
+ */
152
+ delete(key: K): boolean;
153
+ /**
154
+ * Checks if a key exists in the map.
155
+ * Does not refresh the timeout.
156
+ *
157
+ * @param key The key to check
158
+ * @returns True if the key exists, false otherwise
159
+ */
160
+ has(key: K): boolean;
161
+ /**
162
+ * Loads multiple key-value pairs into the map.
163
+ *
164
+ * @param entries Iterable of key-value pairs to load
165
+ * @param timeoutMs Optional timeout override for all entries
166
+ * @returns This instance for chaining
167
+ */
168
+ load(entries: Iterable<[K, V]>, timeoutMs?: number): this;
169
+ /**
170
+ * Updates an existing value or creates a new one using an update function.
171
+ *
172
+ * @param key The key to update
173
+ * @param update Function that receives the current value and returns the new value
174
+ * @returns This instance for chaining
175
+ */
176
+ update(key: K, update: (value: V | undefined, key: K, map: this) => V): this;
177
+ /**
178
+ * Gets a value or creates it using a factory function if it doesn't exist.
179
+ * Refreshes timeout if the value exists.
180
+ *
181
+ * @param key The key to get or create
182
+ * @param factory Function to create the value if it doesn't exist
183
+ * @param timeoutMs Optional timeout override for new entries
184
+ * @returns The existing or newly created value
185
+ */
186
+ getOrDefault(key: K, factory: (key: K, map: this) => V, timeoutMs?: number): V;
187
+ }
188
+
189
+ /**
190
+ * Count unique occurrences of values in an iterable, returning a sorted map by count descending.
191
+ */
192
+ declare function countUniques<V>(input: Iterable<V>): ExtMap<V, number>;
193
+
194
+ /**
195
+ * Returns an array of all key-value pairs in the map.
196
+ * Convenience method that converts the entries iterator to an array.
197
+ *
198
+ * @returns Array of all key-value pairs
199
+ *
200
+ * @example
201
+ * ```typescript
202
+ * const map = new ExtMap<string, number>()
203
+ * .load([['a', 1], ['b', 2], ['c', 3]])
204
+ *
205
+ * console.log(entriesArray(map)) // [['a', 1], ['b', 2], ['c', 3]]
206
+ * ```
207
+ */
208
+ declare function entriesArray<K, V>(ins: GenericMap<K, V, typeof Symbol.iterator>): [K, V][];
209
+
210
+ /**
211
+ * Checks if the provided value implements the Map interface with the specified required properties.
212
+ */
213
+ declare function isGenericMap<Props extends (keyof Map<K, V>)[], K, V>(target: unknown, requiredProps?: Props): target is Pick<Map<K, V>, Props[number]>;
214
+
215
+ /**
216
+ * Returns an array of all keys in the map.
217
+ * Convenience method that converts the keys iterator to an array.
218
+ *
219
+ * @returns Array of all keys
220
+ *
221
+ * @example
222
+ * ```typescript
223
+ * const map = new ExtMap<string, number>()
224
+ * .load([['a', 1], ['b', 2], ['c', 3]])
225
+ *
226
+ * console.log(keysArray(map)) // ['a', 'b', 'c']
227
+ * ```
228
+ */
229
+ declare function keysArray<K, V>(ins: GenericMap<K, V, 'keys'>): K[];
230
+
231
+ /**
232
+ * Gets a value from a map or creates it using a factory function if it doesn't exist.
233
+ */
234
+ declare function mapGetOrDefault<K, V, T extends GenericMap<K, V, 'get' | 'has' | 'set'>>(map: T, key: K, factory: (key: K, map: T) => V): V;
235
+
236
+ /**
237
+ * Loads multiple entries into the map from an iterable.
238
+ *
239
+ * @param entries - An iterable of key-value pairs to load into the map
240
+ * @returns The map instance for method chaining
241
+ */
242
+ declare function mapLoad<T extends GenericMap<K, V, 'set'>, K, V>(ins: T, entries: Iterable<[K, V]>): T;
243
+
244
+ /**
245
+ * Reverses the order of entries in a Map.
246
+ * @remarks This function creates a new Map with the entries of the original Map in reverse order.
247
+ * The original Map is not modified.
248
+ * @example ```ts
249
+ * mapReverse(new Map([['a', 1], ['b', 2], ['c', 3]]));
250
+ * //=> [['c', 3], ['b', 2], ['a', 1]]
251
+ * ```
252
+ */
253
+ declare function mapReverse<T extends GenericMap<K, V, 'set' | 'clear' | typeof Symbol.iterator>, K, V>(ins: T): T;
254
+ declare function mapReverse<K, V>(ins: Map<K, V>): Map<K, V>;
255
+
256
+ /**
257
+ * Updates a value in the map using an update function.
258
+ *
259
+ * @param key - The key to update
260
+ * @param update - Function that receives the current value and returns the new value
261
+ * @returns The map instance for method chaining
262
+ */
263
+ declare function mapUpdate<T extends GenericMap<K, V, 'set' | 'get'>, K, V>(ins: T, key: K, update: (value: V | undefined, key: K, map: T) => V): T;
264
+ declare function mapUpdate<K, V>(ins: Map<K, V>, key: K, update: (value: V | undefined, key: K, map: Map<K, V>) => V): typeof ins;
265
+
266
+ /**
267
+ * Sorts the map entries using a custom comparison function and updates the map in place.
268
+ * This is Map-specific because it maintains insertion order.
269
+ *
270
+ * @param ins - The map instance to sort
271
+ * @param compare - Function that compares two entries
272
+ * @returns The map instance for method chaining
273
+ *
274
+ * @example
275
+ * ```typescript
276
+ * const map = new ExtMap<string, number>([
277
+ * ['c', 3],
278
+ * ['a', 1],
279
+ * ['b', 2],
280
+ * ])
281
+ *
282
+ * sort(map, ([k1], [k2]) => k1.localeCompare(k2))
283
+ * console.log(entriesArray(map)) // [['a', 1], ['b', 2], ['c', 3]]
284
+ * ```
285
+ */
286
+ declare function sort<K, V>(ins: GenericMap<K, V, 'set' | 'clear' | typeof Symbol.iterator>, compare: (a: [K, V], b: [K, V]) => number): GenericMap<K, V, 'set' | 'clear' | typeof Symbol.iterator>;
287
+
288
+ /**
289
+ * Sorts the map entries by their keys and updates the map in place.
290
+ *
291
+ * @param ins - The map instance to sort
292
+ * @param compare - Function that compares two keys
293
+ * @returns The map instance for method chaining
294
+ *
295
+ * @example
296
+ * ```typescript
297
+ * const map = new ExtMap<string, number>([
298
+ * ['c', 3],
299
+ * ['a', 1],
300
+ * ['b', 2],
301
+ * ])
302
+ *
303
+ * sortByKeys(map, (a, b) => a.localeCompare(b))
304
+ * console.log(entriesArray(map)) // [['a', 1], ['b', 2], ['c', 3]]
305
+ * ```
306
+ */
307
+ declare function sortByKeys<K, V>(ins: GenericMap<K, V, 'set' | 'clear' | typeof Symbol.iterator>, compare: (a: K, b: K) => number): GenericMap<K, V, 'set' | 'clear' | typeof Symbol.iterator>;
308
+
309
+ /**
310
+ * Sorts the map entries by their values and updates the map in place.
311
+ *
312
+ * @param ins - The map instance to sort
313
+ * @param compare - Function that compares two values
314
+ * @returns The map instance for method chaining
315
+ *
316
+ * @example
317
+ * ```typescript
318
+ * const map = new ExtMap<string, number>([
319
+ * ['c', 3],
320
+ * ['a', 1],
321
+ * ['b', 2],
322
+ * ])
323
+ *
324
+ * sortByValues(map, (a, b) => a - b)
325
+ * console.log(entriesArray(map)) // [['a', 1], ['b', 2], ['c', 3]]
326
+ * ```
327
+ */
328
+ declare function sortByValues<T extends GenericMap<K, V, 'set' | 'clear' | typeof Symbol.iterator>, K, V>(ins: T, compare: (a: V, b: V) => number): T;
329
+ declare function sortByValues<K, V>(ins: GenericMap<K, V, 'set' | 'clear' | typeof Symbol.iterator>, compare: (a: V, b: V) => number): GenericMap<K, V, 'set' | 'clear' | typeof Symbol.iterator>;
330
+
331
+ /**
332
+ * Converts a GenericMap to a native Map.
333
+ *
334
+ * @param ins - The GenericMap instance to convert
335
+ * @returns A new native Map with the same entries
336
+ *
337
+ * @example
338
+ * ```typescript
339
+ * const extMap = new ExtMap<string, number>()
340
+ * .load([['a', 1], ['b', 2], ['c', 3]])
341
+ *
342
+ * const nativeMap = toMap(extMap)
343
+ * console.log(nativeMap instanceof Map) // true
344
+ * ```
345
+ */
346
+ declare function toMap<K, V>(ins: GenericMap<K, V, typeof Symbol.iterator>): Map<K, V>;
347
+
348
+ /**
349
+ * Returns an array of all values in the map.
350
+ * Convenience method that converts the values iterator to an array.
351
+ *
352
+ * @returns Array of all values
353
+ *
354
+ * @example
355
+ * ```typescript
356
+ * const map = new ExtMap<string, number>()
357
+ * .load([['a', 1], ['b', 2], ['c', 3]])
358
+ *
359
+ * console.log(valuesArray(map)) // [1, 2, 3]
360
+ * ```
361
+ */
362
+ declare function valuesArray<K, V>(ins: GenericMap<K, V, 'values'>): V[];
363
+
364
+ export { ExtMap, TimeoutWeakMap, countUniques, entriesArray, isGenericMap, keysArray, mapGetOrDefault, mapLoad, mapReverse, mapUpdate, sort, sortByKeys, sortByValues, toMap, valuesArray };