@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.
- package/README.md +23 -21
- package/lib/index.cjs +33 -122
- package/lib/index.d.cts +364 -17
- package/lib/index.d.ts +364 -17
- package/lib/index.js +15 -104
- package/package.json +21 -221
- package/lib/ExtMap.cjs +0 -354
- package/lib/ExtMap.d.cts +0 -110
- package/lib/ExtMap.d.ts +0 -110
- package/lib/ExtMap.js +0 -352
- package/lib/TimeoutWeakMap.cjs +0 -122
- package/lib/TimeoutWeakMap.d.cts +0 -75
- package/lib/TimeoutWeakMap.d.ts +0 -75
- package/lib/TimeoutWeakMap.js +0 -120
- package/lib/countUniques.cjs +0 -363
- package/lib/countUniques.d.cts +0 -9
- package/lib/countUniques.d.ts +0 -9
- package/lib/countUniques.js +0 -361
- package/lib/entriesArray.cjs +0 -12
- package/lib/entriesArray.d.cts +0 -19
- package/lib/entriesArray.d.ts +0 -19
- package/lib/entriesArray.js +0 -10
- package/lib/isGenericMap.cjs +0 -18
- package/lib/isGenericMap.d.cts +0 -6
- package/lib/isGenericMap.d.ts +0 -6
- package/lib/isGenericMap.js +0 -16
- package/lib/keysArray.cjs +0 -12
- package/lib/keysArray.d.cts +0 -19
- package/lib/keysArray.d.ts +0 -19
- package/lib/keysArray.js +0 -10
- package/lib/mapGetOrDefault.cjs +0 -18
- package/lib/mapGetOrDefault.d.cts +0 -8
- package/lib/mapGetOrDefault.d.ts +0 -8
- package/lib/mapGetOrDefault.js +0 -16
- package/lib/mapLoad.cjs +0 -15
- package/lib/mapLoad.d.cts +0 -11
- package/lib/mapLoad.d.ts +0 -11
- package/lib/mapLoad.js +0 -13
- package/lib/mapReverse.cjs +0 -24
- package/lib/mapReverse.d.cts +0 -15
- package/lib/mapReverse.d.ts +0 -15
- package/lib/mapReverse.js +0 -22
- package/lib/mapUpdate.cjs +0 -14
- package/lib/mapUpdate.d.cts +0 -13
- package/lib/mapUpdate.d.ts +0 -13
- package/lib/mapUpdate.js +0 -12
- package/lib/sort.cjs +0 -17
- package/lib/sort.d.cts +0 -25
- package/lib/sort.d.ts +0 -25
- package/lib/sort.js +0 -15
- package/lib/sortByKeys.cjs +0 -19
- package/lib/sortByKeys.d.cts +0 -24
- package/lib/sortByKeys.d.ts +0 -24
- package/lib/sortByKeys.js +0 -17
- package/lib/sortByValues.cjs +0 -19
- package/lib/sortByValues.d.cts +0 -25
- package/lib/sortByValues.d.ts +0 -25
- package/lib/sortByValues.js +0 -17
- package/lib/toMap.cjs +0 -12
- package/lib/toMap.d.cts +0 -20
- package/lib/toMap.d.ts +0 -20
- package/lib/toMap.js +0 -10
- package/lib/valuesArray.cjs +0 -12
- package/lib/valuesArray.d.cts +0 -19
- package/lib/valuesArray.d.ts +0 -19
- package/lib/valuesArray.js +0 -10
package/lib/TimeoutWeakMap.d.cts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
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 };
|
package/lib/TimeoutWeakMap.d.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
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 };
|
package/lib/TimeoutWeakMap.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
|
-
// src/TimeoutWeakMap.ts
|
|
5
|
-
var TimeoutWeakMap = class {
|
|
6
|
-
static {
|
|
7
|
-
__name(this, "TimeoutWeakMap");
|
|
8
|
-
}
|
|
9
|
-
timeoutMs;
|
|
10
|
-
wmap = /* @__PURE__ */ new WeakMap();
|
|
11
|
-
/**
|
|
12
|
-
* @param timeoutMs Default timeout in milliseconds for entries
|
|
13
|
-
*/
|
|
14
|
-
constructor(timeoutMs) {
|
|
15
|
-
this.timeoutMs = timeoutMs;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Retrieves the value for the given key and refreshes its timeout.
|
|
19
|
-
*
|
|
20
|
-
* @param key The key to retrieve
|
|
21
|
-
* @returns The value if found, undefined otherwise
|
|
22
|
-
*/
|
|
23
|
-
get(key) {
|
|
24
|
-
const vt = this.wmap.get(key);
|
|
25
|
-
if (!vt) {
|
|
26
|
-
return void 0;
|
|
27
|
-
}
|
|
28
|
-
const [value, timeout] = vt;
|
|
29
|
-
timeout.refresh();
|
|
30
|
-
return value;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Sets a key-value pair with an optional custom timeout.
|
|
34
|
-
*
|
|
35
|
-
* @param key The key to set
|
|
36
|
-
* @param value The value to associate with the key
|
|
37
|
-
* @param timeoutMs Optional timeout override for this entry
|
|
38
|
-
* @returns This instance for chaining
|
|
39
|
-
*/
|
|
40
|
-
set(key, value, timeoutMs) {
|
|
41
|
-
this.wmap.set(key, [
|
|
42
|
-
value,
|
|
43
|
-
setTimeout(() => {
|
|
44
|
-
this.delete(key);
|
|
45
|
-
}, timeoutMs ?? this.timeoutMs).unref()
|
|
46
|
-
]);
|
|
47
|
-
return this;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Removes a key-value pair and clears its timeout.
|
|
51
|
-
*
|
|
52
|
-
* @param key The key to delete
|
|
53
|
-
* @returns True if the key existed and was deleted, false otherwise
|
|
54
|
-
*/
|
|
55
|
-
delete(key) {
|
|
56
|
-
const vt = this.wmap.get(key);
|
|
57
|
-
if (!vt) {
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
const timeout = vt[1];
|
|
61
|
-
clearTimeout(timeout);
|
|
62
|
-
return this.wmap.delete(key);
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Checks if a key exists in the map.
|
|
66
|
-
* Does not refresh the timeout.
|
|
67
|
-
*
|
|
68
|
-
* @param key The key to check
|
|
69
|
-
* @returns True if the key exists, false otherwise
|
|
70
|
-
*/
|
|
71
|
-
has(key) {
|
|
72
|
-
return this.wmap.has(key);
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Loads multiple key-value pairs into the map.
|
|
76
|
-
*
|
|
77
|
-
* @param entries Iterable of key-value pairs to load
|
|
78
|
-
* @param timeoutMs Optional timeout override for all entries
|
|
79
|
-
* @returns This instance for chaining
|
|
80
|
-
*/
|
|
81
|
-
load(entries, timeoutMs) {
|
|
82
|
-
for (const [key, value] of entries) {
|
|
83
|
-
this.set(key, value, timeoutMs);
|
|
84
|
-
}
|
|
85
|
-
return this;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Updates an existing value or creates a new one using an update function.
|
|
89
|
-
*
|
|
90
|
-
* @param key The key to update
|
|
91
|
-
* @param update Function that receives the current value and returns the new value
|
|
92
|
-
* @returns This instance for chaining
|
|
93
|
-
*/
|
|
94
|
-
update(key, update) {
|
|
95
|
-
return this.set(key, update(this.get(key), key, this));
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Gets a value or creates it using a factory function if it doesn't exist.
|
|
99
|
-
* Refreshes timeout if the value exists.
|
|
100
|
-
*
|
|
101
|
-
* @param key The key to get or create
|
|
102
|
-
* @param factory Function to create the value if it doesn't exist
|
|
103
|
-
* @param timeoutMs Optional timeout override for new entries
|
|
104
|
-
* @returns The existing or newly created value
|
|
105
|
-
*/
|
|
106
|
-
getOrDefault(key, factory, timeoutMs) {
|
|
107
|
-
const vt = this.wmap.get(key);
|
|
108
|
-
if (vt) {
|
|
109
|
-
const [value, timeout] = vt;
|
|
110
|
-
timeout.refresh();
|
|
111
|
-
return value;
|
|
112
|
-
} else {
|
|
113
|
-
const value = factory(key, this);
|
|
114
|
-
this.set(key, value, timeoutMs);
|
|
115
|
-
return value;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
export { TimeoutWeakMap };
|
package/lib/countUniques.cjs
DELETED
|
@@ -1,363 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var iterTools = require('iter-tools');
|
|
4
|
-
var util = require('util');
|
|
5
|
-
var mnemonist = require('mnemonist');
|
|
6
|
-
|
|
7
|
-
var __defProp = Object.defineProperty;
|
|
8
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
-
|
|
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
|
-
// ../composition/src/View.ts
|
|
29
|
-
var TARGET_SYMBOL = /* @__PURE__ */ Symbol("target");
|
|
30
|
-
var View = class {
|
|
31
|
-
static {
|
|
32
|
-
__name(this, "View");
|
|
33
|
-
}
|
|
34
|
-
[TARGET_SYMBOL];
|
|
35
|
-
constructor(target) {
|
|
36
|
-
this[TARGET_SYMBOL] = target;
|
|
37
|
-
}
|
|
38
|
-
get [Symbol.toStringTag]() {
|
|
39
|
-
return this.constructor.name;
|
|
40
|
-
}
|
|
41
|
-
get target() {
|
|
42
|
-
return this[TARGET_SYMBOL];
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
// ../composition/src/inheritProxifiedPrototypeProperty.ts
|
|
47
|
-
function inheritProxifiedPrototypeProperty(ViewerClass, TargetClass, key) {
|
|
48
|
-
const des = Reflect.getOwnPropertyDescriptor(TargetClass.prototype, key);
|
|
49
|
-
if (!des) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
if (des.value && typeof des.value === "function") {
|
|
53
|
-
return Object.defineProperty(ViewerClass.prototype, key, {
|
|
54
|
-
value(...args) {
|
|
55
|
-
return this.target[key](...args);
|
|
56
|
-
},
|
|
57
|
-
writable: true,
|
|
58
|
-
configurable: true,
|
|
59
|
-
enumerable: false
|
|
60
|
-
});
|
|
61
|
-
} else if (des && !des.get && !des.set) {
|
|
62
|
-
return Object.defineProperty(ViewerClass.prototype, key, {
|
|
63
|
-
get() {
|
|
64
|
-
return this.target[key];
|
|
65
|
-
},
|
|
66
|
-
set: des.writable ? /* @__PURE__ */ __name(function set(value) {
|
|
67
|
-
this.target[key] = value;
|
|
68
|
-
}, "set") : void 0,
|
|
69
|
-
configurable: true,
|
|
70
|
-
enumerable: false
|
|
71
|
-
});
|
|
72
|
-
} else {
|
|
73
|
-
Object.defineProperty(ViewerClass.prototype, key, {
|
|
74
|
-
get: des.get ? function() {
|
|
75
|
-
return this.target[key];
|
|
76
|
-
} : void 0,
|
|
77
|
-
set: des.set ? function(value) {
|
|
78
|
-
this.target[key] = value;
|
|
79
|
-
} : void 0,
|
|
80
|
-
configurable: true,
|
|
81
|
-
enumerable: false
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
__name(inheritProxifiedPrototypeProperty, "inheritProxifiedPrototypeProperty");
|
|
86
|
-
|
|
87
|
-
// ../composition/src/inheritProxifiedPrototype.ts
|
|
88
|
-
function inheritProxifiedPrototype(ViewerClass, TargetClass, omitKeys) {
|
|
89
|
-
Reflect.ownKeys(TargetClass.prototype).filter((k) => {
|
|
90
|
-
return k !== "constructor" && k !== Symbol.toStringTag;
|
|
91
|
-
}).filter((k) => {
|
|
92
|
-
return omitKeys ? !omitKeys.includes(k) : true;
|
|
93
|
-
}).forEach((k) => {
|
|
94
|
-
return inheritProxifiedPrototypeProperty(ViewerClass, TargetClass, k);
|
|
95
|
-
});
|
|
96
|
-
return ViewerClass;
|
|
97
|
-
}
|
|
98
|
-
__name(inheritProxifiedPrototype, "inheritProxifiedPrototype");
|
|
99
|
-
|
|
100
|
-
// src/entriesArray.ts
|
|
101
|
-
function entriesArray(ins) {
|
|
102
|
-
return Array.from(ins);
|
|
103
|
-
}
|
|
104
|
-
__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
|
-
|
|
112
|
-
// src/keysArray.ts
|
|
113
|
-
function keysArray(ins) {
|
|
114
|
-
return Array.from(ins.keys());
|
|
115
|
-
}
|
|
116
|
-
__name(keysArray, "keysArray");
|
|
117
|
-
|
|
118
|
-
// src/mapGetOrDefault.ts
|
|
119
|
-
function mapGetOrDefault(map3, key, factory) {
|
|
120
|
-
let value = map3.get(key);
|
|
121
|
-
if (value !== void 0 || map3.has(key)) {
|
|
122
|
-
return value;
|
|
123
|
-
}
|
|
124
|
-
value = factory(key, map3);
|
|
125
|
-
map3.set(key, value);
|
|
126
|
-
return value;
|
|
127
|
-
}
|
|
128
|
-
__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
|
-
|
|
148
|
-
// src/mapLoad.ts
|
|
149
|
-
function mapLoad(ins, entries) {
|
|
150
|
-
for (const [key, value] of entries) {
|
|
151
|
-
ins.set(key, value);
|
|
152
|
-
}
|
|
153
|
-
return ins;
|
|
154
|
-
}
|
|
155
|
-
__name(mapLoad, "mapLoad");
|
|
156
|
-
|
|
157
|
-
// src/mapReverse.ts
|
|
158
|
-
function mapReverse(ins) {
|
|
159
|
-
const entries = Array.from(ins).reverse();
|
|
160
|
-
ins.clear();
|
|
161
|
-
mapLoad(ins, entries);
|
|
162
|
-
return ins;
|
|
163
|
-
}
|
|
164
|
-
__name(mapReverse, "mapReverse");
|
|
165
|
-
|
|
166
|
-
// src/mapUpdate.ts
|
|
167
|
-
function mapUpdate(ins, key, update) {
|
|
168
|
-
const newValue = update(ins.get(key), key, ins);
|
|
169
|
-
ins.set(key, newValue);
|
|
170
|
-
return ins;
|
|
171
|
-
}
|
|
172
|
-
__name(mapUpdate, "mapUpdate");
|
|
173
|
-
|
|
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
|
-
// src/sort.ts
|
|
185
|
-
function sort(ins, compare) {
|
|
186
|
-
const entries = Array.from(ins).sort(compare);
|
|
187
|
-
ins.clear();
|
|
188
|
-
for (const [k, v] of entries) {
|
|
189
|
-
ins.set(k, v);
|
|
190
|
-
}
|
|
191
|
-
return ins;
|
|
192
|
-
}
|
|
193
|
-
__name(sort, "sort");
|
|
194
|
-
|
|
195
|
-
// src/sortByKeys.ts
|
|
196
|
-
function sortByKeys(ins, compare) {
|
|
197
|
-
const entries = Array.from(ins).sort((a, b) => {
|
|
198
|
-
return compare(a[0], b[0]);
|
|
199
|
-
});
|
|
200
|
-
ins.clear();
|
|
201
|
-
for (const [k, v] of entries) {
|
|
202
|
-
ins.set(k, v);
|
|
203
|
-
}
|
|
204
|
-
return ins;
|
|
205
|
-
}
|
|
206
|
-
__name(sortByKeys, "sortByKeys");
|
|
207
|
-
|
|
208
|
-
// src/sortByValues.ts
|
|
209
|
-
function sortByValues(ins, compare) {
|
|
210
|
-
const entries = Array.from(ins).sort((a, b) => {
|
|
211
|
-
return compare(a[1], b[1]);
|
|
212
|
-
});
|
|
213
|
-
ins.clear();
|
|
214
|
-
for (const [k, v] of entries) {
|
|
215
|
-
ins.set(k, v);
|
|
216
|
-
}
|
|
217
|
-
return ins;
|
|
218
|
-
}
|
|
219
|
-
__name(sortByValues, "sortByValues");
|
|
220
|
-
|
|
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
|
-
// src/toMap.ts
|
|
245
|
-
function toMap(ins) {
|
|
246
|
-
return new Map(ins);
|
|
247
|
-
}
|
|
248
|
-
__name(toMap, "toMap");
|
|
249
|
-
|
|
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
|
-
// src/valuesArray.ts
|
|
274
|
-
function valuesArray(ins) {
|
|
275
|
-
return Array.from(ins.values());
|
|
276
|
-
}
|
|
277
|
-
__name(valuesArray, "valuesArray");
|
|
278
|
-
|
|
279
|
-
// src/ExtMap.ts
|
|
280
|
-
var ExtMap = class _ExtMap extends View {
|
|
281
|
-
static {
|
|
282
|
-
__name(this, "ExtMap");
|
|
283
|
-
}
|
|
284
|
-
constructor(arg) {
|
|
285
|
-
super(new Map(iterTools.isIterable(arg) ? arg : arg ? entriesOf(arg) : void 0));
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Creates a new ExtMap instance from a regular object.
|
|
289
|
-
*
|
|
290
|
-
* @param obj - An object whose key-value pairs will be used to initialize the map
|
|
291
|
-
* @returns A new ExtMap instance containing the entries from the object
|
|
292
|
-
*/
|
|
293
|
-
static fromObject(obj) {
|
|
294
|
-
return new _ExtMap(Object.entries(obj));
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Creates a new ExtMap instance from an iterable of key-value pairs.
|
|
298
|
-
*
|
|
299
|
-
* @param entries - An iterable of key-value pairs to initialize the map
|
|
300
|
-
* @returns A new ExtMap instance containing the provided entries
|
|
301
|
-
*/
|
|
302
|
-
static fromIterable(entries) {
|
|
303
|
-
return new _ExtMap(entries);
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* Creates a shallow copy of the map.
|
|
307
|
-
*
|
|
308
|
-
* @returns A new ExtMap instance with the same entries
|
|
309
|
-
*/
|
|
310
|
-
clone() {
|
|
311
|
-
return new _ExtMap(this);
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* Converts the map to a JSON-serializable format.
|
|
315
|
-
*
|
|
316
|
-
* @returns Array of key-value pairs suitable for JSON serialization
|
|
317
|
-
*/
|
|
318
|
-
toJSON() {
|
|
319
|
-
return [
|
|
320
|
-
...this.entries()
|
|
321
|
-
];
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
324
|
-
* Custom inspection method for better debugging output.
|
|
325
|
-
*
|
|
326
|
-
* @param _depth - The depth of inspection
|
|
327
|
-
* @param _options - Options for inspection
|
|
328
|
-
* @returns A string representation of the map
|
|
329
|
-
*/
|
|
330
|
-
[util.inspect.custom](_depth, _options) {
|
|
331
|
-
return util.inspect(this.target, {
|
|
332
|
-
breakLength: 50
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
};
|
|
336
|
-
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)));
|
|
354
|
-
function countUniques(input) {
|
|
355
|
-
return new ExtMap(iterTools.reduce(new mnemonist.MultiSet(), (acc, imp) => {
|
|
356
|
-
return acc.add(imp);
|
|
357
|
-
}, input).multiplicities()).sortByValues((a, b) => {
|
|
358
|
-
return b - a;
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
__name(countUniques, "countUniques");
|
|
362
|
-
|
|
363
|
-
exports.countUniques = countUniques;
|
package/lib/countUniques.d.cts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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 };
|
package/lib/countUniques.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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 };
|