@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.
- package/README.md +100 -0
- package/lib/ExtMap.cjs +104 -0
- package/lib/ExtMap.d.cts +110 -0
- package/lib/ExtMap.d.ts +110 -0
- package/lib/ExtMap.js +101 -0
- package/lib/TimeoutWeakMap.cjs +120 -0
- package/lib/TimeoutWeakMap.d.cts +75 -0
- package/lib/TimeoutWeakMap.d.ts +75 -0
- package/lib/TimeoutWeakMap.js +118 -0
- package/lib/countUniques.cjs +18 -0
- package/lib/countUniques.d.cts +9 -0
- package/lib/countUniques.d.ts +9 -0
- package/lib/countUniques.js +15 -0
- package/lib/entriesArray.cjs +10 -0
- package/lib/entriesArray.d.cts +19 -0
- package/lib/entriesArray.d.ts +19 -0
- package/lib/entriesArray.js +8 -0
- package/lib/index.cjs +110 -0
- package/lib/index.d.cts +17 -0
- package/lib/index.d.ts +17 -0
- package/lib/index.js +15 -0
- package/lib/isGenericMap.cjs +16 -0
- package/lib/isGenericMap.d.cts +6 -0
- package/lib/isGenericMap.d.ts +6 -0
- package/lib/isGenericMap.js +14 -0
- package/lib/keysArray.cjs +10 -0
- package/lib/keysArray.d.cts +19 -0
- package/lib/keysArray.d.ts +19 -0
- package/lib/keysArray.js +8 -0
- package/lib/mapGetOrDefault.cjs +16 -0
- package/lib/mapGetOrDefault.d.cts +8 -0
- package/lib/mapGetOrDefault.d.ts +8 -0
- package/lib/mapGetOrDefault.js +14 -0
- package/lib/mapLoad.cjs +13 -0
- package/lib/mapLoad.d.cts +11 -0
- package/lib/mapLoad.d.ts +11 -0
- package/lib/mapLoad.js +11 -0
- package/lib/mapReverse.cjs +15 -0
- package/lib/mapReverse.d.cts +15 -0
- package/lib/mapReverse.d.ts +15 -0
- package/lib/mapReverse.js +12 -0
- package/lib/mapUpdate.cjs +12 -0
- package/lib/mapUpdate.d.cts +13 -0
- package/lib/mapUpdate.d.ts +13 -0
- package/lib/mapUpdate.js +10 -0
- package/lib/sort.cjs +15 -0
- package/lib/sort.d.cts +25 -0
- package/lib/sort.d.ts +25 -0
- package/lib/sort.js +13 -0
- package/lib/sortByKeys.cjs +17 -0
- package/lib/sortByKeys.d.cts +24 -0
- package/lib/sortByKeys.d.ts +24 -0
- package/lib/sortByKeys.js +15 -0
- package/lib/sortByValues.cjs +17 -0
- package/lib/sortByValues.d.cts +25 -0
- package/lib/sortByValues.d.ts +25 -0
- package/lib/sortByValues.js +15 -0
- package/lib/toMap.cjs +10 -0
- package/lib/toMap.d.cts +20 -0
- package/lib/toMap.d.ts +20 -0
- package/lib/toMap.js +8 -0
- package/lib/valuesArray.cjs +10 -0
- package/lib/valuesArray.d.cts +19 -0
- package/lib/valuesArray.d.ts +19 -0
- package/lib/valuesArray.js +8 -0
- package/package.json +250 -19
- package/index.d.ts +0 -348
- package/index.mjs +0 -446
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A WeakMap with automatic timeout-based expiry for entries.
|
|
3
|
+
*
|
|
4
|
+
* Entries are automatically removed after a specified timeout period.
|
|
5
|
+
* Accessing an entry refreshes its timeout, extending its lifetime.
|
|
6
|
+
* This is useful for caching scenarios where you want automatic cleanup
|
|
7
|
+
* of unused entries while keeping frequently accessed ones alive.
|
|
8
|
+
*/
|
|
9
|
+
declare class TimeoutWeakMap<K extends object, V> {
|
|
10
|
+
readonly timeoutMs: number;
|
|
11
|
+
protected readonly wmap: WeakMap<K, [V, NodeJS.Timeout]>;
|
|
12
|
+
/**
|
|
13
|
+
* @param timeoutMs Default timeout in milliseconds for entries
|
|
14
|
+
*/
|
|
15
|
+
constructor(timeoutMs: number);
|
|
16
|
+
/**
|
|
17
|
+
* Retrieves the value for the given key and refreshes its timeout.
|
|
18
|
+
*
|
|
19
|
+
* @param key The key to retrieve
|
|
20
|
+
* @returns The value if found, undefined otherwise
|
|
21
|
+
*/
|
|
22
|
+
get(key: K): V | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Sets a key-value pair with an optional custom timeout.
|
|
25
|
+
*
|
|
26
|
+
* @param key The key to set
|
|
27
|
+
* @param value The value to associate with the key
|
|
28
|
+
* @param timeoutMs Optional timeout override for this entry
|
|
29
|
+
* @returns This instance for chaining
|
|
30
|
+
*/
|
|
31
|
+
set(key: K, value: V, timeoutMs?: number): this;
|
|
32
|
+
/**
|
|
33
|
+
* Removes a key-value pair and clears its timeout.
|
|
34
|
+
*
|
|
35
|
+
* @param key The key to delete
|
|
36
|
+
* @returns True if the key existed and was deleted, false otherwise
|
|
37
|
+
*/
|
|
38
|
+
delete(key: K): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Checks if a key exists in the map.
|
|
41
|
+
* Does not refresh the timeout.
|
|
42
|
+
*
|
|
43
|
+
* @param key The key to check
|
|
44
|
+
* @returns True if the key exists, false otherwise
|
|
45
|
+
*/
|
|
46
|
+
has(key: K): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Loads multiple key-value pairs into the map.
|
|
49
|
+
*
|
|
50
|
+
* @param entries Iterable of key-value pairs to load
|
|
51
|
+
* @param timeoutMs Optional timeout override for all entries
|
|
52
|
+
* @returns This instance for chaining
|
|
53
|
+
*/
|
|
54
|
+
load(entries: Iterable<[K, V]>, timeoutMs?: number): this;
|
|
55
|
+
/**
|
|
56
|
+
* Updates an existing value or creates a new one using an update function.
|
|
57
|
+
*
|
|
58
|
+
* @param key The key to update
|
|
59
|
+
* @param update Function that receives the current value and returns the new value
|
|
60
|
+
* @returns This instance for chaining
|
|
61
|
+
*/
|
|
62
|
+
update(key: K, update: (value: V | undefined, key: K, map: this) => V): this;
|
|
63
|
+
/**
|
|
64
|
+
* Gets a value or creates it using a factory function if it doesn't exist.
|
|
65
|
+
* Refreshes timeout if the value exists.
|
|
66
|
+
*
|
|
67
|
+
* @param key The key to get or create
|
|
68
|
+
* @param factory Function to create the value if it doesn't exist
|
|
69
|
+
* @param timeoutMs Optional timeout override for new entries
|
|
70
|
+
* @returns The existing or newly created value
|
|
71
|
+
*/
|
|
72
|
+
getOrDefault(key: K, factory: (key: K, map: this) => V, timeoutMs?: number): V;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export { TimeoutWeakMap };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A WeakMap with automatic timeout-based expiry for entries.
|
|
3
|
+
*
|
|
4
|
+
* Entries are automatically removed after a specified timeout period.
|
|
5
|
+
* Accessing an entry refreshes its timeout, extending its lifetime.
|
|
6
|
+
* This is useful for caching scenarios where you want automatic cleanup
|
|
7
|
+
* of unused entries while keeping frequently accessed ones alive.
|
|
8
|
+
*/
|
|
9
|
+
declare class TimeoutWeakMap<K extends object, V> {
|
|
10
|
+
readonly timeoutMs: number;
|
|
11
|
+
protected readonly wmap: WeakMap<K, [V, NodeJS.Timeout]>;
|
|
12
|
+
/**
|
|
13
|
+
* @param timeoutMs Default timeout in milliseconds for entries
|
|
14
|
+
*/
|
|
15
|
+
constructor(timeoutMs: number);
|
|
16
|
+
/**
|
|
17
|
+
* Retrieves the value for the given key and refreshes its timeout.
|
|
18
|
+
*
|
|
19
|
+
* @param key The key to retrieve
|
|
20
|
+
* @returns The value if found, undefined otherwise
|
|
21
|
+
*/
|
|
22
|
+
get(key: K): V | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Sets a key-value pair with an optional custom timeout.
|
|
25
|
+
*
|
|
26
|
+
* @param key The key to set
|
|
27
|
+
* @param value The value to associate with the key
|
|
28
|
+
* @param timeoutMs Optional timeout override for this entry
|
|
29
|
+
* @returns This instance for chaining
|
|
30
|
+
*/
|
|
31
|
+
set(key: K, value: V, timeoutMs?: number): this;
|
|
32
|
+
/**
|
|
33
|
+
* Removes a key-value pair and clears its timeout.
|
|
34
|
+
*
|
|
35
|
+
* @param key The key to delete
|
|
36
|
+
* @returns True if the key existed and was deleted, false otherwise
|
|
37
|
+
*/
|
|
38
|
+
delete(key: K): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Checks if a key exists in the map.
|
|
41
|
+
* Does not refresh the timeout.
|
|
42
|
+
*
|
|
43
|
+
* @param key The key to check
|
|
44
|
+
* @returns True if the key exists, false otherwise
|
|
45
|
+
*/
|
|
46
|
+
has(key: K): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Loads multiple key-value pairs into the map.
|
|
49
|
+
*
|
|
50
|
+
* @param entries Iterable of key-value pairs to load
|
|
51
|
+
* @param timeoutMs Optional timeout override for all entries
|
|
52
|
+
* @returns This instance for chaining
|
|
53
|
+
*/
|
|
54
|
+
load(entries: Iterable<[K, V]>, timeoutMs?: number): this;
|
|
55
|
+
/**
|
|
56
|
+
* Updates an existing value or creates a new one using an update function.
|
|
57
|
+
*
|
|
58
|
+
* @param key The key to update
|
|
59
|
+
* @param update Function that receives the current value and returns the new value
|
|
60
|
+
* @returns This instance for chaining
|
|
61
|
+
*/
|
|
62
|
+
update(key: K, update: (value: V | undefined, key: K, map: this) => V): this;
|
|
63
|
+
/**
|
|
64
|
+
* Gets a value or creates it using a factory function if it doesn't exist.
|
|
65
|
+
* Refreshes timeout if the value exists.
|
|
66
|
+
*
|
|
67
|
+
* @param key The key to get or create
|
|
68
|
+
* @param factory Function to create the value if it doesn't exist
|
|
69
|
+
* @param timeoutMs Optional timeout override for new entries
|
|
70
|
+
* @returns The existing or newly created value
|
|
71
|
+
*/
|
|
72
|
+
getOrDefault(key: K, factory: (key: K, map: this) => V, timeoutMs?: number): V;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export { TimeoutWeakMap };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { __name } from './chunk-SHUYVCID.js';
|
|
2
|
+
|
|
3
|
+
class TimeoutWeakMap {
|
|
4
|
+
static {
|
|
5
|
+
__name(this, "TimeoutWeakMap");
|
|
6
|
+
}
|
|
7
|
+
timeoutMs;
|
|
8
|
+
wmap = /* @__PURE__ */ new WeakMap();
|
|
9
|
+
/**
|
|
10
|
+
* @param timeoutMs Default timeout in milliseconds for entries
|
|
11
|
+
*/
|
|
12
|
+
constructor(timeoutMs) {
|
|
13
|
+
this.timeoutMs = timeoutMs;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves the value for the given key and refreshes its timeout.
|
|
17
|
+
*
|
|
18
|
+
* @param key The key to retrieve
|
|
19
|
+
* @returns The value if found, undefined otherwise
|
|
20
|
+
*/
|
|
21
|
+
get(key) {
|
|
22
|
+
const vt = this.wmap.get(key);
|
|
23
|
+
if (!vt) {
|
|
24
|
+
return void 0;
|
|
25
|
+
}
|
|
26
|
+
const [value, timeout] = vt;
|
|
27
|
+
timeout.refresh();
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Sets a key-value pair with an optional custom timeout.
|
|
32
|
+
*
|
|
33
|
+
* @param key The key to set
|
|
34
|
+
* @param value The value to associate with the key
|
|
35
|
+
* @param timeoutMs Optional timeout override for this entry
|
|
36
|
+
* @returns This instance for chaining
|
|
37
|
+
*/
|
|
38
|
+
set(key, value, timeoutMs) {
|
|
39
|
+
this.wmap.set(key, [
|
|
40
|
+
value,
|
|
41
|
+
setTimeout(() => {
|
|
42
|
+
this.delete(key);
|
|
43
|
+
}, timeoutMs ?? this.timeoutMs).unref()
|
|
44
|
+
]);
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Removes a key-value pair and clears its timeout.
|
|
49
|
+
*
|
|
50
|
+
* @param key The key to delete
|
|
51
|
+
* @returns True if the key existed and was deleted, false otherwise
|
|
52
|
+
*/
|
|
53
|
+
delete(key) {
|
|
54
|
+
const vt = this.wmap.get(key);
|
|
55
|
+
if (!vt) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
const timeout = vt[1];
|
|
59
|
+
clearTimeout(timeout);
|
|
60
|
+
return this.wmap.delete(key);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Checks if a key exists in the map.
|
|
64
|
+
* Does not refresh the timeout.
|
|
65
|
+
*
|
|
66
|
+
* @param key The key to check
|
|
67
|
+
* @returns True if the key exists, false otherwise
|
|
68
|
+
*/
|
|
69
|
+
has(key) {
|
|
70
|
+
return this.wmap.has(key);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Loads multiple key-value pairs into the map.
|
|
74
|
+
*
|
|
75
|
+
* @param entries Iterable of key-value pairs to load
|
|
76
|
+
* @param timeoutMs Optional timeout override for all entries
|
|
77
|
+
* @returns This instance for chaining
|
|
78
|
+
*/
|
|
79
|
+
load(entries, timeoutMs) {
|
|
80
|
+
for (const [key, value] of entries) {
|
|
81
|
+
this.set(key, value, timeoutMs);
|
|
82
|
+
}
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Updates an existing value or creates a new one using an update function.
|
|
87
|
+
*
|
|
88
|
+
* @param key The key to update
|
|
89
|
+
* @param update Function that receives the current value and returns the new value
|
|
90
|
+
* @returns This instance for chaining
|
|
91
|
+
*/
|
|
92
|
+
update(key, update) {
|
|
93
|
+
return this.set(key, update(this.get(key), key, this));
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Gets a value or creates it using a factory function if it doesn't exist.
|
|
97
|
+
* Refreshes timeout if the value exists.
|
|
98
|
+
*
|
|
99
|
+
* @param key The key to get or create
|
|
100
|
+
* @param factory Function to create the value if it doesn't exist
|
|
101
|
+
* @param timeoutMs Optional timeout override for new entries
|
|
102
|
+
* @returns The existing or newly created value
|
|
103
|
+
*/
|
|
104
|
+
getOrDefault(key, factory, timeoutMs) {
|
|
105
|
+
const vt = this.wmap.get(key);
|
|
106
|
+
if (vt) {
|
|
107
|
+
const [value, timeout] = vt;
|
|
108
|
+
timeout.refresh();
|
|
109
|
+
return value;
|
|
110
|
+
} else {
|
|
111
|
+
const value = factory(key, this);
|
|
112
|
+
this.set(key, value, timeoutMs);
|
|
113
|
+
return value;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export { TimeoutWeakMap };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ExtMap = require('./ExtMap');
|
|
4
|
+
var mnemonist = require('mnemonist');
|
|
5
|
+
var iterTools = require('iter-tools');
|
|
6
|
+
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
function countUniques(input) {
|
|
10
|
+
return new ExtMap.ExtMap(iterTools.reduce(new mnemonist.MultiSet(), (acc, imp) => {
|
|
11
|
+
return acc.add(imp);
|
|
12
|
+
}, input).multiplicities()).sortByValues((a, b) => {
|
|
13
|
+
return b - a;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
__name(countUniques, "countUniques");
|
|
17
|
+
|
|
18
|
+
exports.countUniques = countUniques;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ExtMap } from './ExtMap.cjs';
|
|
2
|
+
import 'util';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Count unique occurrences of values in an iterable, returning a sorted map by count descending.
|
|
6
|
+
*/
|
|
7
|
+
declare function countUniques<V>(input: Iterable<V>): ExtMap<V, number>;
|
|
8
|
+
|
|
9
|
+
export { countUniques };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ExtMap } from './ExtMap.js';
|
|
2
|
+
import 'util';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Count unique occurrences of values in an iterable, returning a sorted map by count descending.
|
|
6
|
+
*/
|
|
7
|
+
declare function countUniques<V>(input: Iterable<V>): ExtMap<V, number>;
|
|
8
|
+
|
|
9
|
+
export { countUniques };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { __name } from './chunk-SHUYVCID.js';
|
|
2
|
+
import { ExtMap } from './ExtMap';
|
|
3
|
+
import { MultiSet } from 'mnemonist';
|
|
4
|
+
import { reduce } from 'iter-tools';
|
|
5
|
+
|
|
6
|
+
function countUniques(input) {
|
|
7
|
+
return new ExtMap(reduce(new MultiSet(), (acc, imp) => {
|
|
8
|
+
return acc.add(imp);
|
|
9
|
+
}, input).multiplicities()).sortByValues((a, b) => {
|
|
10
|
+
return b - a;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
__name(countUniques, "countUniques");
|
|
14
|
+
|
|
15
|
+
export { countUniques };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
function entriesArray(ins) {
|
|
6
|
+
return Array.from(ins);
|
|
7
|
+
}
|
|
8
|
+
__name(entriesArray, "entriesArray");
|
|
9
|
+
|
|
10
|
+
exports.entriesArray = entriesArray;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { G as GenericMap } from './GenericMap-B4OM3vGu.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns an array of all key-value pairs in the map.
|
|
5
|
+
* Convenience method that converts the entries iterator to an array.
|
|
6
|
+
*
|
|
7
|
+
* @returns Array of all key-value pairs
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const map = new ExtMap<string, number>()
|
|
12
|
+
* .load([['a', 1], ['b', 2], ['c', 3]])
|
|
13
|
+
*
|
|
14
|
+
* console.log(entriesArray(map)) // [['a', 1], ['b', 2], ['c', 3]]
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare function entriesArray<K, V>(ins: GenericMap<K, V, typeof Symbol.iterator>): [K, V][];
|
|
18
|
+
|
|
19
|
+
export { entriesArray };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { G as GenericMap } from './GenericMap-B4OM3vGu.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns an array of all key-value pairs in the map.
|
|
5
|
+
* Convenience method that converts the entries iterator to an array.
|
|
6
|
+
*
|
|
7
|
+
* @returns Array of all key-value pairs
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const map = new ExtMap<string, number>()
|
|
12
|
+
* .load([['a', 1], ['b', 2], ['c', 3]])
|
|
13
|
+
*
|
|
14
|
+
* console.log(entriesArray(map)) // [['a', 1], ['b', 2], ['c', 3]]
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare function entriesArray<K, V>(ins: GenericMap<K, V, typeof Symbol.iterator>): [K, V][];
|
|
18
|
+
|
|
19
|
+
export { entriesArray };
|
package/lib/index.cjs
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ExtMap = require('./ExtMap');
|
|
4
|
+
var TimeoutWeakMap = require('./TimeoutWeakMap');
|
|
5
|
+
var countUniques = require('./countUniques');
|
|
6
|
+
var entriesArray = require('./entriesArray');
|
|
7
|
+
var isGenericMap = require('./isGenericMap');
|
|
8
|
+
var keysArray = require('./keysArray');
|
|
9
|
+
var mapGetOrDefault = require('./mapGetOrDefault');
|
|
10
|
+
var mapLoad = require('./mapLoad');
|
|
11
|
+
var mapReverse = require('./mapReverse');
|
|
12
|
+
var mapUpdate = require('./mapUpdate');
|
|
13
|
+
var sort = require('./sort');
|
|
14
|
+
var sortByKeys = require('./sortByKeys');
|
|
15
|
+
var sortByValues = require('./sortByValues');
|
|
16
|
+
var toMap = require('./toMap');
|
|
17
|
+
var valuesArray = require('./valuesArray');
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
Object.keys(ExtMap).forEach(function (k) {
|
|
22
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () { return ExtMap[k]; }
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
Object.keys(TimeoutWeakMap).forEach(function (k) {
|
|
28
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () { return TimeoutWeakMap[k]; }
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
Object.keys(countUniques).forEach(function (k) {
|
|
34
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get: function () { return countUniques[k]; }
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
Object.keys(entriesArray).forEach(function (k) {
|
|
40
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function () { return entriesArray[k]; }
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
Object.keys(isGenericMap).forEach(function (k) {
|
|
46
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
get: function () { return isGenericMap[k]; }
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
Object.keys(keysArray).forEach(function (k) {
|
|
52
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
get: function () { return keysArray[k]; }
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
Object.keys(mapGetOrDefault).forEach(function (k) {
|
|
58
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
59
|
+
enumerable: true,
|
|
60
|
+
get: function () { return mapGetOrDefault[k]; }
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
Object.keys(mapLoad).forEach(function (k) {
|
|
64
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
get: function () { return mapLoad[k]; }
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
Object.keys(mapReverse).forEach(function (k) {
|
|
70
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
71
|
+
enumerable: true,
|
|
72
|
+
get: function () { return mapReverse[k]; }
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
Object.keys(mapUpdate).forEach(function (k) {
|
|
76
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
get: function () { return mapUpdate[k]; }
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
Object.keys(sort).forEach(function (k) {
|
|
82
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
83
|
+
enumerable: true,
|
|
84
|
+
get: function () { return sort[k]; }
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
Object.keys(sortByKeys).forEach(function (k) {
|
|
88
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
89
|
+
enumerable: true,
|
|
90
|
+
get: function () { return sortByKeys[k]; }
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
Object.keys(sortByValues).forEach(function (k) {
|
|
94
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
95
|
+
enumerable: true,
|
|
96
|
+
get: function () { return sortByValues[k]; }
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
Object.keys(toMap).forEach(function (k) {
|
|
100
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
101
|
+
enumerable: true,
|
|
102
|
+
get: function () { return toMap[k]; }
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
Object.keys(valuesArray).forEach(function (k) {
|
|
106
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
107
|
+
enumerable: true,
|
|
108
|
+
get: function () { return valuesArray[k]; }
|
|
109
|
+
});
|
|
110
|
+
});
|
package/lib/index.d.cts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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';
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { ExtMap } from './ExtMap.js';
|
|
2
|
+
export { TimeoutWeakMap } from './TimeoutWeakMap.js';
|
|
3
|
+
export { countUniques } from './countUniques.js';
|
|
4
|
+
export { entriesArray } from './entriesArray.js';
|
|
5
|
+
export { isGenericMap } from './isGenericMap.js';
|
|
6
|
+
export { keysArray } from './keysArray.js';
|
|
7
|
+
export { mapGetOrDefault } from './mapGetOrDefault.js';
|
|
8
|
+
export { mapLoad } from './mapLoad.js';
|
|
9
|
+
export { mapReverse } from './mapReverse.js';
|
|
10
|
+
export { mapUpdate } from './mapUpdate.js';
|
|
11
|
+
export { sort } from './sort.js';
|
|
12
|
+
export { sortByKeys } from './sortByKeys.js';
|
|
13
|
+
export { sortByValues } from './sortByValues.js';
|
|
14
|
+
export { toMap } from './toMap.js';
|
|
15
|
+
export { valuesArray } from './valuesArray.js';
|
|
16
|
+
import 'util';
|
|
17
|
+
import './GenericMap-B4OM3vGu.js';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from './ExtMap';
|
|
2
|
+
export * from './TimeoutWeakMap';
|
|
3
|
+
export * from './countUniques';
|
|
4
|
+
export * from './entriesArray';
|
|
5
|
+
export * from './isGenericMap';
|
|
6
|
+
export * from './keysArray';
|
|
7
|
+
export * from './mapGetOrDefault';
|
|
8
|
+
export * from './mapLoad';
|
|
9
|
+
export * from './mapReverse';
|
|
10
|
+
export * from './mapUpdate';
|
|
11
|
+
export * from './sort';
|
|
12
|
+
export * from './sortByKeys';
|
|
13
|
+
export * from './sortByValues';
|
|
14
|
+
export * from './toMap';
|
|
15
|
+
export * from './valuesArray';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
function isGenericMap(target, requiredProps = [
|
|
6
|
+
"get",
|
|
7
|
+
"set",
|
|
8
|
+
"has"
|
|
9
|
+
]) {
|
|
10
|
+
return !!target && requiredProps.every((prop) => {
|
|
11
|
+
return typeof target[prop] === typeof Map.prototype[prop];
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
__name(isGenericMap, "isGenericMap");
|
|
15
|
+
|
|
16
|
+
exports.isGenericMap = isGenericMap;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the provided value implements the Map interface with the specified required properties.
|
|
3
|
+
*/
|
|
4
|
+
declare function isGenericMap<Props extends (keyof Map<K, V>)[], K, V>(target: unknown, requiredProps?: Props): target is Pick<Map<K, V>, Props[number]>;
|
|
5
|
+
|
|
6
|
+
export { isGenericMap };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the provided value implements the Map interface with the specified required properties.
|
|
3
|
+
*/
|
|
4
|
+
declare function isGenericMap<Props extends (keyof Map<K, V>)[], K, V>(target: unknown, requiredProps?: Props): target is Pick<Map<K, V>, Props[number]>;
|
|
5
|
+
|
|
6
|
+
export { isGenericMap };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { __name } from './chunk-SHUYVCID.js';
|
|
2
|
+
|
|
3
|
+
function isGenericMap(target, requiredProps = [
|
|
4
|
+
"get",
|
|
5
|
+
"set",
|
|
6
|
+
"has"
|
|
7
|
+
]) {
|
|
8
|
+
return !!target && requiredProps.every((prop) => {
|
|
9
|
+
return typeof target[prop] === typeof Map.prototype[prop];
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
__name(isGenericMap, "isGenericMap");
|
|
13
|
+
|
|
14
|
+
export { isGenericMap };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
function keysArray(ins) {
|
|
6
|
+
return Array.from(ins.keys());
|
|
7
|
+
}
|
|
8
|
+
__name(keysArray, "keysArray");
|
|
9
|
+
|
|
10
|
+
exports.keysArray = keysArray;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { G as GenericMap } from './GenericMap-B4OM3vGu.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns an array of all keys in the map.
|
|
5
|
+
* Convenience method that converts the keys iterator to an array.
|
|
6
|
+
*
|
|
7
|
+
* @returns Array of all keys
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const map = new ExtMap<string, number>()
|
|
12
|
+
* .load([['a', 1], ['b', 2], ['c', 3]])
|
|
13
|
+
*
|
|
14
|
+
* console.log(keysArray(map)) // ['a', 'b', 'c']
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare function keysArray<K, V>(ins: GenericMap<K, V, 'keys'>): K[];
|
|
18
|
+
|
|
19
|
+
export { keysArray };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { G as GenericMap } from './GenericMap-B4OM3vGu.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns an array of all keys in the map.
|
|
5
|
+
* Convenience method that converts the keys iterator to an array.
|
|
6
|
+
*
|
|
7
|
+
* @returns Array of all keys
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const map = new ExtMap<string, number>()
|
|
12
|
+
* .load([['a', 1], ['b', 2], ['c', 3]])
|
|
13
|
+
*
|
|
14
|
+
* console.log(keysArray(map)) // ['a', 'b', 'c']
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare function keysArray<K, V>(ins: GenericMap<K, V, 'keys'>): K[];
|
|
18
|
+
|
|
19
|
+
export { keysArray };
|