@wener/utils 1.1.54 → 1.1.58
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/lib/arrays/arrayFromAsync.js +11 -3
- package/lib/asyncs/AsyncInterval.js +11 -3
- package/lib/asyncs/Promises.js +6 -5
- package/lib/asyncs/createAsyncIterator.js +11 -3
- package/lib/asyncs/createLazyPromise.test.js +11 -3
- package/lib/asyncs/generatorOfStream.js +11 -3
- package/lib/browsers/download.js +11 -3
- package/lib/browsers/getFileFromDataTransfer.js +2 -2
- package/lib/browsers/loaders.js +11 -3
- package/lib/crypto/hashing.js +11 -3
- package/lib/crypto/hashing.test.js +11 -3
- package/lib/crypto/pem/pem.js +1 -1
- package/lib/crypto/randomUUIDv7.js +63 -0
- package/lib/crypto/randomUUIDv7.test.js +79 -0
- package/lib/fetch/createFetchWith.js +12 -4
- package/lib/fetch/dumpRequest.js +12 -4
- package/lib/fetch/dumpRequest.test.js +11 -3
- package/lib/fetch/dumpResponse.js +11 -3
- package/lib/fetch/dumpResponse.test.js +11 -3
- package/lib/index.js +2 -1
- package/lib/io/ArrayBuffers.js +2 -2
- package/lib/io/ByteBuffer.test.js +11 -3
- package/lib/io/dump.js +1 -1
- package/lib/io/parseDataUri.js +11 -3
- package/lib/io/parseDataUri.test.js +31 -11
- package/lib/langs/AsyncCloser.js +11 -3
- package/lib/langs/deepFreeze.js +5 -5
- package/lib/langs/mixin.js +6 -12
- package/lib/langs/mixin.test.js +50 -5
- package/lib/langs/mixin2.js +26 -0
- package/lib/langs/parseBoolean.js +3 -2
- package/lib/langs/shallowEqual.js +5 -5
- package/lib/libs/ms.js +1 -1
- package/lib/maths/clamp.js +5 -84
- package/lib/maths/clamp.test.js +33 -35
- package/lib/maths/createRandom.test.js +271 -29
- package/lib/maths/random.js +176 -154
- package/lib/objects/merge/isMergeableObject.js +1 -1
- package/lib/objects/merge/merge.js +1 -1
- package/lib/objects/merge/merge.test.js +11 -3
- package/lib/objects/set.js +10 -2
- package/lib/objects/set.test.js +2 -2
- package/lib/scripts/getGenerateContext.js +13 -5
- package/lib/server/fetch/createFetchWithProxyByNodeFetch.js +11 -3
- package/lib/server/fetch/createFetchWithProxyByUndici.js +11 -3
- package/lib/server/polyfill/polyfillBrowser.js +11 -3
- package/lib/server/polyfill/polyfillBrowser.test.js +11 -3
- package/lib/server/polyfill/polyfillCrypto.js +11 -3
- package/lib/server/polyfill/polyfillJsDom.js +31 -11
- package/lib/strings/renderTemplate.test.js +2 -2
- package/lib/web/getGlobalThis.js +0 -2
- package/lib/web/getRandomValues.js +5 -11
- package/lib/web/structuredClone.js +2 -2
- package/package.json +10 -6
- package/src/asyncs/Promises.ts +2 -1
- package/src/asyncs/timeout.ts +1 -1
- package/src/crypto/hashing.ts +7 -6
- package/src/crypto/pem/pem.ts +3 -2
- package/src/crypto/randomUUIDv7.test.ts +82 -0
- package/src/crypto/randomUUIDv7.ts +79 -0
- package/src/fetch/dumpRequest.ts +1 -1
- package/src/index.ts +9 -2
- package/src/langs/mixin.test.ts +32 -5
- package/src/langs/mixin.ts +46 -65
- package/src/langs/mixin2.ts +80 -0
- package/src/langs/parseBoolean.ts +18 -1
- package/src/maths/clamp.test.ts +12 -9
- package/src/maths/clamp.ts +10 -16
- package/src/maths/createRandom.test.ts +199 -11
- package/src/maths/random.ts +190 -33
- package/src/objects/set.ts +10 -1
- package/src/types.d.ts +1 -1
- package/src/web/getGlobalThis.ts +1 -2
- package/src/web/getRandomValues.ts +14 -15
- package/tsconfig.json +6 -12
- package/src/schema/README.md +0 -2
|
@@ -70,9 +70,17 @@ function _ts_generator(thisArg, body) {
|
|
|
70
70
|
},
|
|
71
71
|
trys: [],
|
|
72
72
|
ops: []
|
|
73
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
74
|
-
return
|
|
75
|
-
|
|
73
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
74
|
+
return d(g, "next", {
|
|
75
|
+
value: verb(0)
|
|
76
|
+
}), d(g, "throw", {
|
|
77
|
+
value: verb(1)
|
|
78
|
+
}), d(g, "return", {
|
|
79
|
+
value: verb(2)
|
|
80
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
81
|
+
value: function () {
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
76
84
|
}), g;
|
|
77
85
|
function verb(n) {
|
|
78
86
|
return function (v) {
|
package/lib/objects/set.js
CHANGED
|
@@ -16,11 +16,19 @@ import { parseObjectPath } from "./parseObjectPath.js";
|
|
|
16
16
|
var x, k;
|
|
17
17
|
while (i < len) {
|
|
18
18
|
k = path[i++];
|
|
19
|
+
// Security: Prevent prototype pollution
|
|
19
20
|
if (k === "__proto__" || k === "constructor" || k === "prototype")
|
|
20
21
|
break;
|
|
21
22
|
// noinspection PointlessArithmeticExpressionJS
|
|
22
|
-
current = current[k] = i === len ? merging ? merge(current[k], val) : val : _type_of(x = current[k]) === (typeof path === "undefined" ? "undefined" : _type_of(path)) ? x :
|
|
23
|
-
|
|
23
|
+
current = current[k] = i === len ? merging ? merge(current[k], val) : val : _type_of(x = current[k]) === (typeof path === "undefined" ? "undefined" : _type_of(path)) ? x : // If the next key is NOT an integer-like index, or contains a dot, create an Object.
|
|
24
|
+
// Otherwise, create an Array.
|
|
25
|
+
//
|
|
26
|
+
// path[i] * 0 !== 0 checks if it is NOT a number (NaN * 0 is NaN).
|
|
27
|
+
// !!~('' + path[i]).indexOf('.') checks if it contains a dot.
|
|
28
|
+
//
|
|
29
|
+
// @ts-expect-error hacky type check from dset
|
|
30
|
+
path[i] * 0 !== 0 || !!~("" + path[i]).indexOf(".") // eslint-disable-line
|
|
31
|
+
? {} : [];
|
|
24
32
|
}
|
|
25
33
|
}
|
|
26
34
|
export function merge(a, b) {
|
package/lib/objects/set.test.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
function _instanceof(left, right) {
|
|
2
2
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
3
3
|
return !!right[Symbol.hasInstance](left);
|
|
4
4
|
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
return left instanceof right;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
import { describe, expect, it, test } from "vitest";
|
|
9
|
+
/* eslint no-proto:0 no-prototype-builtins:0 */ import { describe, expect, it, test } from "vitest";
|
|
10
10
|
import { set } from "./set.js";
|
|
11
11
|
test("set basics", function () {
|
|
12
12
|
expect(set({}, "c", 3), "should not give return value").toBe(undefined);
|
|
@@ -93,9 +93,17 @@ function _ts_generator(thisArg, body) {
|
|
|
93
93
|
},
|
|
94
94
|
trys: [],
|
|
95
95
|
ops: []
|
|
96
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
97
|
-
return
|
|
98
|
-
|
|
96
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
97
|
+
return d(g, "next", {
|
|
98
|
+
value: verb(0)
|
|
99
|
+
}), d(g, "throw", {
|
|
100
|
+
value: verb(1)
|
|
101
|
+
}), d(g, "return", {
|
|
102
|
+
value: verb(2)
|
|
103
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
104
|
+
value: function () {
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
99
107
|
}), g;
|
|
100
108
|
function verb(n) {
|
|
101
109
|
return function (v) {
|
|
@@ -347,7 +355,7 @@ export function getGenerateContext(prefix) {
|
|
|
347
355
|
}
|
|
348
356
|
function write(dir, file, content) {
|
|
349
357
|
return _async_to_generator(function () {
|
|
350
|
-
var size, dst, last,
|
|
358
|
+
var size, dst, last, unused;
|
|
351
359
|
return _ts_generator(this, function (_state) {
|
|
352
360
|
switch (_state.label) {
|
|
353
361
|
case 0:
|
|
@@ -374,7 +382,7 @@ function write(dir, file, content) {
|
|
|
374
382
|
4
|
|
375
383
|
];
|
|
376
384
|
case 3:
|
|
377
|
-
|
|
385
|
+
unused = _state.sent();
|
|
378
386
|
return [
|
|
379
387
|
3,
|
|
380
388
|
4
|
|
@@ -101,9 +101,17 @@ function _ts_generator(thisArg, body) {
|
|
|
101
101
|
},
|
|
102
102
|
trys: [],
|
|
103
103
|
ops: []
|
|
104
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
105
|
-
return
|
|
106
|
-
|
|
104
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
105
|
+
return d(g, "next", {
|
|
106
|
+
value: verb(0)
|
|
107
|
+
}), d(g, "throw", {
|
|
108
|
+
value: verb(1)
|
|
109
|
+
}), d(g, "return", {
|
|
110
|
+
value: verb(2)
|
|
111
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
112
|
+
value: function () {
|
|
113
|
+
return this;
|
|
114
|
+
}
|
|
107
115
|
}), g;
|
|
108
116
|
function verb(n) {
|
|
109
117
|
return function (v) {
|
|
@@ -139,9 +139,17 @@ function _ts_generator(thisArg, body) {
|
|
|
139
139
|
},
|
|
140
140
|
trys: [],
|
|
141
141
|
ops: []
|
|
142
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
143
|
-
return
|
|
144
|
-
|
|
142
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
143
|
+
return d(g, "next", {
|
|
144
|
+
value: verb(0)
|
|
145
|
+
}), d(g, "throw", {
|
|
146
|
+
value: verb(1)
|
|
147
|
+
}), d(g, "return", {
|
|
148
|
+
value: verb(2)
|
|
149
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
150
|
+
value: function () {
|
|
151
|
+
return this;
|
|
152
|
+
}
|
|
145
153
|
}), g;
|
|
146
154
|
function verb(n) {
|
|
147
155
|
return function (v) {
|
|
@@ -39,9 +39,17 @@ function _ts_generator(thisArg, body) {
|
|
|
39
39
|
},
|
|
40
40
|
trys: [],
|
|
41
41
|
ops: []
|
|
42
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
43
|
-
return
|
|
44
|
-
|
|
42
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
43
|
+
return d(g, "next", {
|
|
44
|
+
value: verb(0)
|
|
45
|
+
}), d(g, "throw", {
|
|
46
|
+
value: verb(1)
|
|
47
|
+
}), d(g, "return", {
|
|
48
|
+
value: verb(2)
|
|
49
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
50
|
+
value: function () {
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
45
53
|
}), g;
|
|
46
54
|
function verb(n) {
|
|
47
55
|
return function (v) {
|
|
@@ -39,9 +39,17 @@ function _ts_generator(thisArg, body) {
|
|
|
39
39
|
},
|
|
40
40
|
trys: [],
|
|
41
41
|
ops: []
|
|
42
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
43
|
-
return
|
|
44
|
-
|
|
42
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
43
|
+
return d(g, "next", {
|
|
44
|
+
value: verb(0)
|
|
45
|
+
}), d(g, "throw", {
|
|
46
|
+
value: verb(1)
|
|
47
|
+
}), d(g, "return", {
|
|
48
|
+
value: verb(2)
|
|
49
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
50
|
+
value: function () {
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
45
53
|
}), g;
|
|
46
54
|
function verb(n) {
|
|
47
55
|
return function (v) {
|
|
@@ -39,9 +39,17 @@ function _ts_generator(thisArg, body) {
|
|
|
39
39
|
},
|
|
40
40
|
trys: [],
|
|
41
41
|
ops: []
|
|
42
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
43
|
-
return
|
|
44
|
-
|
|
42
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
43
|
+
return d(g, "next", {
|
|
44
|
+
value: verb(0)
|
|
45
|
+
}), d(g, "throw", {
|
|
46
|
+
value: verb(1)
|
|
47
|
+
}), d(g, "return", {
|
|
48
|
+
value: verb(2)
|
|
49
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
50
|
+
value: function () {
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
45
53
|
}), g;
|
|
46
54
|
function verb(n) {
|
|
47
55
|
return function (v) {
|
|
@@ -37,12 +37,24 @@ function _class_call_check(instance, Constructor) {
|
|
|
37
37
|
function _object_without_properties(source, excluded) {
|
|
38
38
|
if (source == null)
|
|
39
39
|
return {};
|
|
40
|
-
var target =
|
|
41
|
-
|
|
40
|
+
var target = {}, sourceKeys, key, i;
|
|
41
|
+
if (typeof Reflect !== "undefined" && Reflect.ownKeys) {
|
|
42
|
+
sourceKeys = Reflect.ownKeys(source);
|
|
43
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
44
|
+
key = sourceKeys[i];
|
|
45
|
+
if (excluded.indexOf(key) >= 0)
|
|
46
|
+
continue;
|
|
47
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key))
|
|
48
|
+
continue;
|
|
49
|
+
target[key] = source[key];
|
|
50
|
+
}
|
|
51
|
+
return target;
|
|
52
|
+
}
|
|
53
|
+
target = _object_without_properties_loose(source, excluded);
|
|
42
54
|
if (Object.getOwnPropertySymbols) {
|
|
43
|
-
|
|
44
|
-
for (i = 0; i <
|
|
45
|
-
key =
|
|
55
|
+
sourceKeys = Object.getOwnPropertySymbols(source);
|
|
56
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
57
|
+
key = sourceKeys[i];
|
|
46
58
|
if (excluded.indexOf(key) >= 0)
|
|
47
59
|
continue;
|
|
48
60
|
if (!Object.prototype.propertyIsEnumerable.call(source, key))
|
|
@@ -55,13 +67,13 @@ function _object_without_properties(source, excluded) {
|
|
|
55
67
|
function _object_without_properties_loose(source, excluded) {
|
|
56
68
|
if (source == null)
|
|
57
69
|
return {};
|
|
58
|
-
var target = {};
|
|
59
|
-
var sourceKeys = Object.keys(source);
|
|
60
|
-
var key, i;
|
|
70
|
+
var target = {}, sourceKeys = Object.getOwnPropertyNames(source), key, i;
|
|
61
71
|
for (i = 0; i < sourceKeys.length; i++) {
|
|
62
72
|
key = sourceKeys[i];
|
|
63
73
|
if (excluded.indexOf(key) >= 0)
|
|
64
74
|
continue;
|
|
75
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key))
|
|
76
|
+
continue;
|
|
65
77
|
target[key] = source[key];
|
|
66
78
|
}
|
|
67
79
|
return target;
|
|
@@ -76,9 +88,17 @@ function _ts_generator(thisArg, body) {
|
|
|
76
88
|
},
|
|
77
89
|
trys: [],
|
|
78
90
|
ops: []
|
|
79
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
80
|
-
return
|
|
81
|
-
|
|
91
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
92
|
+
return d(g, "next", {
|
|
93
|
+
value: verb(0)
|
|
94
|
+
}), d(g, "throw", {
|
|
95
|
+
value: verb(1)
|
|
96
|
+
}), d(g, "return", {
|
|
97
|
+
value: verb(2)
|
|
98
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
99
|
+
value: function () {
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
82
102
|
}), g;
|
|
83
103
|
function verb(n) {
|
|
84
104
|
return function (v) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
2
|
if (len == null || len > arr.length)
|
|
3
3
|
len = arr.length;
|
|
4
4
|
for (var i = 0, arr2 = new Array(len); i < len; i++)
|
|
@@ -59,7 +59,7 @@ function _unsupported_iterable_to_array(o, minLen) {
|
|
|
59
59
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
|
|
60
60
|
return _array_like_to_array(o, minLen);
|
|
61
61
|
}
|
|
62
|
-
import { expect, test } from "vitest";
|
|
62
|
+
/* eslint no-template-curly-in-string:0 */ import { expect, test } from "vitest";
|
|
63
63
|
import { renderTemplate } from "./renderTemplate.js";
|
|
64
64
|
test("renderTemplate", function () {
|
|
65
65
|
var obj = {
|
package/lib/web/getGlobalThis.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
var _this = this;
|
|
2
1
|
/**
|
|
3
2
|
* isomorphic globalThis
|
|
4
3
|
*
|
|
@@ -13,6 +12,5 @@ var _this = this;
|
|
|
13
12
|
if (typeof self !== 'undefined') return self;
|
|
14
13
|
if (typeof window !== 'undefined') return window;
|
|
15
14
|
if (typeof global !== 'undefined') return global;
|
|
16
|
-
if (typeof _this !== 'undefined') return _this;
|
|
17
15
|
throw new Error('Unable to locate global `this`');
|
|
18
16
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
|
|
2
1
|
function _instanceof(left, right) {
|
|
3
2
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
4
3
|
return !!right[Symbol.hasInstance](left);
|
|
@@ -10,29 +9,24 @@ function _instanceof(left, right) {
|
|
|
10
9
|
var _globalThis_crypto_getRandomValues, _globalThis_crypto, _globalThis_msCrypto_getRandomValues, _globalThis_msCrypto;
|
|
11
10
|
import { getNodeCrypto } from "../crypto/getNodeCrypto.js";
|
|
12
11
|
import { getGlobalThis } from "./getGlobalThis.js";
|
|
13
|
-
var
|
|
12
|
+
var _globalThis = getGlobalThis();
|
|
14
13
|
// chrome 11+, safari 5+, nodejs 17.4+
|
|
15
14
|
// https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
|
|
16
|
-
export var getRandomValues = ((_globalThis_crypto =
|
|
17
|
-
throw new Error("[getRandomValues]: No secure random number generator available.");
|
|
18
|
-
};
|
|
15
|
+
export var getRandomValues = ((_globalThis_crypto = _globalThis.crypto) === null || _globalThis_crypto === void 0 ? void 0 : (_globalThis_crypto_getRandomValues = _globalThis_crypto.getRandomValues) === null || _globalThis_crypto_getRandomValues === void 0 ? void 0 : _globalThis_crypto_getRandomValues.bind(_globalThis.crypto)) || ((_globalThis_msCrypto = _globalThis.msCrypto) === null || _globalThis_msCrypto === void 0 ? void 0 : (_globalThis_msCrypto_getRandomValues = _globalThis_msCrypto.getRandomValues) === null || _globalThis_msCrypto_getRandomValues === void 0 ? void 0 : _globalThis_msCrypto_getRandomValues.bind(_globalThis.msCrypto)) || _getRandomValues;
|
|
19
16
|
function _getRandomValues(buf) {
|
|
20
17
|
var nodeCrypto = getNodeCrypto();
|
|
21
|
-
// avoid type error
|
|
22
18
|
var wc = nodeCrypto === null || nodeCrypto === void 0 ? void 0 : nodeCrypto.webcrypto;
|
|
23
19
|
if (wc === null || wc === void 0 ? void 0 : wc.getRandomValues) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return wc.getRandomValues(buf);
|
|
20
|
+
getRandomValues = wc.getRandomValues.bind(wc);
|
|
21
|
+
return getRandomValues(buf);
|
|
27
22
|
}
|
|
28
23
|
if (nodeCrypto === null || nodeCrypto === void 0 ? void 0 : nodeCrypto.randomBytes) {
|
|
29
24
|
if (!_instanceof(buf, Uint8Array)) {
|
|
30
25
|
throw new TypeError("expected Uint8Array");
|
|
31
26
|
}
|
|
32
27
|
if (buf.length > 65536) {
|
|
33
|
-
var e = new Error();
|
|
28
|
+
var e = new Error("Failed to execute 'getRandomValues' on 'Crypto': The ArrayBufferView's byte length (".concat(buf.length, ") exceeds the number of bytes of entropy available via this API (65536)."));
|
|
34
29
|
e.code = 22;
|
|
35
|
-
e.message = "Failed to execute 'getRandomValues' on 'Crypto': The ArrayBufferView's byte length (".concat(buf.length, ") exceeds the number of bytes of entropy available via this API (65536).");
|
|
36
30
|
e.name = "QuotaExceededError";
|
|
37
31
|
throw e;
|
|
38
32
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
function _type_of(obj) {
|
|
2
2
|
"@swc/helpers - typeof";
|
|
3
3
|
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
4
4
|
}
|
|
5
|
-
import { classOf } from "../langs/classOf.js";
|
|
5
|
+
/* eslint no-proto:0 */ import { classOf } from "../langs/classOf.js";
|
|
6
6
|
/**
|
|
7
7
|
* Clone an object using structured cloning algorithm
|
|
8
8
|
*
|
package/package.json
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wener/utils",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.58",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Utils for daily use",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "
|
|
8
|
+
"url": "https://github.com/wenerme/wener.git",
|
|
9
|
+
"directory": "packages/wener-utils"
|
|
9
10
|
},
|
|
10
|
-
"homepage": "https://github.com/wenerme/
|
|
11
|
+
"homepage": "https://github.com/wenerme/wener/tree/main/packages/wener-utils",
|
|
11
12
|
"author": "wener",
|
|
12
13
|
"license": "MIT",
|
|
14
|
+
"imports": {
|
|
15
|
+
"#/*": "./src/*"
|
|
16
|
+
},
|
|
13
17
|
"exports": {
|
|
14
18
|
".": {
|
|
15
19
|
"types": "./src/index.ts",
|
|
@@ -65,12 +69,12 @@
|
|
|
65
69
|
"lodash"
|
|
66
70
|
],
|
|
67
71
|
"devDependencies": {
|
|
68
|
-
"@sinclair/typebox": "^0.34.
|
|
72
|
+
"@sinclair/typebox": "^0.34.47",
|
|
69
73
|
"@types/ws": "^8.18.1",
|
|
70
74
|
"https-proxy-agent": "^7.0.6",
|
|
71
75
|
"node-fetch": "^3.3.2",
|
|
72
|
-
"undici": "^7.
|
|
73
|
-
"zod": "^4.
|
|
76
|
+
"undici": "^7.18.2",
|
|
77
|
+
"zod": "^4.3.5"
|
|
74
78
|
},
|
|
75
79
|
"publishConfig": {
|
|
76
80
|
"registry": "https://registry.npmjs.org",
|
package/src/asyncs/Promises.ts
CHANGED
|
@@ -20,7 +20,8 @@ export class Promises {
|
|
|
20
20
|
}
|
|
21
21
|
let resolve: (value: T | PromiseLike<T>) => void;
|
|
22
22
|
let reject: (reason?: any) => void;
|
|
23
|
-
// @ts-ignore
|
|
23
|
+
// @ts-ignore -- Polyfill/Fallback for environment without Promise.withResolvers
|
|
24
|
+
// eslint-disable-next-line
|
|
24
25
|
const promise = new Promise<T>((res, rej) => {
|
|
25
26
|
resolve = res;
|
|
26
27
|
reject = rej;
|
package/src/asyncs/timeout.ts
CHANGED
|
@@ -3,7 +3,7 @@ export function timeout<T = any>(
|
|
|
3
3
|
ms: number,
|
|
4
4
|
): Promise<T> {
|
|
5
5
|
const error = new TimeoutError();
|
|
6
|
-
let timeout:
|
|
6
|
+
let timeout: ReturnType<typeof setTimeout>;
|
|
7
7
|
let ac: AbortController | undefined;
|
|
8
8
|
if (typeof pending === 'function') {
|
|
9
9
|
ac = new AbortController();
|
package/src/crypto/hashing.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { ArrayBuffers } from '../io/ArrayBuffers';
|
|
2
|
+
import type { Bytes } from '../io/types';
|
|
2
3
|
|
|
3
4
|
type HashEncoding = 'hex' | 'base64' | 'buffer';
|
|
4
5
|
|
|
5
6
|
type HashFunction = {
|
|
6
7
|
(s: BinaryLike, o?: 'hex' | 'base64' | undefined): Promise<string>;
|
|
7
|
-
(s: BinaryLike, o: 'buffer'): Promise<
|
|
8
|
+
(s: BinaryLike, o: 'buffer'): Promise<Bytes>;
|
|
8
9
|
};
|
|
9
10
|
|
|
10
11
|
function createDigestFunction(a: string): HashFunction {
|
|
@@ -17,27 +18,27 @@ function createDigestFunction(a: string): HashFunction {
|
|
|
17
18
|
}) as HashFunction;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
export function sha1(s: BinaryLike, o?: undefined | 'buffer'): Promise<
|
|
21
|
+
export function sha1(s: BinaryLike, o?: undefined | 'buffer'): Promise<Bytes>;
|
|
21
22
|
export function sha1(s: BinaryLike, o: 'hex' | 'base64'): Promise<string>;
|
|
22
23
|
export function sha1(s: BinaryLike, o?: DigestOptions) {
|
|
23
24
|
return digestOf('SHA-1', s, o);
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
export function sha256(s: BinaryLike, o?: undefined | 'buffer'): Promise<
|
|
27
|
+
export function sha256(s: BinaryLike, o?: undefined | 'buffer'): Promise<Bytes>;
|
|
27
28
|
export function sha256(s: BinaryLike, o: 'hex' | 'base64'): Promise<string>;
|
|
28
29
|
|
|
29
30
|
export function sha256(s: BinaryLike, o?: DigestOptions) {
|
|
30
31
|
return digestOf('SHA-256', s, o);
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
export function sha384(s: BinaryLike, o?: undefined | 'buffer'): Promise<
|
|
34
|
+
export function sha384(s: BinaryLike, o?: undefined | 'buffer'): Promise<Bytes>;
|
|
34
35
|
export function sha384(s: BinaryLike, o: 'hex' | 'base64'): Promise<string>;
|
|
35
36
|
|
|
36
37
|
export function sha384(s: BinaryLike, o?: DigestOptions) {
|
|
37
38
|
return digestOf('SHA-384', s, o);
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
export function sha512(s: BinaryLike, o?: undefined | 'buffer'): Promise<
|
|
41
|
+
export function sha512(s: BinaryLike, o?: undefined | 'buffer'): Promise<Bytes>;
|
|
41
42
|
export function sha512(s: BinaryLike, o: 'hex' | 'base64'): Promise<string>;
|
|
42
43
|
|
|
43
44
|
export function sha512(s: BinaryLike, o?: DigestOptions) {
|
|
@@ -84,7 +85,7 @@ export function hmac<O extends DigestOptions>(
|
|
|
84
85
|
key: BinaryLike | CryptoKey,
|
|
85
86
|
data: BinaryLike,
|
|
86
87
|
o?: O,
|
|
87
|
-
): Promise<IsStringCoding<O> extends true ? string :
|
|
88
|
+
): Promise<IsStringCoding<O> extends true ? string : Bytes>;
|
|
88
89
|
|
|
89
90
|
export async function hmac(
|
|
90
91
|
hash: 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512' | 'sha1' | 'sha256' | 'sha384' | 'sha512',
|
package/src/crypto/pem/pem.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ArrayBuffers } from '../../io/ArrayBuffers';
|
|
2
|
+
import type { Bytes } from '../../io/types';
|
|
2
3
|
|
|
3
4
|
export interface Block {
|
|
4
5
|
/**
|
|
@@ -30,7 +31,7 @@ export interface Block {
|
|
|
30
31
|
| 'SM2 PARAMETERS';
|
|
31
32
|
|
|
32
33
|
header: Record<string, string>;
|
|
33
|
-
bytes:
|
|
34
|
+
bytes: Bytes;
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
export class PEM {
|
|
@@ -53,7 +54,7 @@ export class PEM {
|
|
|
53
54
|
type,
|
|
54
55
|
header,
|
|
55
56
|
// avoid replaceAll
|
|
56
|
-
bytes: ArrayBuffers.from(b64.replace(/[\r\n]/g, ''), 'base64'),
|
|
57
|
+
bytes: ArrayBuffers.from(b64.replace(/[\r\n]/g, ''), 'base64', Uint8Array),
|
|
57
58
|
},
|
|
58
59
|
head: data.slice(0, match.index || 0),
|
|
59
60
|
tail: data.slice((match.index || 0) + match[0].length),
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import { createRandomUUIDv7, isUUIDv7, parseUUIDv7Timestamp, randomUUIDv7 } from './randomUUIDv7';
|
|
3
|
+
|
|
4
|
+
describe('randomUUIDv7', () => {
|
|
5
|
+
test('generates valid UUIDv7', () => {
|
|
6
|
+
const uuid = randomUUIDv7();
|
|
7
|
+
expect(uuid).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test('generates unique UUIDs', () => {
|
|
11
|
+
const uuids = new Set<string>();
|
|
12
|
+
for (let i = 0; i < 1000; i++) {
|
|
13
|
+
uuids.add(randomUUIDv7());
|
|
14
|
+
}
|
|
15
|
+
expect(uuids.size).toBe(1000);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('respects provided timestamp', () => {
|
|
19
|
+
const ts = 1704067200000; // 2024-01-01 00:00:00 UTC
|
|
20
|
+
const uuid = randomUUIDv7(ts);
|
|
21
|
+
const extractedTs = parseUUIDv7Timestamp(uuid);
|
|
22
|
+
expect(extractedTs).toBe(ts);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('UUIDs are sortable by time', () => {
|
|
26
|
+
const ts1 = 1704067200000;
|
|
27
|
+
const ts2 = 1704067201000;
|
|
28
|
+
const uuid1 = randomUUIDv7(ts1);
|
|
29
|
+
const uuid2 = randomUUIDv7(ts2);
|
|
30
|
+
expect(uuid1 < uuid2).toBe(true);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('isUUIDv7', () => {
|
|
35
|
+
test('returns true for valid UUIDv7', () => {
|
|
36
|
+
const uuid = randomUUIDv7();
|
|
37
|
+
expect(isUUIDv7(uuid)).toBe(true);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('returns false for UUIDv4', () => {
|
|
41
|
+
expect(isUUIDv7('550e8400-e29b-41d4-a716-446655440000')).toBe(false);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('returns false for invalid strings', () => {
|
|
45
|
+
expect(isUUIDv7('')).toBe(false);
|
|
46
|
+
expect(isUUIDv7(null)).toBe(false);
|
|
47
|
+
expect(isUUIDv7(undefined)).toBe(false);
|
|
48
|
+
expect(isUUIDv7('not-a-uuid')).toBe(false);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('parseUUIDv7Timestamp', () => {
|
|
53
|
+
test('extracts correct timestamp', () => {
|
|
54
|
+
const ts = Date.now();
|
|
55
|
+
const uuid = randomUUIDv7(ts);
|
|
56
|
+
expect(parseUUIDv7Timestamp(uuid)).toBe(ts);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('throws for invalid UUID format', () => {
|
|
60
|
+
expect(() => parseUUIDv7Timestamp('invalid')).toThrow('Invalid UUID format');
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('createRandomUUIDv7', () => {
|
|
65
|
+
test('creates generator with custom now function', () => {
|
|
66
|
+
let currentTime = 1704067200000;
|
|
67
|
+
const generator = createRandomUUIDv7({ now: () => currentTime });
|
|
68
|
+
|
|
69
|
+
const uuid1 = generator();
|
|
70
|
+
expect(parseUUIDv7Timestamp(uuid1)).toBe(currentTime);
|
|
71
|
+
|
|
72
|
+
currentTime = 1704067201000;
|
|
73
|
+
const uuid2 = generator();
|
|
74
|
+
expect(parseUUIDv7Timestamp(uuid2)).toBe(currentTime);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('generator accepts explicit timestamp override', () => {
|
|
78
|
+
const generator = createRandomUUIDv7({ now: () => 1000 });
|
|
79
|
+
const uuid = generator(2000);
|
|
80
|
+
expect(parseUUIDv7Timestamp(uuid)).toBe(2000);
|
|
81
|
+
});
|
|
82
|
+
});
|