@valkyriestudios/utils 10.0.0 → 11.1.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/README.md +1 -1
- package/dist/array/dedupe.d.ts +8 -0
- package/dist/array/dedupe.js +19 -0
- package/dist/array/is.d.ts +8 -0
- package/dist/array/is.js +6 -0
- package/dist/array/isNotEmpty.d.ts +8 -0
- package/dist/array/isNotEmpty.js +6 -0
- package/dist/array/join.d.ts +36 -0
- package/dist/array/join.js +24 -0
- package/dist/array/mapFn.d.ts +40 -0
- package/{src/array/mapFn.mjs → dist/array/mapFn.js} +13 -15
- package/dist/array/mapKey.d.ts +38 -0
- package/dist/array/mapKey.js +27 -0
- package/dist/array/mapPrimitive.d.ts +40 -0
- package/dist/array/mapPrimitive.js +27 -0
- package/dist/array/shuffle.d.ts +9 -0
- package/dist/array/shuffle.js +11 -0
- package/dist/array/sort.d.ts +58 -0
- package/dist/array/sort.js +92 -0
- package/dist/boolean/is.d.ts +8 -0
- package/dist/boolean/is.js +6 -0
- package/dist/caching/memoize.d.ts +10 -0
- package/dist/caching/memoize.js +15 -0
- package/dist/date/addUTC.d.ts +10 -0
- package/{src/date/addUTC.mjs → dist/date/addUTC.js} +11 -26
- package/dist/date/diff.d.ts +10 -0
- package/dist/date/diff.js +38 -0
- package/dist/date/endOfUTC.d.ts +9 -0
- package/dist/date/endOfUTC.js +52 -0
- package/dist/date/is.d.ts +8 -0
- package/dist/date/is.js +6 -0
- package/dist/date/nowUnix.d.ts +6 -0
- package/dist/date/nowUnix.js +6 -0
- package/dist/date/nowUnixMs.d.ts +6 -0
- package/dist/date/nowUnixMs.js +6 -0
- package/dist/date/startOfUTC.d.ts +9 -0
- package/dist/date/startOfUTC.js +52 -0
- package/dist/date/toUTC.d.ts +8 -0
- package/dist/date/toUTC.js +9 -0
- package/dist/date/toUnix.d.ts +8 -0
- package/dist/date/toUnix.js +9 -0
- package/dist/deep/freeze.d.ts +14 -0
- package/dist/deep/freeze.js +23 -0
- package/dist/deep/get.d.ts +27 -0
- package/dist/deep/get.js +41 -0
- package/dist/deep/seal.d.ts +14 -0
- package/dist/deep/seal.js +23 -0
- package/dist/deep/set.d.ts +42 -0
- package/dist/deep/set.js +52 -0
- package/dist/equal.d.ts +10 -0
- package/dist/equal.js +43 -0
- package/dist/function/is.d.ts +8 -0
- package/dist/function/is.js +6 -0
- package/dist/function/noop.d.ts +6 -0
- package/dist/function/noop.js +5 -0
- package/dist/function/noopresolve.d.ts +9 -0
- package/dist/function/noopresolve.js +6 -0
- package/dist/function/noopreturn.d.ts +8 -0
- package/dist/function/noopreturn.js +6 -0
- package/dist/function/sleep.d.ts +9 -0
- package/dist/function/sleep.js +8 -0
- package/dist/hash/fnv1A.d.ts +10 -0
- package/dist/hash/fnv1A.js +51 -0
- package/dist/hash/guid.d.ts +6 -0
- package/{src/hash/guid.mjs → dist/hash/guid.js} +9 -14
- package/dist/index.d.ts +358 -0
- package/dist/is.d.ts +75 -0
- package/dist/is.js +77 -0
- package/dist/number/is.d.ts +8 -0
- package/dist/number/is.js +6 -0
- package/dist/number/isAbove.d.ts +9 -0
- package/dist/number/isAbove.js +6 -0
- package/dist/number/isAboveOrEqual.d.ts +9 -0
- package/dist/number/isAboveOrEqual.js +6 -0
- package/dist/number/isBelow.d.ts +9 -0
- package/dist/number/isBelow.js +6 -0
- package/dist/number/isBelowOrEqual.d.ts +10 -0
- package/dist/number/isBelowOrEqual.js +6 -0
- package/dist/number/isBetween.d.ts +12 -0
- package/dist/number/isBetween.js +11 -0
- package/dist/number/isInteger.d.ts +8 -0
- package/dist/number/isInteger.js +6 -0
- package/dist/number/isIntegerAbove.d.ts +9 -0
- package/dist/number/isIntegerAbove.js +6 -0
- package/dist/number/isIntegerAboveOrEqual.d.ts +10 -0
- package/dist/number/isIntegerAboveOrEqual.js +6 -0
- package/dist/number/isIntegerBelow.d.ts +9 -0
- package/dist/number/isIntegerBelow.js +6 -0
- package/dist/number/isIntegerBelowOrEqual.d.ts +10 -0
- package/dist/number/isIntegerBelowOrEqual.js +6 -0
- package/dist/number/isIntegerBetween.d.ts +12 -0
- package/dist/number/isIntegerBetween.js +11 -0
- package/dist/number/isNumericalNaN.d.ts +8 -0
- package/dist/number/isNumericalNaN.js +6 -0
- package/dist/number/randomBetween.d.ts +9 -0
- package/dist/number/randomBetween.js +9 -0
- package/dist/number/randomIntBetween.d.ts +10 -0
- package/dist/number/randomIntBetween.js +9 -0
- package/dist/number/round.d.ts +9 -0
- package/dist/number/round.js +10 -0
- package/dist/number/toPercentage.d.ts +11 -0
- package/dist/number/toPercentage.js +11 -0
- package/dist/object/define.d.ts +15 -0
- package/dist/object/define.js +9 -0
- package/dist/object/is.d.ts +8 -0
- package/dist/object/is.js +7 -0
- package/dist/object/isNotEmpty.d.ts +8 -0
- package/dist/object/isNotEmpty.js +6 -0
- package/dist/object/merge.d.ts +18 -0
- package/dist/object/merge.js +20 -0
- package/dist/object/pick.d.ts +13 -0
- package/dist/object/pick.js +34 -0
- package/dist/regexp/is.d.ts +8 -0
- package/dist/regexp/is.js +6 -0
- package/dist/regexp/sanitize.d.ts +11 -0
- package/dist/regexp/sanitize.js +8 -0
- package/dist/string/humanizeBytes.d.ts +40 -0
- package/{src/string/humanizeBytes.mjs → dist/string/humanizeBytes.js} +7 -10
- package/dist/string/humanizeNumber.d.ts +52 -0
- package/dist/string/humanizeNumber.js +60 -0
- package/dist/string/is.d.ts +8 -0
- package/dist/string/is.js +6 -0
- package/dist/string/isBetween.d.ts +13 -0
- package/dist/string/isBetween.js +14 -0
- package/dist/string/isNotEmpty.d.ts +9 -0
- package/dist/string/isNotEmpty.js +8 -0
- package/dist/string/shorten.d.ts +10 -0
- package/dist/string/shorten.js +11 -0
- package/package.json +112 -46
- package/tsconfig.types.json +12 -0
- package/tsconfig.types_all.json +12 -0
- package/array/dedupe.js +0 -33
- package/array/is.js +0 -9
- package/array/isNotEmpty.js +0 -9
- package/array/join.js +0 -38
- package/array/mapFn.js +0 -37
- package/array/mapKey.js +0 -36
- package/array/mapPrimitive.js +0 -38
- package/array/shuffle.js +0 -14
- package/array/sort.js +0 -125
- package/boolean/is.js +0 -9
- package/caching/memoize.js +0 -19
- package/date/addUTC.js +0 -60
- package/date/diff.js +0 -40
- package/date/endOfUTC.js +0 -55
- package/date/is.js +0 -9
- package/date/nowUnix.js +0 -9
- package/date/nowUnixMs.js +0 -9
- package/date/startOfUTC.js +0 -55
- package/date/toUTC.js +0 -12
- package/date/toUnix.js +0 -12
- package/deep/define.js +0 -12
- package/deep/freeze.js +0 -17
- package/deep/get.js +0 -29
- package/deep/seal.js +0 -17
- package/deep/set.js +0 -26
- package/equal.js +0 -35
- package/function/is.js +0 -8
- package/function/noop.js +0 -7
- package/function/noopresolve.js +0 -10
- package/function/noopreturn.js +0 -8
- package/function/sleep.js +0 -13
- package/hash/fnv1A.js +0 -44
- package/hash/guid.js +0 -16
- package/is.js +0 -319
- package/number/is.js +0 -9
- package/number/isAbove.js +0 -8
- package/number/isAboveOrEqual.js +0 -8
- package/number/isBelow.js +0 -8
- package/number/isBelowOrEqual.js +0 -8
- package/number/isBetween.js +0 -9
- package/number/isInteger.js +0 -9
- package/number/isIntegerAbove.js +0 -8
- package/number/isIntegerAboveOrEqual.js +0 -8
- package/number/isIntegerBelow.js +0 -8
- package/number/isIntegerBelowOrEqual.js +0 -8
- package/number/isIntegerBetween.js +0 -9
- package/number/isNumericalNaN.js +0 -9
- package/number/randomBetween.js +0 -11
- package/number/randomIntBetween.js +0 -11
- package/number/round.js +0 -12
- package/number/toPercentage.js +0 -15
- package/object/define.js +0 -11
- package/object/is.js +0 -10
- package/object/isNotEmpty.js +0 -9
- package/object/merge.js +0 -19
- package/object/pick.js +0 -41
- package/regexp/is.js +0 -9
- package/regexp/sanitize.js +0 -9
- package/src/array/dedupe.mjs +0 -24
- package/src/array/is.mjs +0 -5
- package/src/array/isNotEmpty.mjs +0 -5
- package/src/array/join.mjs +0 -29
- package/src/array/mapKey.mjs +0 -31
- package/src/array/mapPrimitive.mjs +0 -30
- package/src/array/shuffle.mjs +0 -14
- package/src/array/sort.mjs +0 -101
- package/src/boolean/is.mjs +0 -5
- package/src/caching/memoize.mjs +0 -22
- package/src/date/diff.mjs +0 -46
- package/src/date/endOfUTC.mjs +0 -130
- package/src/date/is.mjs +0 -5
- package/src/date/nowUnix.mjs +0 -5
- package/src/date/nowUnixMs.mjs +0 -5
- package/src/date/startOfUTC.mjs +0 -129
- package/src/date/toUTC.mjs +0 -19
- package/src/date/toUnix.mjs +0 -11
- package/src/deep/define.mjs +0 -7
- package/src/deep/freeze.mjs +0 -20
- package/src/deep/get.mjs +0 -52
- package/src/deep/seal.mjs +0 -20
- package/src/deep/set.mjs +0 -46
- package/src/equal.mjs +0 -65
- package/src/function/is.mjs +0 -6
- package/src/function/noop.mjs +0 -5
- package/src/function/noopresolve.mjs +0 -6
- package/src/function/noopreturn.mjs +0 -6
- package/src/function/sleep.mjs +0 -12
- package/src/hash/fnv1A.mjs +0 -53
- package/src/is.mjs +0 -86
- package/src/number/is.mjs +0 -5
- package/src/number/isAbove.mjs +0 -6
- package/src/number/isAboveOrEqual.mjs +0 -6
- package/src/number/isBelow.mjs +0 -6
- package/src/number/isBelowOrEqual.mjs +0 -6
- package/src/number/isBetween.mjs +0 -13
- package/src/number/isInteger.mjs +0 -5
- package/src/number/isIntegerAbove.mjs +0 -6
- package/src/number/isIntegerAboveOrEqual.mjs +0 -6
- package/src/number/isIntegerBelow.mjs +0 -6
- package/src/number/isIntegerBelowOrEqual.mjs +0 -6
- package/src/number/isIntegerBetween.mjs +0 -13
- package/src/number/isNumericalNaN.mjs +0 -5
- package/src/number/randomBetween.mjs +0 -11
- package/src/number/randomIntBetween.mjs +0 -11
- package/src/number/round.mjs +0 -10
- package/src/number/toPercentage.mjs +0 -14
- package/src/object/define.mjs +0 -10
- package/src/object/is.mjs +0 -7
- package/src/object/isNotEmpty.mjs +0 -5
- package/src/object/merge.mjs +0 -25
- package/src/object/pick.mjs +0 -35
- package/src/regexp/is.mjs +0 -5
- package/src/regexp/sanitize.mjs +0 -10
- package/src/string/humanizeNumber.mjs +0 -82
- package/src/string/is.mjs +0 -5
- package/src/string/isBetween.mjs +0 -16
- package/src/string/isNotEmpty.mjs +0 -6
- package/src/string/shorten.mjs +0 -20
- package/string/humanizeBytes.js +0 -21
- package/string/humanizeNumber.js +0 -54
- package/string/is.js +0 -9
- package/string/isBetween.js +0 -11
- package/string/isNotEmpty.js +0 -11
- package/string/shorten.js +0 -11
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const is_1 = require("./is");
|
|
4
|
+
const SECOND_IN_MILLISECONDS = 1000;
|
|
5
|
+
const MINUTE_IN_MILLISECONDS = SECOND_IN_MILLISECONDS * 60;
|
|
6
|
+
const HOUR_IN_MILLISECONDS = MINUTE_IN_MILLISECONDS * 60;
|
|
7
|
+
const DAY_IN_MILLISECONDS = HOUR_IN_MILLISECONDS * 24;
|
|
8
|
+
const WEEK_IN_MILLISECONDS = DAY_IN_MILLISECONDS * 7;
|
|
9
|
+
function diff(val_a, val_b, key = 'millisecond') {
|
|
10
|
+
if (!(0, is_1.default)(val_a) ||
|
|
11
|
+
!(0, is_1.default)(val_b))
|
|
12
|
+
throw new TypeError('Diff requires date objects for both values');
|
|
13
|
+
if (typeof key !== 'string')
|
|
14
|
+
throw new TypeError('Key needs to be a string');
|
|
15
|
+
const diff_in_ms = val_a.valueOf() - val_b.valueOf();
|
|
16
|
+
switch (key) {
|
|
17
|
+
case 'week':
|
|
18
|
+
case 'weeks':
|
|
19
|
+
return diff_in_ms / WEEK_IN_MILLISECONDS;
|
|
20
|
+
case 'day':
|
|
21
|
+
case 'days':
|
|
22
|
+
return diff_in_ms / DAY_IN_MILLISECONDS;
|
|
23
|
+
case 'hour':
|
|
24
|
+
case 'hours':
|
|
25
|
+
return diff_in_ms / HOUR_IN_MILLISECONDS;
|
|
26
|
+
case 'minute':
|
|
27
|
+
case 'minutes':
|
|
28
|
+
return diff_in_ms / MINUTE_IN_MILLISECONDS;
|
|
29
|
+
case 'second':
|
|
30
|
+
case 'seconds':
|
|
31
|
+
return diff_in_ms / SECOND_IN_MILLISECONDS;
|
|
32
|
+
case 'millisecond':
|
|
33
|
+
case 'milliseconds':
|
|
34
|
+
default:
|
|
35
|
+
return diff_in_ms;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.default = diff;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sets the provided date to end of UTC of provided key
|
|
3
|
+
*
|
|
4
|
+
* @param val - Date to set to end of
|
|
5
|
+
* @param key - (default='millisecond') Key to set
|
|
6
|
+
*
|
|
7
|
+
* @returns New date set to end of key
|
|
8
|
+
*/
|
|
9
|
+
export default function endOfUTC(val: Date, key?: 'year' | 'quarter' | 'month' | 'week' | 'week_sun' | 'week_mon' | 'week_tue' | 'week_wed' | 'week_thu' | 'week_fri' | 'week_sat' | 'day' | 'hour' | 'minute' | 'second' | 'millisecond'): Date;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const is_1 = require("./is");
|
|
4
|
+
const WEEK_END = {
|
|
5
|
+
week: 0,
|
|
6
|
+
week_sun: 6,
|
|
7
|
+
week_mon: 0,
|
|
8
|
+
week_tue: 1,
|
|
9
|
+
week_wed: 2,
|
|
10
|
+
week_thu: 3,
|
|
11
|
+
week_fri: 4,
|
|
12
|
+
week_sat: 5,
|
|
13
|
+
};
|
|
14
|
+
function endOfUTC(val, key = 'millisecond') {
|
|
15
|
+
if (!(0, is_1.default)(val))
|
|
16
|
+
throw new TypeError('endOfUTC requires a date object');
|
|
17
|
+
if (typeof key !== 'string')
|
|
18
|
+
throw new TypeError('Key needs to be a string with content');
|
|
19
|
+
switch (key) {
|
|
20
|
+
case 'year':
|
|
21
|
+
return new Date(Date.UTC(val.getUTCFullYear(), 11, 31, 23, 59, 59, 999));
|
|
22
|
+
case 'quarter': {
|
|
23
|
+
return new Date(Date.UTC(val.getUTCFullYear(), (val.getUTCMonth() - (val.getUTCMonth() % 3)) + 3, 0, 23, 59, 59, 999));
|
|
24
|
+
}
|
|
25
|
+
case 'month':
|
|
26
|
+
return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth() + 1, 0, 23, 59, 59, 999));
|
|
27
|
+
case 'week':
|
|
28
|
+
case 'week_sun':
|
|
29
|
+
case 'week_mon':
|
|
30
|
+
case 'week_tue':
|
|
31
|
+
case 'week_wed':
|
|
32
|
+
case 'week_thu':
|
|
33
|
+
case 'week_fri':
|
|
34
|
+
case 'week_sat': {
|
|
35
|
+
const UTC_DAY = val.getUTCDay();
|
|
36
|
+
const UTC_EOD = WEEK_END[key];
|
|
37
|
+
return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate() + (UTC_DAY <= UTC_EOD ? UTC_EOD - UTC_DAY : (7 - UTC_DAY) + UTC_EOD), 23, 59, 59, 999));
|
|
38
|
+
}
|
|
39
|
+
case 'day':
|
|
40
|
+
return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), 23, 59, 59, 999));
|
|
41
|
+
case 'hour':
|
|
42
|
+
return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), val.getUTCHours(), 59, 59, 999));
|
|
43
|
+
case 'minute':
|
|
44
|
+
return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), val.getUTCHours(), val.getUTCMinutes(), 59, 999));
|
|
45
|
+
case 'second':
|
|
46
|
+
return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), val.getUTCHours(), val.getUTCMinutes(), val.getUTCSeconds(), 999));
|
|
47
|
+
case 'millisecond':
|
|
48
|
+
default:
|
|
49
|
+
return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), val.getUTCHours(), val.getUTCMinutes(), val.getUTCSeconds(), val.getUTCMilliseconds()));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.default = endOfUTC;
|
package/dist/date/is.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sets the provided date to start of UTC of provided key
|
|
3
|
+
*
|
|
4
|
+
* @param val - Date to set to start of
|
|
5
|
+
* @param key - (default='millisecond') Key to set
|
|
6
|
+
*
|
|
7
|
+
* @returns New date set to start of key
|
|
8
|
+
*/
|
|
9
|
+
export default function startOfUTC(val: Date, key?: 'year' | 'quarter' | 'month' | 'week' | 'week_sun' | 'week_mon' | 'week_tue' | 'week_wed' | 'week_thu' | 'week_fri' | 'week_sat' | 'day' | 'hour' | 'minute' | 'second' | 'millisecond'): Date;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const is_1 = require("./is");
|
|
4
|
+
const WEEK_START = {
|
|
5
|
+
week: 1,
|
|
6
|
+
week_sun: 0,
|
|
7
|
+
week_mon: 1,
|
|
8
|
+
week_tue: 2,
|
|
9
|
+
week_wed: 3,
|
|
10
|
+
week_thu: 4,
|
|
11
|
+
week_fri: 5,
|
|
12
|
+
week_sat: 6,
|
|
13
|
+
};
|
|
14
|
+
function startOfUTC(val, key = 'millisecond') {
|
|
15
|
+
if (!(0, is_1.default)(val))
|
|
16
|
+
throw new TypeError('startOfUTC requires a date object');
|
|
17
|
+
if (typeof key !== 'string')
|
|
18
|
+
throw new TypeError('Key needs to be a string with content');
|
|
19
|
+
switch (key) {
|
|
20
|
+
case 'year':
|
|
21
|
+
return new Date(Date.UTC(val.getUTCFullYear(), 0, 1, 0, 0, 0, 0));
|
|
22
|
+
case 'quarter': {
|
|
23
|
+
return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth() - (val.getUTCMonth() % 3), 1, 0, 0, 0, 0));
|
|
24
|
+
}
|
|
25
|
+
case 'month':
|
|
26
|
+
return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), 1, 0, 0, 0, 0));
|
|
27
|
+
case 'week':
|
|
28
|
+
case 'week_sun':
|
|
29
|
+
case 'week_mon':
|
|
30
|
+
case 'week_tue':
|
|
31
|
+
case 'week_wed':
|
|
32
|
+
case 'week_thu':
|
|
33
|
+
case 'week_fri':
|
|
34
|
+
case 'week_sat': {
|
|
35
|
+
const UTC_DAY = val.getUTCDay();
|
|
36
|
+
const UTC_SOD = WEEK_START[key];
|
|
37
|
+
return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate() - (UTC_DAY < UTC_SOD ? (7 - UTC_SOD) + UTC_DAY : UTC_DAY - UTC_SOD), 0, 0, 0, 0));
|
|
38
|
+
}
|
|
39
|
+
case 'day':
|
|
40
|
+
return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), 0, 0, 0, 0));
|
|
41
|
+
case 'hour':
|
|
42
|
+
return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), val.getUTCHours(), 0, 0, 0));
|
|
43
|
+
case 'minute':
|
|
44
|
+
return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), val.getUTCHours(), val.getUTCMinutes(), 0, 0));
|
|
45
|
+
case 'second':
|
|
46
|
+
return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), val.getUTCHours(), val.getUTCMinutes(), val.getUTCSeconds(), 0));
|
|
47
|
+
case 'millisecond':
|
|
48
|
+
default:
|
|
49
|
+
return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), val.getUTCHours(), val.getUTCMinutes(), val.getUTCSeconds(), val.getUTCMilliseconds()));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.default = startOfUTC;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const is_1 = require("./is");
|
|
4
|
+
function toUTC(val) {
|
|
5
|
+
if (!(0, is_1.default)(val))
|
|
6
|
+
throw new TypeError('toUTC requires a date object');
|
|
7
|
+
return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), val.getUTCHours(), val.getUTCMinutes(), val.getUTCSeconds(), val.getUTCMilliseconds()));
|
|
8
|
+
}
|
|
9
|
+
exports.default = toUTC;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const is_1 = require("./is");
|
|
4
|
+
function toUnix(val) {
|
|
5
|
+
if (!(0, is_1.default)(val))
|
|
6
|
+
throw new TypeError('toUnix requires a date object');
|
|
7
|
+
return Math.floor(val.valueOf() / 1000);
|
|
8
|
+
}
|
|
9
|
+
exports.default = toUnix;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type deepInput = {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
} | {
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
}[] | any[];
|
|
6
|
+
/**
|
|
7
|
+
* Recursively freezes all properties of an object
|
|
8
|
+
*
|
|
9
|
+
* @param obj - Object to deep freeze
|
|
10
|
+
*
|
|
11
|
+
* @returns Deeply frozen object
|
|
12
|
+
*/
|
|
13
|
+
export default function deepFreeze(obj: deepInput): Readonly<deepInput>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function deep(obj) {
|
|
4
|
+
if (Array.isArray(obj)) {
|
|
5
|
+
for (const el of obj)
|
|
6
|
+
deep(el);
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
for (const key of Object.keys(obj)) {
|
|
10
|
+
if (Object.prototype.toString.call(obj[key]) === '[object Object]' ||
|
|
11
|
+
Array.isArray(obj[key]))
|
|
12
|
+
deep(obj[key]);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return Object.freeze(obj);
|
|
16
|
+
}
|
|
17
|
+
function deepFreeze(obj) {
|
|
18
|
+
if (Object.prototype.toString.call(obj) !== '[object Object]' &&
|
|
19
|
+
!Array.isArray(obj))
|
|
20
|
+
throw new TypeError('Only objects/arrays can be frozen');
|
|
21
|
+
return deep(obj);
|
|
22
|
+
}
|
|
23
|
+
exports.default = deepFreeze;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get a property's value deep inside the structure of an array/object
|
|
3
|
+
*
|
|
4
|
+
* Example:
|
|
5
|
+
* const myObj = {
|
|
6
|
+
* a: 2,
|
|
7
|
+
* b: [
|
|
8
|
+
* {price : 2},
|
|
9
|
+
* {price : 4},
|
|
10
|
+
* ],
|
|
11
|
+
* };
|
|
12
|
+
* deepGet(myObj, 'b[0].price');
|
|
13
|
+
* Output:
|
|
14
|
+
* 2
|
|
15
|
+
*
|
|
16
|
+
* @param val - Object/Array to get the value from
|
|
17
|
+
* @param path - Path string to deeply get the value at
|
|
18
|
+
* @param get_parent - If passed as true retrieves the parent of where the value lives
|
|
19
|
+
*
|
|
20
|
+
* @returns Value stored at property or undefined
|
|
21
|
+
* @throws {TypeError}
|
|
22
|
+
*/
|
|
23
|
+
export default function deepGet(obj: {
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
} | {
|
|
26
|
+
[key: string]: any;
|
|
27
|
+
}[] | any[], path: string, get_parent?: boolean): any | undefined;
|
package/dist/deep/get.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function deepGet(obj, path, get_parent = false) {
|
|
4
|
+
if (Object.prototype.toString.call(obj) !== '[object Object]' &&
|
|
5
|
+
!Array.isArray(obj))
|
|
6
|
+
throw new TypeError('Deepget is only supported for objects');
|
|
7
|
+
if (typeof path !== 'string')
|
|
8
|
+
throw new TypeError('No path was given');
|
|
9
|
+
const path_s = path.trim();
|
|
10
|
+
if (path_s.length === 0)
|
|
11
|
+
throw new TypeError('No path was given');
|
|
12
|
+
const parts = path_s
|
|
13
|
+
.replace(/\[/g, '.')
|
|
14
|
+
.replace(/(\.){2,}/g, '.')
|
|
15
|
+
.replace(/(^\.|\.$|\])/g, '')
|
|
16
|
+
.split('.');
|
|
17
|
+
if (parts.length === 0 || (parts.length === 1 && get_parent))
|
|
18
|
+
return obj;
|
|
19
|
+
if (get_parent)
|
|
20
|
+
parts.pop();
|
|
21
|
+
let cursor = obj;
|
|
22
|
+
while (parts.length > 0) {
|
|
23
|
+
if (Array.isArray(cursor)) {
|
|
24
|
+
const ix = parseInt(parts.shift());
|
|
25
|
+
if (!Number.isInteger(ix) || ix < 0 || ix > (cursor.length - 1))
|
|
26
|
+
return undefined;
|
|
27
|
+
cursor = cursor[ix];
|
|
28
|
+
}
|
|
29
|
+
else if (Object.prototype.toString.call(cursor) === '[object Object]') {
|
|
30
|
+
const key = parts.shift();
|
|
31
|
+
if (!Object.prototype.hasOwnProperty.call(cursor, key))
|
|
32
|
+
return undefined;
|
|
33
|
+
cursor = cursor[key];
|
|
34
|
+
}
|
|
35
|
+
if ((!Array.isArray(cursor) && Object.prototype.toString.call(cursor) !== '[object Object]') &&
|
|
36
|
+
parts.length > 0)
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
return cursor;
|
|
40
|
+
}
|
|
41
|
+
exports.default = deepGet;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type deepInput = {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
} | {
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
}[] | any[];
|
|
6
|
+
/**
|
|
7
|
+
* Recursively seals all properties of an object
|
|
8
|
+
*
|
|
9
|
+
* @param obj - Object to deep seal
|
|
10
|
+
*
|
|
11
|
+
* @returns Deeply sealed object
|
|
12
|
+
*/
|
|
13
|
+
export default function deepSeal(obj: deepInput): deepInput;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function deep(obj) {
|
|
4
|
+
if (Array.isArray(obj)) {
|
|
5
|
+
for (const el of obj)
|
|
6
|
+
deep(el);
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
for (const key of Object.keys(obj)) {
|
|
10
|
+
if (Object.prototype.toString.call(obj[key]) === '[object Object]' ||
|
|
11
|
+
Array.isArray(obj[key]))
|
|
12
|
+
deep(obj[key]);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return Object.seal(obj);
|
|
16
|
+
}
|
|
17
|
+
function deepSeal(obj) {
|
|
18
|
+
if (Object.prototype.toString.call(obj) !== '[object Object]' &&
|
|
19
|
+
!Array.isArray(obj))
|
|
20
|
+
throw new TypeError('Only objects/arrays can be sealed');
|
|
21
|
+
return deep(obj);
|
|
22
|
+
}
|
|
23
|
+
exports.default = deepSeal;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sets a property and its value deep in the structure of an object
|
|
3
|
+
*
|
|
4
|
+
* Example:
|
|
5
|
+
* const myObj = {a: 2};
|
|
6
|
+
* deepSet(myObj, 'b.c.d.e', 4);
|
|
7
|
+
* Output:
|
|
8
|
+
* {
|
|
9
|
+
* a: 2,
|
|
10
|
+
* b: {
|
|
11
|
+
* c: {
|
|
12
|
+
* d: {
|
|
13
|
+
* e: 4
|
|
14
|
+
* }
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* Example:
|
|
20
|
+
* const myObj = {a: 2, b: [{price: 2}]};
|
|
21
|
+
* deepSet(myObj, 'b[0].price', 4);
|
|
22
|
+
* Output:
|
|
23
|
+
* {
|
|
24
|
+
* a: 2,
|
|
25
|
+
* b: [
|
|
26
|
+
* {price: 4}
|
|
27
|
+
* ]
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* @param val - Object to set the value on
|
|
31
|
+
* @param path - Path string to deeply set the value at
|
|
32
|
+
* @param value - Value to set (if using defineProperty can be an accessor object)
|
|
33
|
+
* @param define - Whether or not the property should be directly assigned or set using Object.defineProperty
|
|
34
|
+
*
|
|
35
|
+
* @returns True or false depending on whether or not the property was set correctly
|
|
36
|
+
* @throws {TypeError}
|
|
37
|
+
*/
|
|
38
|
+
export default function deepSet(obj: {
|
|
39
|
+
[key: string]: any;
|
|
40
|
+
} | {
|
|
41
|
+
[key: string]: any;
|
|
42
|
+
}[] | any[], path: string, value: any, define?: boolean): boolean;
|
package/dist/deep/set.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function deepSet(obj, path, value, define = false) {
|
|
4
|
+
if (Object.prototype.toString.call(obj) !== '[object Object]' &&
|
|
5
|
+
!Array.isArray(obj))
|
|
6
|
+
throw new TypeError('Deepset is only supported for objects');
|
|
7
|
+
if (typeof path !== 'string')
|
|
8
|
+
throw new TypeError('No path was given');
|
|
9
|
+
if (/__proto__|constructor|prototype/.test(path))
|
|
10
|
+
throw new TypeError('Malicious path provided');
|
|
11
|
+
const path_s = path.trim();
|
|
12
|
+
if (path_s.length === 0)
|
|
13
|
+
throw new TypeError('No path was given');
|
|
14
|
+
const parts = path_s
|
|
15
|
+
.replace(/\[/g, '.')
|
|
16
|
+
.replace(/(\.){2,}/g, '.')
|
|
17
|
+
.replace(/(^\.|\.$|\])/g, '')
|
|
18
|
+
.split('.');
|
|
19
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
20
|
+
if (parts[i] === '')
|
|
21
|
+
continue;
|
|
22
|
+
if (Array.isArray(obj)) {
|
|
23
|
+
const idx = parseInt(parts[i]);
|
|
24
|
+
if (!Number.isInteger(idx) || idx < 0)
|
|
25
|
+
throw new TypeError('Invalid path provided');
|
|
26
|
+
if (!obj[idx])
|
|
27
|
+
obj[idx] = {};
|
|
28
|
+
obj = obj[idx];
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
if (!obj[parts[i]])
|
|
32
|
+
obj[parts[i]] = {};
|
|
33
|
+
obj = obj[parts[i]];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (!Array.isArray(obj) && Object.prototype.toString.call(obj) !== '[object Object]')
|
|
37
|
+
return false;
|
|
38
|
+
if (define) {
|
|
39
|
+
Object.defineProperty(obj, parts[parts.length - 1], value);
|
|
40
|
+
}
|
|
41
|
+
else if (Array.isArray(obj)) {
|
|
42
|
+
const idx = parseInt(parts[parts.length - 1]);
|
|
43
|
+
if (!Number.isInteger(idx) || idx < 0)
|
|
44
|
+
throw new TypeError('Invalid path provided');
|
|
45
|
+
obj[idx] = value;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
obj[parts[parts.length - 1]] = value;
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
exports.default = deepSet;
|
package/dist/equal.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compute whether or not two provided values are deeply equal
|
|
3
|
+
*
|
|
4
|
+
* @param a - Value to compare against
|
|
5
|
+
* @param b - Value to compare with
|
|
6
|
+
*
|
|
7
|
+
* @returns Whether or not they are equal
|
|
8
|
+
*/
|
|
9
|
+
declare function equal(a: any, b: any): boolean;
|
|
10
|
+
export default equal;
|
package/dist/equal.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const isNumericalNaN_1 = require("./number/isNumericalNaN");
|
|
4
|
+
function isArrayEqual(a, b) {
|
|
5
|
+
if (a.length !== b.length)
|
|
6
|
+
return false;
|
|
7
|
+
for (let i = a.length - 1; i >= 0; i--) {
|
|
8
|
+
if (equal(a[i], b[i]))
|
|
9
|
+
continue;
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
function isObjectEqual(a, b) {
|
|
15
|
+
const keys_a = Object.keys(a);
|
|
16
|
+
if (keys_a.length !== Object.keys(b).length)
|
|
17
|
+
return false;
|
|
18
|
+
for (let i = keys_a.length - 1; i >= 0; i--) {
|
|
19
|
+
if (equal(a[keys_a[i]], b[keys_a[i]]))
|
|
20
|
+
continue;
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
function equal(a, b) {
|
|
26
|
+
if (a instanceof Date &&
|
|
27
|
+
b instanceof Date)
|
|
28
|
+
return a.valueOf() === b.valueOf();
|
|
29
|
+
if (Object.prototype.toString.call(a) === '[object RegExp]' &&
|
|
30
|
+
Object.prototype.toString.call(b) === '[object RegExp]')
|
|
31
|
+
return String(a) === String(b);
|
|
32
|
+
if (Array.isArray(a) &&
|
|
33
|
+
Array.isArray(b))
|
|
34
|
+
return isArrayEqual(a, b);
|
|
35
|
+
if (Object.prototype.toString.call(a) === '[object Object]' &&
|
|
36
|
+
Object.prototype.toString.call(b) === '[object Object]')
|
|
37
|
+
return isObjectEqual(a, b);
|
|
38
|
+
if ((0, isNumericalNaN_1.default)(a)) {
|
|
39
|
+
return (0, isNumericalNaN_1.default)(b);
|
|
40
|
+
}
|
|
41
|
+
return a === b;
|
|
42
|
+
}
|
|
43
|
+
exports.default = equal;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* No-Operation (noop) resolver that simply returns a promise
|
|
3
|
+
* that resolves with the value that was passed to it
|
|
4
|
+
*
|
|
5
|
+
* @param val - Value to be resolved with
|
|
6
|
+
*
|
|
7
|
+
* @returns Promise that resolves with passed value
|
|
8
|
+
*/
|
|
9
|
+
export default function noopresolve(val?: any): Promise<any>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a promise that resolves after X milliseconds, useful in
|
|
3
|
+
* async scenarios where we wish to wait for a specific periodic of time
|
|
4
|
+
*
|
|
5
|
+
* @param ms - (default=1000) Amount of milliseconds to wait for
|
|
6
|
+
*
|
|
7
|
+
* @returns Promise that resolves after X milliseconds
|
|
8
|
+
*/
|
|
9
|
+
export default function sleep(ms?: number): Promise<void>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a provided value into a Fowler-Noll-Vo 1A hash
|
|
3
|
+
* For more info: https://tools.ietf.org/html/draft-eastlake-fnv-03
|
|
4
|
+
*
|
|
5
|
+
* @param data - Value to be converted
|
|
6
|
+
* @param offset - (default=2166136261) FNV prime to use
|
|
7
|
+
*
|
|
8
|
+
* @returns FNV1A hash of provided value
|
|
9
|
+
*/
|
|
10
|
+
export default function fnv1A(data: any, offset?: number): number;
|