@valkyriestudios/utils 12.38.0 → 12.40.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/date/format.js +3 -7
- package/cjs/date/isFormat.js +17 -12
- package/cjs/deep/get.js +6 -4
- package/cjs/formdata/toObject.js +21 -14
- package/cjs/modules/Scheduler.js +8 -8
- package/cjs/object/merge.js +11 -13
- package/cjs/object/omit.js +15 -15
- package/date/isFormat.d.ts +2 -0
- package/esm/date/format.js +3 -7
- package/esm/date/isFormat.js +16 -12
- package/esm/deep/get.js +6 -4
- package/esm/formdata/toObject.js +21 -14
- package/esm/modules/Scheduler.js +8 -8
- package/esm/object/merge.js +11 -13
- package/esm/object/omit.js +15 -15
- package/index.d.ts +6 -4
- package/package.json +197 -197
package/cjs/date/format.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.format = format;
|
|
7
7
|
exports.default = format;
|
|
8
8
|
const convertToDate_1 = require("./convertToDate");
|
|
9
|
+
const isFormat_1 = require("./isFormat");
|
|
9
10
|
const LRU_1 = __importDefault(require("../caching/LRU"));
|
|
10
11
|
const WEEK_STARTS = {
|
|
11
12
|
mon: 'mon',
|
|
@@ -13,13 +14,8 @@ const WEEK_STARTS = {
|
|
|
13
14
|
sat: 'sat',
|
|
14
15
|
};
|
|
15
16
|
let DEFAULT_LOCALE = 'en-US';
|
|
16
|
-
let DEFAULT_TZ = 'UTC';
|
|
17
|
+
let DEFAULT_TZ = Intl?.DateTimeFormat?.().resolvedOptions?.().timeZone || 'UTC';
|
|
17
18
|
let DEFAULT_SOW = 'mon';
|
|
18
|
-
try {
|
|
19
|
-
DEFAULT_TZ = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
20
|
-
}
|
|
21
|
-
catch {
|
|
22
|
-
}
|
|
23
19
|
const ESCAPE_RGX = /\[[\s\S]+?]/g;
|
|
24
20
|
const intl_formatters = new LRU_1.default({ max_size: 100 });
|
|
25
21
|
const spec_cache = new LRU_1.default({ max_size: 100 });
|
|
@@ -50,7 +46,7 @@ function toZone(d, zone) {
|
|
|
50
46
|
const month = d.getUTCMonth();
|
|
51
47
|
const day = d.getUTCDate();
|
|
52
48
|
const time = d.getTime();
|
|
53
|
-
const daysInMonths =
|
|
49
|
+
const daysInMonths = (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0) ? isFormat_1.MONTHS_LEAP : isFormat_1.MONTHS;
|
|
54
50
|
let doy = day;
|
|
55
51
|
for (let i = 0; i <= month; i++)
|
|
56
52
|
doy += daysInMonths[i];
|
package/cjs/date/isFormat.js
CHANGED
|
@@ -3,25 +3,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MONTHS = exports.MONTHS_LEAP = void 0;
|
|
6
7
|
exports.isDateFormat = isDateFormat;
|
|
7
8
|
exports.default = isDateFormat;
|
|
8
9
|
const LRU_1 = __importDefault(require("../caching/LRU"));
|
|
9
10
|
const SPECIAL_CHARS = /[.*+?^${}()|[\]\\]/g;
|
|
10
11
|
const TOKENS = [
|
|
11
12
|
['YYYY', /\d{4}/.source, (raw, context) => {
|
|
12
|
-
context.year =
|
|
13
|
+
context.year = raw | 0;
|
|
13
14
|
return context.year > 0;
|
|
14
15
|
}],
|
|
15
16
|
['MM', /(?:0[1-9]|1[0-2])/.source, (raw, context) => {
|
|
16
|
-
context.month =
|
|
17
|
+
context.month = raw | 0;
|
|
17
18
|
return context.month >= 1 && context.month <= 12;
|
|
18
19
|
}],
|
|
19
20
|
['DD', /(?:0[1-9]|[12][0-9]|3[01])/.source, (raw, context) => {
|
|
20
|
-
context.day =
|
|
21
|
+
context.day = raw | 0;
|
|
21
22
|
return context.day >= 1 && context.day <= 31;
|
|
22
23
|
}],
|
|
23
24
|
['HH', /(?:[01][0-9]|2[0-3])/.source, (raw, context) => {
|
|
24
|
-
context.hour =
|
|
25
|
+
context.hour = raw | 0;
|
|
25
26
|
return context.hour >= 0 && context.hour <= 23;
|
|
26
27
|
}],
|
|
27
28
|
['mm', /[0-5][0-9]/.source, () => true],
|
|
@@ -39,10 +40,10 @@ const TOKENS = [
|
|
|
39
40
|
['Z', /Z|[+-](?:0[0-9]|1[0-4]):[0-5][0-9]/.source, raw => {
|
|
40
41
|
if (raw === 'Z')
|
|
41
42
|
return true;
|
|
42
|
-
let hour =
|
|
43
|
+
let hour = (raw[1] + raw[2]) | 0;
|
|
43
44
|
if (raw[0] === '-')
|
|
44
45
|
hour = -hour;
|
|
45
|
-
const minutes =
|
|
46
|
+
const minutes = (raw[4] + raw[5]) | 0;
|
|
46
47
|
if (hour === 14 || hour === -12)
|
|
47
48
|
return minutes === 0;
|
|
48
49
|
return hour >= -11 && hour < 14 && [0, 15, 30, 45].indexOf(minutes) >= 0;
|
|
@@ -52,6 +53,13 @@ const SPEC_ALIASES = {
|
|
|
52
53
|
ISO: 'YYYY-MM-DDTHH:mm:ss{.SSS}Z',
|
|
53
54
|
};
|
|
54
55
|
const spec_pat_cache = new LRU_1.default({ max_size: 100 });
|
|
56
|
+
exports.MONTHS_LEAP = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
57
|
+
exports.MONTHS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
58
|
+
function isValidDay(year, month, day) {
|
|
59
|
+
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0)
|
|
60
|
+
? day <= exports.MONTHS_LEAP[month - 1]
|
|
61
|
+
: day <= exports.MONTHS[month - 1];
|
|
62
|
+
}
|
|
55
63
|
function compileSpec(spec, is_chunk = false) {
|
|
56
64
|
let cached = spec_pat_cache.get(spec);
|
|
57
65
|
if (cached !== undefined)
|
|
@@ -90,7 +98,7 @@ function compileSpec(spec, is_chunk = false) {
|
|
|
90
98
|
}
|
|
91
99
|
}
|
|
92
100
|
}
|
|
93
|
-
cached = { rgx: is_chunk ? RegExp(pat) : RegExp('^' + pat + '$'), tokens };
|
|
101
|
+
cached = { rgx: is_chunk ? new RegExp(pat) : new RegExp('^' + pat + '$'), tokens };
|
|
94
102
|
spec_pat_cache.set(spec, cached);
|
|
95
103
|
return cached;
|
|
96
104
|
}
|
|
@@ -113,11 +121,8 @@ function isDateFormat(input, spec) {
|
|
|
113
121
|
return false;
|
|
114
122
|
}
|
|
115
123
|
const { is12, day, month, year } = context;
|
|
116
|
-
if (day && month)
|
|
117
|
-
|
|
118
|
-
if (date.getDate() !== day || date.getMonth() !== month - 1)
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
124
|
+
if (day && month && !isValidDay(year || 2024, month, day))
|
|
125
|
+
return false;
|
|
121
126
|
if (is12 && 'hour' in context && context.hour > 11)
|
|
122
127
|
return false;
|
|
123
128
|
return true;
|
package/cjs/deep/get.js
CHANGED
|
@@ -21,8 +21,9 @@ function deepGet(obj, path, get_parent = false) {
|
|
|
21
21
|
if (!key)
|
|
22
22
|
break;
|
|
23
23
|
if (Array.isArray(node)) {
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
let ix = Number(key);
|
|
25
|
+
if (!isNaN(ix)) {
|
|
26
|
+
ix = ix | 0;
|
|
26
27
|
if (ix < 0 || ix > node.length - 1)
|
|
27
28
|
return undefined;
|
|
28
29
|
node = node[ix];
|
|
@@ -53,8 +54,9 @@ function deepGet(obj, path, get_parent = false) {
|
|
|
53
54
|
}
|
|
54
55
|
if (key) {
|
|
55
56
|
if (Array.isArray(node)) {
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
let ix = Number(key);
|
|
58
|
+
if (!isNaN(ix)) {
|
|
59
|
+
ix = ix | 0;
|
|
58
60
|
if (ix < 0 || ix > node.length - 1)
|
|
59
61
|
return undefined;
|
|
60
62
|
node = node[ix];
|
package/cjs/formdata/toObject.js
CHANGED
|
@@ -6,7 +6,7 @@ const isFormat_1 = require("../date/isFormat");
|
|
|
6
6
|
const RGX_TOKENS = /[^.[\]]+/g;
|
|
7
7
|
function assign(acc, rawkey, value, single) {
|
|
8
8
|
let cursor = acc;
|
|
9
|
-
const keys = rawkey.match(RGX_TOKENS);
|
|
9
|
+
const keys = rawkey.match(RGX_TOKENS) || [];
|
|
10
10
|
const keys_len = keys.length;
|
|
11
11
|
for (let i = 0; i < keys_len; i++) {
|
|
12
12
|
const key = keys[i];
|
|
@@ -19,7 +19,7 @@ function assign(acc, rawkey, value, single) {
|
|
|
19
19
|
if (i < (keys_len - 1)) {
|
|
20
20
|
const n_key = Array.isArray(cursor) ? Number(key) : key;
|
|
21
21
|
if (!cursor[n_key])
|
|
22
|
-
cursor[n_key] = Number
|
|
22
|
+
cursor[n_key] = isNaN(Number(keys[i + 1])) ? {} : [];
|
|
23
23
|
cursor = cursor[n_key];
|
|
24
24
|
}
|
|
25
25
|
else if (!(key in cursor) || (single && single.has(key))) {
|
|
@@ -50,12 +50,16 @@ function toObject(form, config) {
|
|
|
50
50
|
const nNumber = config?.normalize_number !== false;
|
|
51
51
|
const acc = {};
|
|
52
52
|
if (set === null) {
|
|
53
|
-
|
|
53
|
+
for (const [key, value] of form) {
|
|
54
|
+
assign(acc, key, value, single);
|
|
55
|
+
}
|
|
56
|
+
return acc;
|
|
54
57
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
for (const [key, value] of form) {
|
|
59
|
+
if (set_guard && set.has(key)) {
|
|
60
|
+
assign(acc, key, value, single);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
59
63
|
switch (value) {
|
|
60
64
|
case 'true':
|
|
61
65
|
case 'TRUE':
|
|
@@ -73,20 +77,23 @@ function toObject(form, config) {
|
|
|
73
77
|
assign(acc, key, nNull ? null : value, single);
|
|
74
78
|
break;
|
|
75
79
|
default: {
|
|
76
|
-
if (typeof value === 'string' && value
|
|
80
|
+
if (typeof value === 'string' && value) {
|
|
77
81
|
if (nNumber) {
|
|
78
82
|
const nVal = Number(value);
|
|
79
|
-
if (!isNaN(nVal))
|
|
80
|
-
|
|
83
|
+
if (!isNaN(nVal)) {
|
|
84
|
+
assign(acc, key, nVal, single);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (nDate && (0, isFormat_1.isDateFormat)(value, 'ISO')) {
|
|
89
|
+
assign(acc, key, new Date(value), single);
|
|
90
|
+
continue;
|
|
81
91
|
}
|
|
82
|
-
if (nDate &&
|
|
83
|
-
(0, isFormat_1.isDateFormat)(value, 'ISO'))
|
|
84
|
-
return assign(acc, key, new Date(value), single);
|
|
85
92
|
}
|
|
86
93
|
assign(acc, key, value, single);
|
|
87
94
|
}
|
|
88
95
|
}
|
|
89
|
-
}
|
|
96
|
+
}
|
|
90
97
|
}
|
|
91
98
|
return acc;
|
|
92
99
|
}
|
package/cjs/modules/Scheduler.js
CHANGED
|
@@ -36,7 +36,7 @@ function convertPart(part, min, max) {
|
|
|
36
36
|
const set = new Set();
|
|
37
37
|
if (part.indexOf('/') > -1) {
|
|
38
38
|
const [base, raw_step] = part.split('/', 2);
|
|
39
|
-
const step =
|
|
39
|
+
const step = raw_step | 0;
|
|
40
40
|
let start;
|
|
41
41
|
let end = max;
|
|
42
42
|
if (base === '*') {
|
|
@@ -44,29 +44,29 @@ function convertPart(part, min, max) {
|
|
|
44
44
|
}
|
|
45
45
|
else if (base.indexOf('-') > -1) {
|
|
46
46
|
const chunks = base.split('-', 2);
|
|
47
|
-
start =
|
|
48
|
-
end =
|
|
47
|
+
start = chunks[0] | 0;
|
|
48
|
+
end = chunks[1] | 0;
|
|
49
49
|
}
|
|
50
50
|
else {
|
|
51
|
-
start =
|
|
51
|
+
start = base | 0;
|
|
52
52
|
}
|
|
53
53
|
for (let i = start; i <= end; i += step)
|
|
54
54
|
set.add(i);
|
|
55
55
|
}
|
|
56
56
|
else if (part.indexOf('-') > -1) {
|
|
57
57
|
const chunks = part.split('-', 2);
|
|
58
|
-
const start =
|
|
59
|
-
const end =
|
|
58
|
+
const start = chunks[0] | 0;
|
|
59
|
+
const end = chunks[1] | 0;
|
|
60
60
|
for (let i = start; i <= end; i++)
|
|
61
61
|
set.add(i);
|
|
62
62
|
}
|
|
63
63
|
else if (part.indexOf(',') > -1) {
|
|
64
64
|
const chunks = part.split(',');
|
|
65
65
|
for (let i = 0; i < chunks.length; i++)
|
|
66
|
-
set.add(
|
|
66
|
+
set.add(chunks[i] | 0);
|
|
67
67
|
}
|
|
68
68
|
else {
|
|
69
|
-
set.add(
|
|
69
|
+
set.add(part | 0);
|
|
70
70
|
}
|
|
71
71
|
return set;
|
|
72
72
|
}
|
package/cjs/object/merge.js
CHANGED
|
@@ -2,33 +2,31 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.merge = merge;
|
|
4
4
|
exports.default = merge;
|
|
5
|
-
const PROTO_OBJ = '[object Object]';
|
|
6
5
|
function innerMerge(target, source, UNION) {
|
|
7
6
|
const origin = UNION ? source : target;
|
|
8
7
|
for (const key in origin) {
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
if (
|
|
12
|
-
Object.prototype.toString.call(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
target[key] = s_key !== undefined ? s_key : t_key;
|
|
8
|
+
const t_val = target[key];
|
|
9
|
+
const s_val = source[key];
|
|
10
|
+
if (s_val !== undefined && t_val !== s_val) {
|
|
11
|
+
target[key] = Object.prototype.toString.call(t_val) === '[object Object]' &&
|
|
12
|
+
Object.prototype.toString.call(s_val) === '[object Object]'
|
|
13
|
+
? innerMerge(t_val, s_val, UNION)
|
|
14
|
+
: s_val;
|
|
17
15
|
}
|
|
18
16
|
}
|
|
19
17
|
return target;
|
|
20
18
|
}
|
|
21
19
|
function merge(target, source, opts = {}) {
|
|
22
|
-
if (Object.prototype.toString.call(target) !==
|
|
20
|
+
if (Object.prototype.toString.call(target) !== '[object Object]')
|
|
23
21
|
throw new Error('object/merge: Please ensure valid target/source is passed');
|
|
24
22
|
const union = opts?.union === true;
|
|
25
23
|
const sources = Array.isArray(source) ? source : [source];
|
|
26
24
|
let acc = { ...target };
|
|
27
25
|
for (let i = 0; i < sources.length; i++) {
|
|
28
26
|
const el = sources[i];
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
if (el &&
|
|
28
|
+
Object.prototype.toString.call(el) === '[object Object]')
|
|
29
|
+
acc = innerMerge(acc, el, union);
|
|
32
30
|
}
|
|
33
31
|
return acc;
|
|
34
32
|
}
|
package/cjs/object/omit.js
CHANGED
|
@@ -4,24 +4,24 @@ exports.omit = omit;
|
|
|
4
4
|
exports.default = omit;
|
|
5
5
|
function innerOmit(obj, keys) {
|
|
6
6
|
const result = { ...obj };
|
|
7
|
-
const groups = {};
|
|
8
7
|
for (let i = 0; i < keys.length; i++) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
const key = keys[i];
|
|
9
|
+
if (typeof key !== 'string')
|
|
10
|
+
continue;
|
|
11
|
+
let target = result;
|
|
12
|
+
const parts = key.split('.');
|
|
13
|
+
const last = parts.length - 1;
|
|
14
|
+
for (let j = 0; j < last; j++) {
|
|
15
|
+
const part = parts[j];
|
|
16
|
+
const val = target[part];
|
|
17
|
+
if (Object.prototype.toString.call(val) === '[object Object]') {
|
|
18
|
+
if (target[part] === obj[part]) {
|
|
19
|
+
target[part] = { ...val };
|
|
20
|
+
}
|
|
21
|
+
target = target[part];
|
|
18
22
|
}
|
|
19
23
|
}
|
|
20
|
-
|
|
21
|
-
for (const root in groups) {
|
|
22
|
-
if (typeof result[root] === 'object' &&
|
|
23
|
-
result[root] !== null)
|
|
24
|
-
result[root] = innerOmit(result[root], groups[root]);
|
|
24
|
+
delete target[parts[last]];
|
|
25
25
|
}
|
|
26
26
|
return result;
|
|
27
27
|
}
|
package/date/isFormat.d.ts
CHANGED
package/esm/date/format.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { convertToDate } from './convertToDate';
|
|
2
|
+
import { MONTHS, MONTHS_LEAP } from './isFormat';
|
|
2
3
|
import LRU from '../caching/LRU';
|
|
3
4
|
const WEEK_STARTS = {
|
|
4
5
|
mon: 'mon',
|
|
@@ -6,13 +7,8 @@ const WEEK_STARTS = {
|
|
|
6
7
|
sat: 'sat',
|
|
7
8
|
};
|
|
8
9
|
let DEFAULT_LOCALE = 'en-US';
|
|
9
|
-
let DEFAULT_TZ = 'UTC';
|
|
10
|
+
let DEFAULT_TZ = Intl?.DateTimeFormat?.().resolvedOptions?.().timeZone || 'UTC';
|
|
10
11
|
let DEFAULT_SOW = 'mon';
|
|
11
|
-
try {
|
|
12
|
-
DEFAULT_TZ = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
13
|
-
}
|
|
14
|
-
catch {
|
|
15
|
-
}
|
|
16
12
|
const ESCAPE_RGX = /\[[\s\S]+?]/g;
|
|
17
13
|
const intl_formatters = new LRU({ max_size: 100 });
|
|
18
14
|
const spec_cache = new LRU({ max_size: 100 });
|
|
@@ -43,7 +39,7 @@ function toZone(d, zone) {
|
|
|
43
39
|
const month = d.getUTCMonth();
|
|
44
40
|
const day = d.getUTCDate();
|
|
45
41
|
const time = d.getTime();
|
|
46
|
-
const daysInMonths =
|
|
42
|
+
const daysInMonths = (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0) ? MONTHS_LEAP : MONTHS;
|
|
47
43
|
let doy = day;
|
|
48
44
|
for (let i = 0; i <= month; i++)
|
|
49
45
|
doy += daysInMonths[i];
|
package/esm/date/isFormat.js
CHANGED
|
@@ -2,19 +2,19 @@ import LRU from '../caching/LRU';
|
|
|
2
2
|
const SPECIAL_CHARS = /[.*+?^${}()|[\]\\]/g;
|
|
3
3
|
const TOKENS = [
|
|
4
4
|
['YYYY', /\d{4}/.source, (raw, context) => {
|
|
5
|
-
context.year =
|
|
5
|
+
context.year = raw | 0;
|
|
6
6
|
return context.year > 0;
|
|
7
7
|
}],
|
|
8
8
|
['MM', /(?:0[1-9]|1[0-2])/.source, (raw, context) => {
|
|
9
|
-
context.month =
|
|
9
|
+
context.month = raw | 0;
|
|
10
10
|
return context.month >= 1 && context.month <= 12;
|
|
11
11
|
}],
|
|
12
12
|
['DD', /(?:0[1-9]|[12][0-9]|3[01])/.source, (raw, context) => {
|
|
13
|
-
context.day =
|
|
13
|
+
context.day = raw | 0;
|
|
14
14
|
return context.day >= 1 && context.day <= 31;
|
|
15
15
|
}],
|
|
16
16
|
['HH', /(?:[01][0-9]|2[0-3])/.source, (raw, context) => {
|
|
17
|
-
context.hour =
|
|
17
|
+
context.hour = raw | 0;
|
|
18
18
|
return context.hour >= 0 && context.hour <= 23;
|
|
19
19
|
}],
|
|
20
20
|
['mm', /[0-5][0-9]/.source, () => true],
|
|
@@ -32,10 +32,10 @@ const TOKENS = [
|
|
|
32
32
|
['Z', /Z|[+-](?:0[0-9]|1[0-4]):[0-5][0-9]/.source, raw => {
|
|
33
33
|
if (raw === 'Z')
|
|
34
34
|
return true;
|
|
35
|
-
let hour =
|
|
35
|
+
let hour = (raw[1] + raw[2]) | 0;
|
|
36
36
|
if (raw[0] === '-')
|
|
37
37
|
hour = -hour;
|
|
38
|
-
const minutes =
|
|
38
|
+
const minutes = (raw[4] + raw[5]) | 0;
|
|
39
39
|
if (hour === 14 || hour === -12)
|
|
40
40
|
return minutes === 0;
|
|
41
41
|
return hour >= -11 && hour < 14 && [0, 15, 30, 45].indexOf(minutes) >= 0;
|
|
@@ -45,6 +45,13 @@ const SPEC_ALIASES = {
|
|
|
45
45
|
ISO: 'YYYY-MM-DDTHH:mm:ss{.SSS}Z',
|
|
46
46
|
};
|
|
47
47
|
const spec_pat_cache = new LRU({ max_size: 100 });
|
|
48
|
+
export const MONTHS_LEAP = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
49
|
+
export const MONTHS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
50
|
+
function isValidDay(year, month, day) {
|
|
51
|
+
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0)
|
|
52
|
+
? day <= MONTHS_LEAP[month - 1]
|
|
53
|
+
: day <= MONTHS[month - 1];
|
|
54
|
+
}
|
|
48
55
|
function compileSpec(spec, is_chunk = false) {
|
|
49
56
|
let cached = spec_pat_cache.get(spec);
|
|
50
57
|
if (cached !== undefined)
|
|
@@ -83,7 +90,7 @@ function compileSpec(spec, is_chunk = false) {
|
|
|
83
90
|
}
|
|
84
91
|
}
|
|
85
92
|
}
|
|
86
|
-
cached = { rgx: is_chunk ? RegExp(pat) : RegExp('^' + pat + '$'), tokens };
|
|
93
|
+
cached = { rgx: is_chunk ? new RegExp(pat) : new RegExp('^' + pat + '$'), tokens };
|
|
87
94
|
spec_pat_cache.set(spec, cached);
|
|
88
95
|
return cached;
|
|
89
96
|
}
|
|
@@ -106,11 +113,8 @@ function isDateFormat(input, spec) {
|
|
|
106
113
|
return false;
|
|
107
114
|
}
|
|
108
115
|
const { is12, day, month, year } = context;
|
|
109
|
-
if (day && month)
|
|
110
|
-
|
|
111
|
-
if (date.getDate() !== day || date.getMonth() !== month - 1)
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
116
|
+
if (day && month && !isValidDay(year || 2024, month, day))
|
|
117
|
+
return false;
|
|
114
118
|
if (is12 && 'hour' in context && context.hour > 11)
|
|
115
119
|
return false;
|
|
116
120
|
return true;
|
package/esm/deep/get.js
CHANGED
|
@@ -17,8 +17,9 @@ function deepGet(obj, path, get_parent = false) {
|
|
|
17
17
|
if (!key)
|
|
18
18
|
break;
|
|
19
19
|
if (Array.isArray(node)) {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
let ix = Number(key);
|
|
21
|
+
if (!isNaN(ix)) {
|
|
22
|
+
ix = ix | 0;
|
|
22
23
|
if (ix < 0 || ix > node.length - 1)
|
|
23
24
|
return undefined;
|
|
24
25
|
node = node[ix];
|
|
@@ -49,8 +50,9 @@ function deepGet(obj, path, get_parent = false) {
|
|
|
49
50
|
}
|
|
50
51
|
if (key) {
|
|
51
52
|
if (Array.isArray(node)) {
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
let ix = Number(key);
|
|
54
|
+
if (!isNaN(ix)) {
|
|
55
|
+
ix = ix | 0;
|
|
54
56
|
if (ix < 0 || ix > node.length - 1)
|
|
55
57
|
return undefined;
|
|
56
58
|
node = node[ix];
|
package/esm/formdata/toObject.js
CHANGED
|
@@ -2,7 +2,7 @@ import { isDateFormat } from '../date/isFormat';
|
|
|
2
2
|
const RGX_TOKENS = /[^.[\]]+/g;
|
|
3
3
|
function assign(acc, rawkey, value, single) {
|
|
4
4
|
let cursor = acc;
|
|
5
|
-
const keys = rawkey.match(RGX_TOKENS);
|
|
5
|
+
const keys = rawkey.match(RGX_TOKENS) || [];
|
|
6
6
|
const keys_len = keys.length;
|
|
7
7
|
for (let i = 0; i < keys_len; i++) {
|
|
8
8
|
const key = keys[i];
|
|
@@ -15,7 +15,7 @@ function assign(acc, rawkey, value, single) {
|
|
|
15
15
|
if (i < (keys_len - 1)) {
|
|
16
16
|
const n_key = Array.isArray(cursor) ? Number(key) : key;
|
|
17
17
|
if (!cursor[n_key])
|
|
18
|
-
cursor[n_key] = Number
|
|
18
|
+
cursor[n_key] = isNaN(Number(keys[i + 1])) ? {} : [];
|
|
19
19
|
cursor = cursor[n_key];
|
|
20
20
|
}
|
|
21
21
|
else if (!(key in cursor) || (single && single.has(key))) {
|
|
@@ -46,12 +46,16 @@ function toObject(form, config) {
|
|
|
46
46
|
const nNumber = config?.normalize_number !== false;
|
|
47
47
|
const acc = {};
|
|
48
48
|
if (set === null) {
|
|
49
|
-
|
|
49
|
+
for (const [key, value] of form) {
|
|
50
|
+
assign(acc, key, value, single);
|
|
51
|
+
}
|
|
52
|
+
return acc;
|
|
50
53
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
for (const [key, value] of form) {
|
|
55
|
+
if (set_guard && set.has(key)) {
|
|
56
|
+
assign(acc, key, value, single);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
55
59
|
switch (value) {
|
|
56
60
|
case 'true':
|
|
57
61
|
case 'TRUE':
|
|
@@ -69,20 +73,23 @@ function toObject(form, config) {
|
|
|
69
73
|
assign(acc, key, nNull ? null : value, single);
|
|
70
74
|
break;
|
|
71
75
|
default: {
|
|
72
|
-
if (typeof value === 'string' && value
|
|
76
|
+
if (typeof value === 'string' && value) {
|
|
73
77
|
if (nNumber) {
|
|
74
78
|
const nVal = Number(value);
|
|
75
|
-
if (!isNaN(nVal))
|
|
76
|
-
|
|
79
|
+
if (!isNaN(nVal)) {
|
|
80
|
+
assign(acc, key, nVal, single);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (nDate && isDateFormat(value, 'ISO')) {
|
|
85
|
+
assign(acc, key, new Date(value), single);
|
|
86
|
+
continue;
|
|
77
87
|
}
|
|
78
|
-
if (nDate &&
|
|
79
|
-
isDateFormat(value, 'ISO'))
|
|
80
|
-
return assign(acc, key, new Date(value), single);
|
|
81
88
|
}
|
|
82
89
|
assign(acc, key, value, single);
|
|
83
90
|
}
|
|
84
91
|
}
|
|
85
|
-
}
|
|
92
|
+
}
|
|
86
93
|
}
|
|
87
94
|
return acc;
|
|
88
95
|
}
|
package/esm/modules/Scheduler.js
CHANGED
|
@@ -33,7 +33,7 @@ function convertPart(part, min, max) {
|
|
|
33
33
|
const set = new Set();
|
|
34
34
|
if (part.indexOf('/') > -1) {
|
|
35
35
|
const [base, raw_step] = part.split('/', 2);
|
|
36
|
-
const step =
|
|
36
|
+
const step = raw_step | 0;
|
|
37
37
|
let start;
|
|
38
38
|
let end = max;
|
|
39
39
|
if (base === '*') {
|
|
@@ -41,29 +41,29 @@ function convertPart(part, min, max) {
|
|
|
41
41
|
}
|
|
42
42
|
else if (base.indexOf('-') > -1) {
|
|
43
43
|
const chunks = base.split('-', 2);
|
|
44
|
-
start =
|
|
45
|
-
end =
|
|
44
|
+
start = chunks[0] | 0;
|
|
45
|
+
end = chunks[1] | 0;
|
|
46
46
|
}
|
|
47
47
|
else {
|
|
48
|
-
start =
|
|
48
|
+
start = base | 0;
|
|
49
49
|
}
|
|
50
50
|
for (let i = start; i <= end; i += step)
|
|
51
51
|
set.add(i);
|
|
52
52
|
}
|
|
53
53
|
else if (part.indexOf('-') > -1) {
|
|
54
54
|
const chunks = part.split('-', 2);
|
|
55
|
-
const start =
|
|
56
|
-
const end =
|
|
55
|
+
const start = chunks[0] | 0;
|
|
56
|
+
const end = chunks[1] | 0;
|
|
57
57
|
for (let i = start; i <= end; i++)
|
|
58
58
|
set.add(i);
|
|
59
59
|
}
|
|
60
60
|
else if (part.indexOf(',') > -1) {
|
|
61
61
|
const chunks = part.split(',');
|
|
62
62
|
for (let i = 0; i < chunks.length; i++)
|
|
63
|
-
set.add(
|
|
63
|
+
set.add(chunks[i] | 0);
|
|
64
64
|
}
|
|
65
65
|
else {
|
|
66
|
-
set.add(
|
|
66
|
+
set.add(part | 0);
|
|
67
67
|
}
|
|
68
68
|
return set;
|
|
69
69
|
}
|
package/esm/object/merge.js
CHANGED
|
@@ -1,30 +1,28 @@
|
|
|
1
|
-
const PROTO_OBJ = '[object Object]';
|
|
2
1
|
function innerMerge(target, source, UNION) {
|
|
3
2
|
const origin = UNION ? source : target;
|
|
4
3
|
for (const key in origin) {
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
if (
|
|
8
|
-
Object.prototype.toString.call(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
target[key] = s_key !== undefined ? s_key : t_key;
|
|
4
|
+
const t_val = target[key];
|
|
5
|
+
const s_val = source[key];
|
|
6
|
+
if (s_val !== undefined && t_val !== s_val) {
|
|
7
|
+
target[key] = Object.prototype.toString.call(t_val) === '[object Object]' &&
|
|
8
|
+
Object.prototype.toString.call(s_val) === '[object Object]'
|
|
9
|
+
? innerMerge(t_val, s_val, UNION)
|
|
10
|
+
: s_val;
|
|
13
11
|
}
|
|
14
12
|
}
|
|
15
13
|
return target;
|
|
16
14
|
}
|
|
17
15
|
function merge(target, source, opts = {}) {
|
|
18
|
-
if (Object.prototype.toString.call(target) !==
|
|
16
|
+
if (Object.prototype.toString.call(target) !== '[object Object]')
|
|
19
17
|
throw new Error('object/merge: Please ensure valid target/source is passed');
|
|
20
18
|
const union = opts?.union === true;
|
|
21
19
|
const sources = Array.isArray(source) ? source : [source];
|
|
22
20
|
let acc = { ...target };
|
|
23
21
|
for (let i = 0; i < sources.length; i++) {
|
|
24
22
|
const el = sources[i];
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
if (el &&
|
|
24
|
+
Object.prototype.toString.call(el) === '[object Object]')
|
|
25
|
+
acc = innerMerge(acc, el, union);
|
|
28
26
|
}
|
|
29
27
|
return acc;
|
|
30
28
|
}
|