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