@lowentry/utils 1.17.1 → 1.19.1
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/api-extractor.json +40 -0
- package/build/LeTypes.d.ts +15 -0
- package/build/LeUtils.d.ts +218 -0
- package/build/classes/LinkedList.d.ts +33 -0
- package/build/classes/SerializableMap.d.ts +17 -0
- package/build/index.d.ts +4 -0
- package/index.d.ts +301 -0
- package/index.js +169 -2
- package/index.js.map +1 -1
- package/package.json +7 -6
- package/src/LeUtils.js +1 -1
- package/src/classes/LinkedList.js +145 -0
- package/src/classes/SerializableMap.js +17 -0
- package/src/index.js +2 -0
- package/tests/each.test.js +3 -5
- package/tests/sort.test.js +1 -1
- package/tsconfig.d.ts +1 -3
- package/tsconfig.json +15 -3
- package/jest.config.mjs +0 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowentry/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"scripts": {
|
|
21
21
|
"build": "npm exec -- rollup -c",
|
|
22
22
|
"prepublishOnly": "rm -r src && mv dist/* ./ && rm -r dist",
|
|
23
|
-
"test": "npx tsc &&
|
|
23
|
+
"test": "npx tsc && vitest run"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@babel/runtime": "*",
|
|
@@ -37,20 +37,21 @@
|
|
|
37
37
|
"@babel/plugin-transform-runtime": "^7.24.7",
|
|
38
38
|
"@babel/preset-env": "^7.24.7",
|
|
39
39
|
"@babel/preset-react": "^7.24.7",
|
|
40
|
+
"@microsoft/api-extractor": "^7.52.8",
|
|
41
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
40
42
|
"@rollup/plugin-commonjs": "^26.0.1",
|
|
41
43
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
42
44
|
"@rollup/plugin-url": "^8.0.2",
|
|
43
45
|
"autoprefixer": "^10.4.19",
|
|
44
46
|
"cssnano": "^7.0.2",
|
|
45
47
|
"fs-extra": "^11.2.0",
|
|
46
|
-
"jest": "^30.0.3",
|
|
47
48
|
"less": "^4.2.0",
|
|
48
49
|
"rollup": "^2.79.1",
|
|
49
|
-
"rollup-plugin-
|
|
50
|
+
"rollup-plugin-execute": "^1.1.1",
|
|
50
51
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
51
52
|
"rollup-plugin-postcss": "^4.0.2",
|
|
52
53
|
"sass": "^1.77.5",
|
|
53
|
-
"
|
|
54
|
-
"
|
|
54
|
+
"typescript": "^5.8.3",
|
|
55
|
+
"vitest": "^3.2.4"
|
|
55
56
|
}
|
|
56
57
|
}
|
package/src/LeUtils.js
CHANGED
|
@@ -593,7 +593,7 @@ export const LeUtils = {
|
|
|
593
593
|
*
|
|
594
594
|
* @param {*} elements
|
|
595
595
|
* @param {boolean} [optionalSkipHasOwnPropertyCheck]
|
|
596
|
-
* @
|
|
596
|
+
* @yields {[key:*, value:*]}
|
|
597
597
|
*/
|
|
598
598
|
eachIterator:
|
|
599
599
|
function* (elements, optionalSkipHasOwnPropertyCheck = false)
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
class LinkedListNode
|
|
2
|
+
{
|
|
3
|
+
/** @type {*} */
|
|
4
|
+
value;
|
|
5
|
+
|
|
6
|
+
/** @type {LinkedListNode|null} */
|
|
7
|
+
next = null;
|
|
8
|
+
|
|
9
|
+
/** @type {LinkedListNode|null} */
|
|
10
|
+
previous = null;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {*} value
|
|
14
|
+
*/
|
|
15
|
+
constructor(value)
|
|
16
|
+
{
|
|
17
|
+
this.value = value;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class LinkedList
|
|
22
|
+
{
|
|
23
|
+
/** @type {LinkedListNode|null} */
|
|
24
|
+
#head = null;
|
|
25
|
+
|
|
26
|
+
/** @type {LinkedListNode|null} */
|
|
27
|
+
#tail = null;
|
|
28
|
+
|
|
29
|
+
/** @type {number} */
|
|
30
|
+
#size = 0;
|
|
31
|
+
|
|
32
|
+
constructor()
|
|
33
|
+
{
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Returns the number of elements in the list.
|
|
38
|
+
*
|
|
39
|
+
* @returns {number}
|
|
40
|
+
*/
|
|
41
|
+
get size()
|
|
42
|
+
{
|
|
43
|
+
return this.#size;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Adds a new value to the beginning of the list.
|
|
48
|
+
*
|
|
49
|
+
* @param {*} value
|
|
50
|
+
*/
|
|
51
|
+
unshift(value)
|
|
52
|
+
{
|
|
53
|
+
const newNode = new LinkedListNode(value);
|
|
54
|
+
if(this.#head === null)
|
|
55
|
+
{
|
|
56
|
+
this.#head = newNode;
|
|
57
|
+
this.#tail = newNode;
|
|
58
|
+
}
|
|
59
|
+
else
|
|
60
|
+
{
|
|
61
|
+
newNode.next = this.#head;
|
|
62
|
+
this.#head.previous = newNode;
|
|
63
|
+
this.#head = newNode;
|
|
64
|
+
}
|
|
65
|
+
this.#size++;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Adds a new value to the end of the list.
|
|
70
|
+
*
|
|
71
|
+
* @param {*} value
|
|
72
|
+
*/
|
|
73
|
+
push(value)
|
|
74
|
+
{
|
|
75
|
+
const newNode = new LinkedListNode(value);
|
|
76
|
+
if(this.#tail === null)
|
|
77
|
+
{
|
|
78
|
+
this.#head = newNode;
|
|
79
|
+
this.#tail = newNode;
|
|
80
|
+
}
|
|
81
|
+
else
|
|
82
|
+
{
|
|
83
|
+
newNode.previous = this.#tail;
|
|
84
|
+
this.#tail.next = newNode;
|
|
85
|
+
this.#tail = newNode;
|
|
86
|
+
}
|
|
87
|
+
this.#size++;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Removes the first value from the list and returns it.
|
|
92
|
+
*
|
|
93
|
+
* @returns {*|undefined}
|
|
94
|
+
*/
|
|
95
|
+
shift()
|
|
96
|
+
{
|
|
97
|
+
if(this.#head === null)
|
|
98
|
+
{
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const value = this.#head.value;
|
|
103
|
+
this.#head = this.#head.next;
|
|
104
|
+
|
|
105
|
+
if(this.#head !== null)
|
|
106
|
+
{
|
|
107
|
+
this.#head.previous = null;
|
|
108
|
+
}
|
|
109
|
+
else
|
|
110
|
+
{
|
|
111
|
+
this.#tail = null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
this.#size--;
|
|
115
|
+
return value;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Removes the last value from the list and returns it.
|
|
120
|
+
*
|
|
121
|
+
* @returns {*|undefined}
|
|
122
|
+
*/
|
|
123
|
+
pop()
|
|
124
|
+
{
|
|
125
|
+
if(this.#tail === null)
|
|
126
|
+
{
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const value = this.#tail.value;
|
|
131
|
+
this.#tail = this.#tail.previous;
|
|
132
|
+
|
|
133
|
+
if(this.#tail !== null)
|
|
134
|
+
{
|
|
135
|
+
this.#tail.next = null;
|
|
136
|
+
}
|
|
137
|
+
else
|
|
138
|
+
{
|
|
139
|
+
this.#head = null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
this.#size--;
|
|
143
|
+
return value;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SerializableMap class extends the native Map to provide a JSON representation.
|
|
3
|
+
*
|
|
4
|
+
* This class can only have string keys, as JSON does not support non-string keys.
|
|
5
|
+
*/
|
|
6
|
+
export class SerializableMap extends Map
|
|
7
|
+
{
|
|
8
|
+
/**
|
|
9
|
+
* Returns a JSON representation of the map.
|
|
10
|
+
*
|
|
11
|
+
* @returns {object}
|
|
12
|
+
*/
|
|
13
|
+
toJSON()
|
|
14
|
+
{
|
|
15
|
+
return Object.fromEntries(this);
|
|
16
|
+
}
|
|
17
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export {LeUtils} from './LeUtils.js';
|
|
2
2
|
export {ISSET, IS_ARRAY, ARRAY, IS_OBJECT, OBJECT, STRING, STRING_ANY, INT, INT_ANY, FLOAT, FLOAT_ANY, INT_LAX, INT_LAX_ANY, FLOAT_LAX, FLOAT_LAX_ANY} from './LeTypes.js';
|
|
3
|
+
export {LinkedList} from './classes/LinkedList.js';
|
|
4
|
+
export {SerializableMap} from './classes/SerializableMap.js';
|
package/tests/each.test.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {describe, test, expect
|
|
1
|
+
import {describe, test, expect} from 'vitest';
|
|
2
2
|
import {LeUtils} from '../src/index.js';
|
|
3
3
|
|
|
4
4
|
const wait = ms => LeUtils.promiseTimeout(ms ?? 100);
|
|
@@ -433,7 +433,6 @@ describe('LeUtils.supportsEach() custom forEach object and function', () =>
|
|
|
433
433
|
|
|
434
434
|
describe('LeUtils.eachAsync() heavy parallel', () =>
|
|
435
435
|
{
|
|
436
|
-
jest.setTimeout(10000);
|
|
437
436
|
test('processes 100 items with concurrency 20', async () =>
|
|
438
437
|
{
|
|
439
438
|
const size = 100;
|
|
@@ -453,7 +452,7 @@ describe('LeUtils.eachAsync() heavy parallel', () =>
|
|
|
453
452
|
);
|
|
454
453
|
expect(max.length).toBe(size);
|
|
455
454
|
expect(Math.max(...max)).toBeLessThanOrEqual(20);
|
|
456
|
-
});
|
|
455
|
+
}, 10000);
|
|
457
456
|
test('serial path matches sequential order with strings', async () =>
|
|
458
457
|
{
|
|
459
458
|
const seen = [];
|
|
@@ -639,7 +638,6 @@ describe('LeUtils.getEmptySimplifiedCollection() extra', () =>
|
|
|
639
638
|
|
|
640
639
|
describe('LeUtils.eachAsync() stress 1000 items', () =>
|
|
641
640
|
{
|
|
642
|
-
jest.setTimeout(20000);
|
|
643
641
|
test('parallel 200 completes', async () =>
|
|
644
642
|
{
|
|
645
643
|
const N = 1000;
|
|
@@ -651,7 +649,7 @@ describe('LeUtils.eachAsync() stress 1000 items', () =>
|
|
|
651
649
|
await wait();
|
|
652
650
|
}, 200);
|
|
653
651
|
expect(count).toBe(N);
|
|
654
|
-
});
|
|
652
|
+
}, 20000);
|
|
655
653
|
test('early false stops further enqueues', async () =>
|
|
656
654
|
{
|
|
657
655
|
const list = [...Array(50).keys()];
|
package/tests/sort.test.js
CHANGED
package/tsconfig.d.ts
CHANGED
package/tsconfig.json
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
"allowJs": true,
|
|
4
4
|
"checkJs": true,
|
|
5
5
|
"strict": true,
|
|
6
|
-
"noEmit": true,
|
|
7
6
|
"noImplicitAny": false,
|
|
8
7
|
"noImplicitThis": false,
|
|
9
8
|
"alwaysStrict": true,
|
|
@@ -15,7 +14,14 @@
|
|
|
15
14
|
"module": "esnext",
|
|
16
15
|
"moduleResolution": "node",
|
|
17
16
|
"skipLibCheck": true,
|
|
18
|
-
"types": []
|
|
17
|
+
"types": [],
|
|
18
|
+
"noEmit": false,
|
|
19
|
+
"declaration": true,
|
|
20
|
+
"declarationMap": false,
|
|
21
|
+
"outDir": "./build",
|
|
22
|
+
"removeComments": false,
|
|
23
|
+
"stripInternal": true,
|
|
24
|
+
"emitDeclarationOnly": true
|
|
19
25
|
},
|
|
20
26
|
"include": [
|
|
21
27
|
"tsconfig.d.ts",
|
|
@@ -23,5 +29,11 @@
|
|
|
23
29
|
],
|
|
24
30
|
"exclude": [
|
|
25
31
|
"node_modules"
|
|
26
|
-
]
|
|
32
|
+
],
|
|
33
|
+
"typeAcquisition": {
|
|
34
|
+
"include": [
|
|
35
|
+
"react",
|
|
36
|
+
"react-dom"
|
|
37
|
+
]
|
|
38
|
+
}
|
|
27
39
|
}
|
package/jest.config.mjs
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
preset: 'ts-jest/presets/js-with-ts-esm',
|
|
3
|
-
globals: {
|
|
4
|
-
extensionsToTreatAsEsm:['.ts', '.js', '.mjs', '.mjsx'],
|
|
5
|
-
},
|
|
6
|
-
transform: {
|
|
7
|
-
'^.+\\.[tj]sx?$|^.+\\.mjsx?$':['ts-jest', {useESM:true}],
|
|
8
|
-
},
|
|
9
|
-
moduleFileExtensions:['ts', 'tsx', 'js', 'jsx', 'mjs', 'mjsx', 'json', 'node'],
|
|
10
|
-
};
|