@manta-eu/lib 0.1.1 → 0.1.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/dist/set.d.ts +1 -0
- package/dist/set.d.ts.map +1 -1
- package/dist/set.js +20 -0
- package/package.json +8 -16
package/dist/set.d.ts
CHANGED
package/dist/set.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"set.d.ts","sourceRoot":"","sources":["../src/set.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"set.d.ts","sourceRoot":"","sources":["../src/set.ts"],"names":[],"mappings":"AAEA,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,CAcnD;AAOD,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;AAC9D,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC"}
|
package/dist/set.js
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
// A Set that removes its oldest member to make room when it is full. Only its add method changes.
|
|
2
|
+
// A copy such as `new Set(bounded)` keeps the members but not the limit.
|
|
3
|
+
export function boundedSet(limit) {
|
|
4
|
+
if (!Number.isInteger(limit) || limit < 1) {
|
|
5
|
+
throw new RangeError(`A bounded set needs a whole limit of 1 or more, but it got ${limit}.`);
|
|
6
|
+
}
|
|
7
|
+
const set = new Set();
|
|
8
|
+
const nativeAdd = Set.prototype.add.bind(set);
|
|
9
|
+
set.add = (value) => {
|
|
10
|
+
if (!set.has(value) && set.size >= limit)
|
|
11
|
+
removeOldest(set);
|
|
12
|
+
return nativeAdd(value);
|
|
13
|
+
};
|
|
14
|
+
return set;
|
|
15
|
+
}
|
|
16
|
+
function removeOldest(set) {
|
|
17
|
+
const oldest = set.values().next();
|
|
18
|
+
if (!oldest.done)
|
|
19
|
+
set.delete(oldest.value);
|
|
20
|
+
}
|
|
1
21
|
export function addAll(set, items) {
|
|
2
22
|
if (Array.isArray(items)) {
|
|
3
23
|
items.forEach((item) => set.add(item));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manta-eu/lib",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Pure TypeScript helpers shared across the Manta packages",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -21,22 +21,14 @@
|
|
|
21
21
|
"ramda": "^0.32.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@tanstack/react-query": "^5.100.10",
|
|
25
|
-
"@types/node": "^20.0.0",
|
|
26
24
|
"@types/pluralize": "^0.0.33",
|
|
27
25
|
"@types/ramda": "^0.31.1",
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"@vitest/coverage-v8": "^3.2.4",
|
|
32
|
-
"eslint": "^9.0.0",
|
|
33
|
-
"prettier": "^3.6.2",
|
|
34
|
-
"react": "^19.2.3",
|
|
35
|
-
"sonner": "^1.7.4",
|
|
26
|
+
"eslint": "^9.39.2",
|
|
27
|
+
"prettier": "^3.8.1",
|
|
28
|
+
"rimraf": "^6.1.3",
|
|
36
29
|
"tsc-alias": "^1.9.5",
|
|
37
|
-
"typescript": "^5.
|
|
38
|
-
"
|
|
39
|
-
"vitest": "^3.0.0",
|
|
30
|
+
"typescript": "^5.9.3",
|
|
31
|
+
"vitest": "^4.1.8",
|
|
40
32
|
"@manta-eu/eslint-config": "0.1.0"
|
|
41
33
|
},
|
|
42
34
|
"prettier": {
|
|
@@ -59,8 +51,8 @@
|
|
|
59
51
|
"access": "public"
|
|
60
52
|
},
|
|
61
53
|
"scripts": {
|
|
62
|
-
"build": "
|
|
63
|
-
"build:lib": "
|
|
54
|
+
"build": "rimraf dist && tsc --project tsconfig.build.json && tsc-alias --project tsconfig.build.json --resolve-full-paths",
|
|
55
|
+
"build:lib": "rimraf dist && tsc --project tsconfig.build.json",
|
|
64
56
|
"test": "vitest --run",
|
|
65
57
|
"test:watch": "vitest --watch",
|
|
66
58
|
"check": "vitest --run",
|