@valkyriestudios/utils 12.47.0 → 12.49.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/convertToDate.js +15 -8
- package/cjs/date/diff.js +10 -10
- package/cjs/date/format.js +33 -55
- package/cjs/date/is.js +1 -1
- package/cjs/date/isFormat.js +47 -38
- 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/number/round.js +1 -1
- package/cjs/string/forbiddenKeys.js +8 -0
- package/cjs/string/humanizeNumber.js +2 -1
- package/esm/array/join.js +1 -1
- package/esm/date/convertToDate.js +15 -8
- package/esm/date/diff.js +10 -10
- package/esm/date/format.js +33 -55
- package/esm/date/is.js +1 -1
- package/esm/date/isFormat.js +47 -38
- 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/number/round.js +1 -1
- package/esm/string/forbiddenKeys.js +5 -0
- package/esm/string/humanizeNumber.js +2 -1
- package/index.d.ts +13 -10
- package/package.json +7 -7
- package/string/forbiddenKeys.d.ts +1 -0
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 (nVal === 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 || (size | 0) !== size)
|
|
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
|
}
|
package/cjs/hash/utils.js
CHANGED
|
@@ -2,39 +2,31 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.toString = toString;
|
|
4
4
|
function toString(raw) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
else if (raw instanceof RegExp) {
|
|
24
|
-
return String(raw);
|
|
25
|
-
}
|
|
26
|
-
else if (raw instanceof Date) {
|
|
27
|
-
return String(raw.getTime());
|
|
28
|
-
}
|
|
29
|
-
else if (raw instanceof Error) {
|
|
30
|
-
return raw.name + '|' + raw.message;
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
throw new TypeError('A Hash could not be calculated for this datatype');
|
|
34
|
-
}
|
|
35
|
-
case 'symbol':
|
|
5
|
+
const type = typeof raw;
|
|
6
|
+
if (type === 'string')
|
|
7
|
+
return raw;
|
|
8
|
+
if (type === 'number')
|
|
9
|
+
return Number.isFinite(raw) ? String(raw) : 'nan';
|
|
10
|
+
if (type === 'boolean')
|
|
11
|
+
return raw ? 'true' : 'false';
|
|
12
|
+
if (type === 'undefined')
|
|
13
|
+
return 'undefined';
|
|
14
|
+
if (type === 'object') {
|
|
15
|
+
if (raw === null)
|
|
16
|
+
return 'null';
|
|
17
|
+
if (Array.isArray(raw) || Object.prototype.toString.call(raw) === '[object Object]')
|
|
18
|
+
return JSON.stringify(raw);
|
|
19
|
+
if (raw instanceof Date)
|
|
20
|
+
return String(raw.getTime());
|
|
21
|
+
if (raw instanceof RegExp)
|
|
36
22
|
return String(raw);
|
|
37
|
-
|
|
38
|
-
|
|
23
|
+
if (raw instanceof Error)
|
|
24
|
+
return raw.name + '|' + raw.message;
|
|
25
|
+
throw new TypeError('A Hash could not be calculated for this datatype');
|
|
39
26
|
}
|
|
27
|
+
if (type === 'bigint')
|
|
28
|
+
return raw.toString();
|
|
29
|
+
if (type === 'symbol')
|
|
30
|
+
return raw.toString();
|
|
31
|
+
throw new TypeError('A Hash could not be calculated for this datatype');
|
|
40
32
|
}
|
package/cjs/hash/uuidv7.js
CHANGED
|
@@ -2,41 +2,42 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.uuidv7 = uuidv7;
|
|
4
4
|
exports.default = uuidv7;
|
|
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 uuidv7() {
|
|
17
|
-
if (poolIdx + 10 >
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
if (poolIdx + 10 > POOL_SIZE) {
|
|
15
|
+
CRYPTO.getRandomValues(pool);
|
|
16
|
+
poolIdx = 0;
|
|
17
|
+
}
|
|
18
|
+
const p = poolIdx;
|
|
20
19
|
poolIdx += 10;
|
|
21
|
-
const time =
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
HEX[
|
|
20
|
+
const time = Date.now();
|
|
21
|
+
const timeHi = (time / 4294967296) | 0;
|
|
22
|
+
const timeLo = time >>> 0;
|
|
23
|
+
return (HEX[(timeHi >>> 8) & 0xff] +
|
|
24
|
+
HEX[timeHi & 0xff] +
|
|
25
|
+
HEX[(timeLo >>> 24) & 0xff] +
|
|
26
|
+
HEX[(timeLo >>> 16) & 0xff] +
|
|
26
27
|
'-' +
|
|
27
|
-
HEX[
|
|
28
|
-
HEX[
|
|
28
|
+
HEX[(timeLo >>> 8) & 0xff] +
|
|
29
|
+
HEX[timeLo & 0xff] +
|
|
29
30
|
'-' +
|
|
30
|
-
HEX[(
|
|
31
|
-
HEX[
|
|
31
|
+
HEX[(pool[p] & 0x0f) | 0x70] +
|
|
32
|
+
HEX[pool[p + 1]] +
|
|
32
33
|
'-' +
|
|
33
|
-
HEX[(
|
|
34
|
-
HEX[
|
|
34
|
+
HEX[(pool[p + 2] & 0x3f) | 0x80] +
|
|
35
|
+
HEX[pool[p + 3]] +
|
|
35
36
|
'-' +
|
|
36
|
-
HEX[
|
|
37
|
-
HEX[
|
|
38
|
-
HEX[
|
|
39
|
-
HEX[
|
|
40
|
-
HEX[
|
|
41
|
-
HEX[
|
|
37
|
+
HEX[pool[p + 4]] +
|
|
38
|
+
HEX[pool[p + 5]] +
|
|
39
|
+
HEX[pool[p + 6]] +
|
|
40
|
+
HEX[pool[p + 7]] +
|
|
41
|
+
HEX[pool[p + 8]] +
|
|
42
|
+
HEX[pool[p + 9]]);
|
|
42
43
|
}
|
package/cjs/number/round.js
CHANGED
|
@@ -6,7 +6,7 @@ const ROUND_EPSILON = 1 + Number.EPSILON;
|
|
|
6
6
|
function round(val, precision = 0) {
|
|
7
7
|
if (!Number.isFinite(val))
|
|
8
8
|
throw new TypeError('Value should be numeric');
|
|
9
|
-
if (
|
|
9
|
+
if (typeof precision !== 'number' || precision <= 0 || (precision | 0) !== precision)
|
|
10
10
|
return Math.round(val * ROUND_EPSILON);
|
|
11
11
|
const exp = Math.pow(10, precision);
|
|
12
12
|
return Math.round((val * exp) * ROUND_EPSILON) / exp;
|
|
@@ -9,6 +9,7 @@ function humanizeNumber(val, options = {}) {
|
|
|
9
9
|
const SEPARATOR = typeof options?.separator === 'string' && options.separator.length ? options.separator : '.';
|
|
10
10
|
const PRECISION = Number.isInteger(options?.precision) && options.precision >= 0 ? options.precision : 2;
|
|
11
11
|
const DIVIDER = Number.isInteger(options?.divider) && options.divider >= 2 ? options.divider : 1000;
|
|
12
|
+
const INV_DIVIDER = 1.0 / DIVIDER;
|
|
12
13
|
const REAL = options?.real === true;
|
|
13
14
|
const UNITS = Array.isArray(options?.units) && options.units.length
|
|
14
15
|
? options.units
|
|
@@ -25,7 +26,7 @@ function humanizeNumber(val, options = {}) {
|
|
|
25
26
|
let unit_ix = 0;
|
|
26
27
|
if (UNITS) {
|
|
27
28
|
while (normalized >= DIVIDER && unit_ix < UNITS.length - 1) {
|
|
28
|
-
normalized
|
|
29
|
+
normalized *= INV_DIVIDER;
|
|
29
30
|
unit_ix++;
|
|
30
31
|
}
|
|
31
32
|
}
|
package/esm/array/join.js
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
|
-
import { isDate } from './is';
|
|
2
1
|
function convertToDate(val) {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
switch (typeof val) {
|
|
3
|
+
case 'number': {
|
|
4
|
+
if (val !== val)
|
|
5
|
+
return null;
|
|
6
|
+
const d = new Date(val);
|
|
7
|
+
return d.getTime() === d.getTime() ? d : null;
|
|
8
|
+
}
|
|
9
|
+
case 'object':
|
|
10
|
+
return val instanceof Date && val.getTime() === val.getTime() ? val : null;
|
|
11
|
+
case 'string': {
|
|
12
|
+
const d = new Date(val);
|
|
13
|
+
return d.getTime() === d.getTime() ? d : null;
|
|
14
|
+
}
|
|
15
|
+
default:
|
|
16
|
+
return null;
|
|
5
17
|
}
|
|
6
|
-
else if (typeof val === 'string') {
|
|
7
|
-
const date = new Date(val);
|
|
8
|
-
return Number.isNaN(date.getTime()) ? null : date;
|
|
9
|
-
}
|
|
10
|
-
return null;
|
|
11
18
|
}
|
|
12
19
|
export { convertToDate, convertToDate as default };
|
package/esm/date/diff.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { convertToDate } from './convertToDate';
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
2
|
+
const INV_SECOND_IN_MILLISECONDS = 1.0 / 1000;
|
|
3
|
+
const INV_MINUTE_IN_MILLISECONDS = 1.0 / (60 * 1000);
|
|
4
|
+
const INV_HOUR_IN_MILLISECONDS = 1.0 / (60 * 60 * 1000);
|
|
5
|
+
const INV_DAY_IN_MILLISECONDS = 1.0 / (24 * 60 * 60 * 1000);
|
|
6
|
+
const INV_WEEK_IN_MILLISECONDS = 1.0 / (7 * 24 * 60 * 60 * 1000);
|
|
7
7
|
function diff(val_a, val_b, key = 'millisecond') {
|
|
8
8
|
const n_val_a = convertToDate(val_a);
|
|
9
9
|
const n_val_b = convertToDate(val_b);
|
|
@@ -14,19 +14,19 @@ function diff(val_a, val_b, key = 'millisecond') {
|
|
|
14
14
|
switch (key) {
|
|
15
15
|
case 'week':
|
|
16
16
|
case 'weeks':
|
|
17
|
-
return diff_in_ms
|
|
17
|
+
return diff_in_ms * INV_WEEK_IN_MILLISECONDS;
|
|
18
18
|
case 'day':
|
|
19
19
|
case 'days':
|
|
20
|
-
return diff_in_ms
|
|
20
|
+
return diff_in_ms * INV_DAY_IN_MILLISECONDS;
|
|
21
21
|
case 'hour':
|
|
22
22
|
case 'hours':
|
|
23
|
-
return diff_in_ms
|
|
23
|
+
return diff_in_ms * INV_HOUR_IN_MILLISECONDS;
|
|
24
24
|
case 'minute':
|
|
25
25
|
case 'minutes':
|
|
26
|
-
return diff_in_ms
|
|
26
|
+
return diff_in_ms * INV_MINUTE_IN_MILLISECONDS;
|
|
27
27
|
case 'second':
|
|
28
28
|
case 'seconds':
|
|
29
|
-
return diff_in_ms
|
|
29
|
+
return diff_in_ms * INV_SECOND_IN_MILLISECONDS;
|
|
30
30
|
default:
|
|
31
31
|
return diff_in_ms;
|
|
32
32
|
}
|