@valkyriestudios/utils 12.47.0 → 12.48.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/cjs/array/join.js +1 -1
- package/cjs/date/diff.js +10 -10
- package/cjs/deep/get.js +46 -72
- package/cjs/deep/set.js +74 -37
- package/cjs/formdata/toObject.js +96 -61
- package/cjs/hash/djb2.js +1 -1
- package/cjs/hash/fnv1A.js +5 -4
- package/cjs/hash/guid.js +30 -18
- package/cjs/hash/hexId.js +23 -15
- package/cjs/hash/utils.js +25 -33
- package/cjs/hash/uuidv7.js +29 -28
- package/cjs/string/forbiddenKeys.js +8 -0
- package/cjs/string/humanizeNumber.js +2 -1
- package/esm/array/join.js +1 -1
- package/esm/date/diff.js +10 -10
- package/esm/deep/get.js +46 -72
- package/esm/deep/set.js +74 -37
- package/esm/formdata/toObject.js +96 -61
- package/esm/hash/djb2.js +1 -1
- package/esm/hash/fnv1A.js +5 -4
- package/esm/hash/guid.js +30 -18
- package/esm/hash/hexId.js +23 -15
- package/esm/hash/utils.js +25 -33
- package/esm/hash/uuidv7.js +29 -28
- package/esm/string/forbiddenKeys.js +5 -0
- package/esm/string/humanizeNumber.js +2 -1
- package/index.d.ts +3 -0
- package/package.json +7 -7
- package/string/forbiddenKeys.d.ts +1 -0
package/cjs/array/join.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.join = join;
|
|
|
4
4
|
exports.default = join;
|
|
5
5
|
const round_1 = require("../number/round");
|
|
6
6
|
const isIntegerAboveOrEqual_1 = require("../number/isIntegerAboveOrEqual");
|
|
7
|
-
const SPACE_RGX =
|
|
7
|
+
const SPACE_RGX = /\s+/g;
|
|
8
8
|
function join(val, opts) {
|
|
9
9
|
let normalized;
|
|
10
10
|
if (Array.isArray(val)) {
|
package/cjs/date/diff.js
CHANGED
|
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.diff = diff;
|
|
4
4
|
exports.default = diff;
|
|
5
5
|
const convertToDate_1 = require("./convertToDate");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
6
|
+
const INV_SECOND_IN_MILLISECONDS = 1.0 / 1000;
|
|
7
|
+
const INV_MINUTE_IN_MILLISECONDS = 1.0 / (60 * 1000);
|
|
8
|
+
const INV_HOUR_IN_MILLISECONDS = 1.0 / (60 * 60 * 1000);
|
|
9
|
+
const INV_DAY_IN_MILLISECONDS = 1.0 / (24 * 60 * 60 * 1000);
|
|
10
|
+
const INV_WEEK_IN_MILLISECONDS = 1.0 / (7 * 24 * 60 * 60 * 1000);
|
|
11
11
|
function diff(val_a, val_b, key = 'millisecond') {
|
|
12
12
|
const n_val_a = (0, convertToDate_1.convertToDate)(val_a);
|
|
13
13
|
const n_val_b = (0, convertToDate_1.convertToDate)(val_b);
|
|
@@ -18,19 +18,19 @@ function diff(val_a, val_b, key = 'millisecond') {
|
|
|
18
18
|
switch (key) {
|
|
19
19
|
case 'week':
|
|
20
20
|
case 'weeks':
|
|
21
|
-
return diff_in_ms
|
|
21
|
+
return diff_in_ms * INV_WEEK_IN_MILLISECONDS;
|
|
22
22
|
case 'day':
|
|
23
23
|
case 'days':
|
|
24
|
-
return diff_in_ms
|
|
24
|
+
return diff_in_ms * INV_DAY_IN_MILLISECONDS;
|
|
25
25
|
case 'hour':
|
|
26
26
|
case 'hours':
|
|
27
|
-
return diff_in_ms
|
|
27
|
+
return diff_in_ms * INV_HOUR_IN_MILLISECONDS;
|
|
28
28
|
case 'minute':
|
|
29
29
|
case 'minutes':
|
|
30
|
-
return diff_in_ms
|
|
30
|
+
return diff_in_ms * INV_MINUTE_IN_MILLISECONDS;
|
|
31
31
|
case 'second':
|
|
32
32
|
case 'seconds':
|
|
33
|
-
return diff_in_ms
|
|
33
|
+
return diff_in_ms * INV_SECOND_IN_MILLISECONDS;
|
|
34
34
|
default:
|
|
35
35
|
return diff_in_ms;
|
|
36
36
|
}
|
package/cjs/deep/get.js
CHANGED
|
@@ -3,87 +3,61 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.deepGet = deepGet;
|
|
4
4
|
exports.default = deepGet;
|
|
5
5
|
function deepGet(obj, path, get_parent = false) {
|
|
6
|
-
if (Object.prototype.toString.call(obj) !== '[object Object]' &&
|
|
7
|
-
!Array.isArray(obj))
|
|
6
|
+
if (Object.prototype.toString.call(obj) !== '[object Object]' && !Array.isArray(obj)) {
|
|
8
7
|
throw new TypeError('deepGet: Requires object or array');
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
}
|
|
9
|
+
if (!path || typeof path !== 'string') {
|
|
11
10
|
throw new TypeError('deepGet: Invalid path provided');
|
|
12
|
-
|
|
13
|
-
let
|
|
14
|
-
let
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
11
|
+
}
|
|
12
|
+
let cursor = obj;
|
|
13
|
+
let parent = obj;
|
|
14
|
+
let keyStart = 0;
|
|
15
|
+
const len = path.length;
|
|
16
|
+
for (let i = 0; i <= len; i++) {
|
|
17
|
+
const code = i === len ? 46 : path.charCodeAt(i);
|
|
18
|
+
if (code === 46 || code === 91 || code === 93) {
|
|
19
|
+
if (i === keyStart) {
|
|
20
|
+
keyStart = i + 1;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
const key = path.substring(keyStart, i);
|
|
24
|
+
keyStart = i + 1;
|
|
25
|
+
parent = cursor;
|
|
26
|
+
if (Array.isArray(cursor)) {
|
|
27
|
+
const idx = +key;
|
|
28
|
+
if (idx === idx) {
|
|
29
|
+
cursor = cursor[idx | 0];
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
const mapped = [];
|
|
33
|
+
const cLen = cursor.length;
|
|
34
|
+
for (let j = 0; j < cLen; j++) {
|
|
35
|
+
const item = cursor[j];
|
|
36
|
+
if (item && typeof item === 'object') {
|
|
37
|
+
const val = item[key];
|
|
38
|
+
if (val !== undefined) {
|
|
39
|
+
if (Array.isArray(val)) {
|
|
40
|
+
const vLen = val.length;
|
|
41
|
+
for (let k = 0; k < vLen; k++)
|
|
42
|
+
mapped.push(val[k]);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
mapped.push(val);
|
|
46
|
+
}
|
|
38
47
|
}
|
|
39
48
|
}
|
|
40
|
-
node = extracted;
|
|
41
|
-
nodes.push(node);
|
|
42
49
|
}
|
|
50
|
+
if (mapped.length === 0)
|
|
51
|
+
return undefined;
|
|
52
|
+
cursor = mapped;
|
|
43
53
|
}
|
|
44
|
-
else if (typeof node === 'object' && node !== null) {
|
|
45
|
-
node = node[key];
|
|
46
|
-
nodes.push(node);
|
|
47
|
-
}
|
|
48
|
-
key = '';
|
|
49
|
-
break;
|
|
50
|
-
default:
|
|
51
|
-
key += char;
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
if (key) {
|
|
56
|
-
if (Array.isArray(node)) {
|
|
57
|
-
let ix = Number(key);
|
|
58
|
-
if (!isNaN(ix)) {
|
|
59
|
-
ix = ix | 0;
|
|
60
|
-
if (ix < 0 || ix > node.length - 1)
|
|
61
|
-
return undefined;
|
|
62
|
-
node = node[ix];
|
|
63
|
-
nodes.push(node);
|
|
64
54
|
}
|
|
65
|
-
else {
|
|
66
|
-
|
|
67
|
-
for (let i = 0; i < node.length; i++) {
|
|
68
|
-
const val = node[i]?.[key];
|
|
69
|
-
if (val !== undefined)
|
|
70
|
-
extracted.push(...Array.isArray(val) ? val : [val]);
|
|
71
|
-
}
|
|
72
|
-
node = extracted.length ? extracted : undefined;
|
|
73
|
-
nodes.push(node);
|
|
55
|
+
else if (cursor) {
|
|
56
|
+
cursor = cursor[key];
|
|
74
57
|
}
|
|
75
|
-
|
|
76
|
-
else if (typeof node === 'object' && node !== null) {
|
|
77
|
-
node = node[key];
|
|
78
|
-
nodes.push(node);
|
|
79
|
-
if (node === undefined)
|
|
58
|
+
if (cursor === undefined)
|
|
80
59
|
return undefined;
|
|
81
60
|
}
|
|
82
|
-
else {
|
|
83
|
-
return undefined;
|
|
84
|
-
}
|
|
85
61
|
}
|
|
86
|
-
|
|
87
|
-
nodes.pop();
|
|
88
|
-
return nodes.length ? nodes.pop() : obj;
|
|
62
|
+
return get_parent ? parent : cursor;
|
|
89
63
|
}
|
package/cjs/deep/set.js
CHANGED
|
@@ -9,45 +9,82 @@ function deepSet(obj, path, value, define = false) {
|
|
|
9
9
|
throw new TypeError('Deepset is only supported for objects');
|
|
10
10
|
if (typeof path !== 'string')
|
|
11
11
|
throw new TypeError('No path was given');
|
|
12
|
-
if (
|
|
13
|
-
throw new TypeError('Malicious path provided');
|
|
14
|
-
const path_s = path.trim();
|
|
15
|
-
if (!path_s.length)
|
|
12
|
+
if (path.trim().length === 0) {
|
|
16
13
|
throw new TypeError('No path was given');
|
|
17
|
-
const parts = path_s
|
|
18
|
-
.replace(/\[/g, '.')
|
|
19
|
-
.replace(/(\.){2,}/g, '.')
|
|
20
|
-
.replace(/(^\.|\.$|\])/g, '')
|
|
21
|
-
.split('.');
|
|
22
|
-
const last_part_ix = parts.length - 1;
|
|
23
|
-
for (let i = 0; i < last_part_ix; i++) {
|
|
24
|
-
if (Array.isArray(obj)) {
|
|
25
|
-
const idx = parseInt(parts[i]);
|
|
26
|
-
if (!Number.isInteger(idx) || idx < 0)
|
|
27
|
-
throw new TypeError('Invalid path provided');
|
|
28
|
-
if (!obj[idx])
|
|
29
|
-
obj[idx] = {};
|
|
30
|
-
obj = obj[idx];
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
if (!obj[parts[i]])
|
|
34
|
-
obj[parts[i]] = {};
|
|
35
|
-
obj = obj[parts[i]];
|
|
36
|
-
}
|
|
37
14
|
}
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
if (define) {
|
|
41
|
-
Object.defineProperty(obj, parts[last_part_ix], value);
|
|
42
|
-
}
|
|
43
|
-
else if (Array.isArray(obj)) {
|
|
44
|
-
const idx = parseInt(parts[last_part_ix]);
|
|
45
|
-
if (!Number.isInteger(idx) || idx < 0)
|
|
46
|
-
throw new TypeError('Invalid path provided');
|
|
47
|
-
obj[idx] = value;
|
|
15
|
+
if (RGX_MALICIOUS.test(path)) {
|
|
16
|
+
throw new TypeError('Malicious path provided');
|
|
48
17
|
}
|
|
49
|
-
|
|
50
|
-
|
|
18
|
+
let cursor = obj;
|
|
19
|
+
let keyStart = 0;
|
|
20
|
+
const len = path.length;
|
|
21
|
+
for (let i = 0; i <= len; i++) {
|
|
22
|
+
const code = i === len ? 46 : path.charCodeAt(i);
|
|
23
|
+
if (code === 46 || code === 91 || code === 93) {
|
|
24
|
+
if (i === keyStart) {
|
|
25
|
+
keyStart = i + 1;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const key = path.substring(keyStart, i);
|
|
29
|
+
keyStart = i + 1;
|
|
30
|
+
let isEnd = i === len;
|
|
31
|
+
if (!isEnd) {
|
|
32
|
+
let j = i + 1;
|
|
33
|
+
isEnd = true;
|
|
34
|
+
for (; j < len; j++) {
|
|
35
|
+
const c = path.charCodeAt(j);
|
|
36
|
+
if (c !== 46 && c !== 91 && c !== 93) {
|
|
37
|
+
isEnd = false;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (isEnd) {
|
|
43
|
+
if (Array.isArray(cursor)) {
|
|
44
|
+
const idx = +key;
|
|
45
|
+
if (idx !== idx || (idx | 0) !== idx || idx < 0) {
|
|
46
|
+
throw new TypeError('Invalid path provided');
|
|
47
|
+
}
|
|
48
|
+
if (define) {
|
|
49
|
+
Object.defineProperty(cursor, key, value);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
cursor[idx] = value;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else if (define) {
|
|
56
|
+
Object.defineProperty(cursor, key, value);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
cursor[key] = value;
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
let nextCursor;
|
|
64
|
+
if (Array.isArray(cursor)) {
|
|
65
|
+
const idx = +key;
|
|
66
|
+
if (idx !== idx || (idx | 0) !== idx || idx < 0) {
|
|
67
|
+
throw new TypeError('Invalid path provided');
|
|
68
|
+
}
|
|
69
|
+
nextCursor = cursor[idx];
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
nextCursor = cursor[key];
|
|
73
|
+
}
|
|
74
|
+
if (nextCursor === undefined || nextCursor === null) {
|
|
75
|
+
nextCursor = {};
|
|
76
|
+
if (Array.isArray(cursor)) {
|
|
77
|
+
cursor[+key] = nextCursor;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
cursor[key] = nextCursor;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else if (typeof nextCursor !== 'object') {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
cursor = nextCursor;
|
|
87
|
+
}
|
|
51
88
|
}
|
|
52
|
-
return
|
|
89
|
+
return false;
|
|
53
90
|
}
|
package/cjs/formdata/toObject.js
CHANGED
|
@@ -3,96 +3,131 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.toObject = toObject;
|
|
4
4
|
exports.default = toObject;
|
|
5
5
|
const isFormat_1 = require("../date/isFormat");
|
|
6
|
-
const
|
|
6
|
+
const forbiddenKeys_1 = require("../string/forbiddenKeys");
|
|
7
7
|
function assign(acc, rawkey, value, single) {
|
|
8
|
+
if (rawkey.indexOf('.') === -1 && rawkey.indexOf('[') === -1) {
|
|
9
|
+
if (forbiddenKeys_1.FORBIDDEN_KEYS.has(rawkey))
|
|
10
|
+
return;
|
|
11
|
+
if (single?.has(rawkey)) {
|
|
12
|
+
acc[rawkey] = value;
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const existing = acc[rawkey];
|
|
16
|
+
if (existing === undefined) {
|
|
17
|
+
acc[rawkey] = value;
|
|
18
|
+
}
|
|
19
|
+
else if (Array.isArray(existing)) {
|
|
20
|
+
existing.push(value);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
acc[rawkey] = [existing, value];
|
|
24
|
+
}
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const keys = [];
|
|
28
|
+
let start = 0;
|
|
29
|
+
const len = rawkey.length;
|
|
30
|
+
for (let i = 0; i < len; i++) {
|
|
31
|
+
const code = rawkey.charCodeAt(i);
|
|
32
|
+
if (code === 46 || code === 91 || code === 93) {
|
|
33
|
+
if (i > start)
|
|
34
|
+
keys.push(rawkey.substring(start, i));
|
|
35
|
+
start = i + 1;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (start < len)
|
|
39
|
+
keys.push(rawkey.substring(start));
|
|
8
40
|
let cursor = acc;
|
|
9
|
-
const keys = rawkey.match(RGX_TOKENS);
|
|
10
41
|
const keys_len = keys.length;
|
|
11
42
|
for (let i = 0; i < keys_len; i++) {
|
|
12
43
|
const key = keys[i];
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
else if (!(key in cursor) || (single && single.has(key))) {
|
|
26
|
-
cursor[key] = value;
|
|
44
|
+
if (forbiddenKeys_1.FORBIDDEN_KEYS.has(key))
|
|
45
|
+
return;
|
|
46
|
+
const isLast = i === keys_len - 1;
|
|
47
|
+
const cursorKey = Array.isArray(cursor) ? +key : key;
|
|
48
|
+
if (isLast) {
|
|
49
|
+
if (cursor[cursorKey] === undefined || (single && single.has(key))) {
|
|
50
|
+
cursor[cursorKey] = value;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
const existing = cursor[cursorKey];
|
|
54
|
+
if (Array.isArray(existing)) {
|
|
55
|
+
existing.push(value);
|
|
27
56
|
}
|
|
28
57
|
else {
|
|
29
|
-
|
|
30
|
-
if (Array.isArray(cursor_val)) {
|
|
31
|
-
cursor_val.push(value);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
cursor[key] = [cursor_val, value];
|
|
35
|
-
}
|
|
58
|
+
cursor[cursorKey] = [existing, value];
|
|
36
59
|
}
|
|
37
60
|
}
|
|
38
61
|
}
|
|
62
|
+
else {
|
|
63
|
+
if (cursor[cursorKey] === undefined) {
|
|
64
|
+
cursor[cursorKey] = isNaN(+keys[i + 1]) ? {} : [];
|
|
65
|
+
}
|
|
66
|
+
cursor = cursor[cursorKey];
|
|
67
|
+
}
|
|
39
68
|
}
|
|
40
69
|
}
|
|
41
70
|
function toObject(form, config) {
|
|
42
71
|
if (!(form instanceof FormData))
|
|
43
72
|
throw new Error('formdata/toObject: Value is not an instance of FormData');
|
|
44
|
-
const set = config?.raw === true ? null : new Set(Array.isArray(config?.raw) ? config?.raw : []);
|
|
45
|
-
const set_guard = !!(set && set.size > 0);
|
|
46
|
-
const single = Array.isArray(config?.single) ? new Set(config.single) : null;
|
|
47
|
-
const nBool = config?.normalize_bool !== false;
|
|
48
|
-
const nNull = config?.normalize_null !== false;
|
|
49
|
-
const nDate = config?.normalize_date !== false;
|
|
50
|
-
const nNumber = config?.normalize_number !== false;
|
|
51
73
|
const acc = {};
|
|
52
|
-
|
|
74
|
+
const single = Array.isArray(config?.single) ? new Set(config.single) : null;
|
|
75
|
+
if (config?.raw === true) {
|
|
53
76
|
for (const [key, value] of form) {
|
|
54
77
|
assign(acc, key, value, single);
|
|
55
78
|
}
|
|
56
79
|
return acc;
|
|
57
80
|
}
|
|
81
|
+
const rawConfig = config?.raw;
|
|
82
|
+
const set = rawConfig ? new Set(Array.isArray(rawConfig) ? rawConfig : []) : null;
|
|
83
|
+
const hasSet = set !== null && set.size > 0;
|
|
84
|
+
const nBool = config?.normalize_bool !== false;
|
|
85
|
+
const nNull = config?.normalize_null !== false;
|
|
86
|
+
const nDate = config?.normalize_date !== false;
|
|
87
|
+
const nNumber = config?.normalize_number !== false;
|
|
58
88
|
for (const [key, value] of form) {
|
|
59
|
-
if (
|
|
89
|
+
if (hasSet && set.has(key)) {
|
|
60
90
|
assign(acc, key, value, single);
|
|
61
91
|
continue;
|
|
62
92
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
assign(acc, key, nBool ? true : value, single);
|
|
68
|
-
continue;
|
|
69
|
-
case 'false':
|
|
70
|
-
case 'FALSE':
|
|
71
|
-
case 'False':
|
|
72
|
-
assign(acc, key, nBool ? false : value, single);
|
|
73
|
-
continue;
|
|
74
|
-
case 'null':
|
|
75
|
-
case 'NULL':
|
|
76
|
-
case 'Null':
|
|
77
|
-
assign(acc, key, nNull ? null : value, single);
|
|
93
|
+
if (typeof value === 'string') {
|
|
94
|
+
const len = value.length;
|
|
95
|
+
if (len === 0) {
|
|
96
|
+
assign(acc, key, value, single);
|
|
78
97
|
continue;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
assign(acc, key, nVal, single);
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if (nDate && value[4] === '-' && value[7] === '-' && value[10] === 'T' && (0, isFormat_1.isDateFormat)(value, 'ISO')) {
|
|
89
|
-
assign(acc, key, new Date(value), single);
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
98
|
+
}
|
|
99
|
+
if (len === 4) {
|
|
100
|
+
if (nBool && (value === 'true' || value === 'TRUE' || value === 'True')) {
|
|
101
|
+
assign(acc, key, true, single);
|
|
102
|
+
continue;
|
|
92
103
|
}
|
|
93
|
-
|
|
104
|
+
if (nNull && (value === 'null' || value === 'NULL' || value === 'Null')) {
|
|
105
|
+
assign(acc, key, null, single);
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else if (len === 5) {
|
|
110
|
+
if (nBool && (value === 'false' || value === 'FALSE' || value === 'False')) {
|
|
111
|
+
assign(acc, key, false, single);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (nNumber && value.charCodeAt(0) !== 48) {
|
|
116
|
+
const nVal = +value;
|
|
117
|
+
if (!isNaN(nVal)) {
|
|
118
|
+
assign(acc, key, nVal, single);
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (nDate && len >= 10 &&
|
|
123
|
+
value.charCodeAt(4) === 45 &&
|
|
124
|
+
value.charCodeAt(7) === 45 &&
|
|
125
|
+
(0, isFormat_1.isDateFormat)(value, 'ISO')) {
|
|
126
|
+
assign(acc, key, new Date(value), single);
|
|
127
|
+
continue;
|
|
94
128
|
}
|
|
95
129
|
}
|
|
130
|
+
assign(acc, key, value, single);
|
|
96
131
|
}
|
|
97
132
|
return acc;
|
|
98
133
|
}
|
package/cjs/hash/djb2.js
CHANGED
package/cjs/hash/fnv1A.js
CHANGED
|
@@ -6,13 +6,14 @@ exports.default = fnv1A;
|
|
|
6
6
|
const utils_1 = require("./utils");
|
|
7
7
|
exports.FNV_32 = 2166136261;
|
|
8
8
|
exports.FNV_64 = 1099511628211n;
|
|
9
|
+
const FNV_PRIME = 16777619;
|
|
9
10
|
function fnv1A(data, offset = exports.FNV_32) {
|
|
10
11
|
let hash = offset;
|
|
11
|
-
const
|
|
12
|
-
const len =
|
|
12
|
+
const str = (0, utils_1.toString)(data);
|
|
13
|
+
const len = str.length;
|
|
13
14
|
for (let i = 0; i < len; i++) {
|
|
14
|
-
hash ^=
|
|
15
|
-
hash
|
|
15
|
+
hash ^= str.charCodeAt(i);
|
|
16
|
+
hash = Math.imul(hash, FNV_PRIME);
|
|
16
17
|
}
|
|
17
18
|
return hash >>> 0;
|
|
18
19
|
}
|
package/cjs/hash/guid.js
CHANGED
|
@@ -2,27 +2,39 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.guid = guid;
|
|
4
4
|
exports.default = guid;
|
|
5
|
+
const CRYPTO = globalThis.crypto;
|
|
5
6
|
const HEX = [];
|
|
6
7
|
for (let i = 0; i < 256; i++) {
|
|
7
|
-
HEX[i] = (i
|
|
8
|
-
}
|
|
9
|
-
let pool = new Uint8Array(0);
|
|
10
|
-
let poolIdx = 0;
|
|
11
|
-
function refill(size = 16 * 1024) {
|
|
12
|
-
pool = new Uint8Array(size);
|
|
13
|
-
crypto.getRandomValues(pool);
|
|
14
|
-
poolIdx = 0;
|
|
8
|
+
HEX[i] = (i + 256).toString(16).substring(1);
|
|
15
9
|
}
|
|
10
|
+
const POOL_SIZE = 16 * 1024;
|
|
11
|
+
const pool = new Uint8Array(POOL_SIZE);
|
|
12
|
+
let poolIdx = POOL_SIZE;
|
|
16
13
|
function guid() {
|
|
17
|
-
if (poolIdx + 16 >
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
if (poolIdx + 16 > POOL_SIZE) {
|
|
15
|
+
CRYPTO.getRandomValues(pool);
|
|
16
|
+
poolIdx = 0;
|
|
17
|
+
}
|
|
18
|
+
const p = poolIdx;
|
|
20
19
|
poolIdx += 16;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
HEX[
|
|
25
|
-
|
|
26
|
-
HEX[
|
|
27
|
-
HEX[
|
|
20
|
+
return (HEX[pool[p]] +
|
|
21
|
+
HEX[pool[p + 1]] +
|
|
22
|
+
HEX[pool[p + 2]] +
|
|
23
|
+
HEX[pool[p + 3]] +
|
|
24
|
+
'-' +
|
|
25
|
+
HEX[pool[p + 4]] +
|
|
26
|
+
HEX[pool[p + 5]] +
|
|
27
|
+
'-' +
|
|
28
|
+
HEX[(pool[p + 6] & 0x0f) | 0x40] +
|
|
29
|
+
HEX[pool[p + 7]] +
|
|
30
|
+
'-' +
|
|
31
|
+
HEX[(pool[p + 8] & 0x3f) | 0x80] +
|
|
32
|
+
HEX[pool[p + 9]] +
|
|
33
|
+
'-' +
|
|
34
|
+
HEX[pool[p + 10]] +
|
|
35
|
+
HEX[pool[p + 11]] +
|
|
36
|
+
HEX[pool[p + 12]] +
|
|
37
|
+
HEX[pool[p + 13]] +
|
|
38
|
+
HEX[pool[p + 14]] +
|
|
39
|
+
HEX[pool[p + 15]]);
|
|
28
40
|
}
|
package/cjs/hash/hexId.js
CHANGED
|
@@ -2,27 +2,35 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.hexId = hexId;
|
|
4
4
|
exports.default = hexId;
|
|
5
|
+
const CRYPTO = globalThis.crypto;
|
|
5
6
|
const HEX = [];
|
|
6
7
|
for (let i = 0; i < 256; i++) {
|
|
7
|
-
HEX[i] = (i
|
|
8
|
-
}
|
|
9
|
-
let pool = new Uint8Array(0);
|
|
10
|
-
let poolIdx = 0;
|
|
11
|
-
function refill(size = 16 * 1024) {
|
|
12
|
-
pool = new Uint8Array(size);
|
|
13
|
-
crypto.getRandomValues(pool);
|
|
14
|
-
poolIdx = 0;
|
|
8
|
+
HEX[i] = (i + 256).toString(16).substring(1);
|
|
15
9
|
}
|
|
10
|
+
const POOL_SIZE = 16 * 1024;
|
|
11
|
+
const pool = new Uint8Array(POOL_SIZE);
|
|
12
|
+
let poolIdx = POOL_SIZE;
|
|
16
13
|
function hexId(size) {
|
|
17
|
-
if (
|
|
14
|
+
if (typeof size !== 'number' || size <= 0)
|
|
18
15
|
return '';
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
if (size > POOL_SIZE) {
|
|
17
|
+
const buf = new Uint8Array(size);
|
|
18
|
+
CRYPTO.getRandomValues(buf);
|
|
19
|
+
let out = '';
|
|
20
|
+
for (let i = 0; i < size; i++) {
|
|
21
|
+
out += HEX[buf[i]];
|
|
22
|
+
}
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
if (poolIdx + size > POOL_SIZE) {
|
|
26
|
+
CRYPTO.getRandomValues(pool);
|
|
27
|
+
poolIdx = 0;
|
|
28
|
+
}
|
|
29
|
+
let i = poolIdx;
|
|
30
|
+
const end = i + size;
|
|
22
31
|
poolIdx += size;
|
|
23
32
|
let out = '';
|
|
24
|
-
|
|
25
|
-
out += HEX[
|
|
26
|
-
}
|
|
33
|
+
while (i < end)
|
|
34
|
+
out += HEX[pool[i++]];
|
|
27
35
|
return out;
|
|
28
36
|
}
|