@valkyriestudios/utils 12.3.0 → 12.5.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 +15 -4
- package/array/dedupe.d.ts +2 -1
- package/array/dedupe.js +3 -1
- package/array/index.d.ts +10 -0
- package/array/index.js +25 -0
- package/array/is.d.ts +2 -1
- package/array/is.js +2 -0
- package/array/isNotEmpty.d.ts +2 -1
- package/array/isNotEmpty.js +2 -0
- package/array/join.d.ts +2 -2
- package/array/join.js +3 -1
- package/array/mapFn.d.ts +4 -7
- package/array/mapFn.js +2 -0
- package/array/mapKey.d.ts +3 -4
- package/array/mapKey.js +2 -0
- package/array/mapPrimitive.d.ts +2 -2
- package/array/mapPrimitive.js +3 -1
- package/array/shuffle.d.ts +2 -1
- package/array/shuffle.js +2 -0
- package/array/sort.d.ts +2 -2
- package/array/sort.js +4 -2
- package/boolean/index.d.ts +2 -0
- package/boolean/index.js +6 -0
- package/boolean/is.d.ts +2 -1
- package/boolean/is.js +2 -0
- package/caching/index.d.ts +2 -0
- package/caching/index.js +5 -0
- package/caching/memoize.d.ts +2 -1
- package/caching/memoize.js +2 -0
- package/date/addUTC.d.ts +2 -1
- package/date/addUTC.js +3 -3
- package/date/diff.d.ts +2 -1
- package/date/diff.js +4 -2
- package/date/endOfUTC.d.ts +2 -1
- package/date/endOfUTC.js +3 -3
- package/date/format.d.ts +2 -1
- package/date/format.js +3 -1
- package/date/index.d.ts +11 -0
- package/date/index.js +24 -0
- package/date/is.d.ts +2 -1
- package/date/is.js +2 -0
- package/date/nowUnix.d.ts +2 -1
- package/date/nowUnix.js +2 -0
- package/date/nowUnixMs.d.ts +2 -1
- package/date/nowUnixMs.js +2 -0
- package/date/startOfUTC.d.ts +2 -1
- package/date/startOfUTC.js +3 -3
- package/date/toUTC.d.ts +2 -1
- package/date/toUTC.js +3 -1
- package/date/toUnix.d.ts +2 -1
- package/date/toUnix.js +3 -1
- package/deep/freeze.d.ts +2 -2
- package/deep/freeze.js +2 -0
- package/deep/get.d.ts +2 -1
- package/deep/get.js +2 -0
- package/deep/index.d.ts +5 -0
- package/deep/index.js +15 -0
- package/deep/seal.d.ts +2 -2
- package/deep/seal.js +2 -0
- package/deep/set.d.ts +2 -1
- package/deep/set.js +2 -0
- package/equal.d.ts +1 -1
- package/equal.js +4 -2
- package/formdata/index.d.ts +2 -0
- package/formdata/index.js +6 -0
- package/formdata/is.d.ts +9 -0
- package/formdata/is.js +8 -0
- package/function/index.d.ts +7 -0
- package/function/index.js +19 -0
- package/function/is.d.ts +2 -1
- package/function/is.js +2 -0
- package/function/isAsync.d.ts +2 -1
- package/function/isAsync.js +2 -0
- package/function/noop.d.ts +2 -1
- package/function/noop.js +2 -0
- package/function/noopresolve.d.ts +2 -1
- package/function/noopresolve.js +2 -0
- package/function/noopreturn.d.ts +2 -1
- package/function/noopreturn.js +2 -0
- package/function/sleep.d.ts +2 -1
- package/function/sleep.js +2 -0
- package/hash/fnv1A.d.ts +2 -1
- package/hash/fnv1A.js +2 -0
- package/hash/guid.d.ts +2 -1
- package/hash/guid.js +2 -0
- package/hash/index.d.ts +3 -0
- package/hash/index.js +7 -0
- package/index.d.ts +386 -238
- package/is.d.ts +52 -66
- package/is.js +61 -73
- package/number/index.d.ts +18 -0
- package/number/index.js +57 -0
- package/number/is.d.ts +2 -1
- package/number/is.js +2 -0
- package/number/isAbove.d.ts +2 -1
- package/number/isAbove.js +2 -0
- package/number/isAboveOrEqual.d.ts +2 -1
- package/number/isAboveOrEqual.js +2 -0
- package/number/isBelow.d.ts +2 -1
- package/number/isBelow.js +2 -0
- package/number/isBelowOrEqual.d.ts +2 -1
- package/number/isBelowOrEqual.js +2 -0
- package/number/isBetween.d.ts +2 -1
- package/number/isBetween.js +2 -0
- package/number/isInteger.d.ts +2 -1
- package/number/isInteger.js +2 -0
- package/number/isIntegerAbove.d.ts +2 -1
- package/number/isIntegerAbove.js +2 -0
- package/number/isIntegerAboveOrEqual.d.ts +2 -1
- package/number/isIntegerAboveOrEqual.js +2 -0
- package/number/isIntegerBelow.d.ts +2 -1
- package/number/isIntegerBelow.js +2 -0
- package/number/isIntegerBelowOrEqual.d.ts +2 -1
- package/number/isIntegerBelowOrEqual.js +2 -0
- package/number/isIntegerBetween.d.ts +2 -1
- package/number/isIntegerBetween.js +2 -0
- package/number/isNumericalNaN.d.ts +2 -1
- package/number/isNumericalNaN.js +2 -0
- package/number/randomBetween.d.ts +2 -1
- package/number/randomBetween.js +2 -0
- package/number/randomIntBetween.d.ts +2 -1
- package/number/randomIntBetween.js +2 -0
- package/number/round.d.ts +2 -1
- package/number/round.js +2 -0
- package/number/toPercentage.d.ts +2 -1
- package/number/toPercentage.js +3 -1
- package/object/define.d.ts +2 -1
- package/object/define.js +2 -0
- package/object/index.d.ts +6 -0
- package/object/index.js +17 -0
- package/object/is.d.ts +2 -1
- package/object/is.js +2 -0
- package/object/isNotEmpty.d.ts +2 -1
- package/object/isNotEmpty.js +2 -0
- package/object/merge.d.ts +1 -1
- package/object/merge.js +2 -0
- package/object/pick.d.ts +2 -1
- package/object/pick.js +4 -2
- package/package.json +1 -1
- package/regexp/index.d.ts +3 -0
- package/regexp/index.js +9 -0
- package/regexp/is.d.ts +2 -1
- package/regexp/is.js +2 -0
- package/regexp/sanitize.d.ts +2 -1
- package/regexp/sanitize.js +2 -0
- package/string/humanizeBytes.d.ts +2 -2
- package/string/humanizeBytes.js +4 -3
- package/string/humanizeNumber.d.ts +2 -2
- package/string/humanizeNumber.js +3 -1
- package/string/index.d.ts +7 -0
- package/string/index.js +20 -0
- package/string/is.d.ts +2 -1
- package/string/is.js +2 -0
- package/string/isBetween.d.ts +2 -1
- package/string/isBetween.js +2 -0
- package/string/isNotEmpty.d.ts +2 -1
- package/string/isNotEmpty.js +2 -0
- package/string/shorten.d.ts +2 -1
- package/string/shorten.js +2 -0
package/README.md
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
# @valkyriestudios/utils
|
|
2
2
|
|
|
3
|
-
[](https://codecov.io/gh/ValkyrieStudios/utils)
|
|
4
|
+
[](https://github.com/ValkyrieStudios/utils/actions/workflows/test.yml)
|
|
5
|
+
[](https://github.com/ValkyrieStudios/utils/actions/workflows/lint.yml)
|
|
6
|
+
[](https://github.com/ValkyrieStudios/utils/actions/workflows/github-code-scanning/codeql)
|
|
5
7
|
[](https://www.npmjs.com/package/@valkyriestudios/utils)
|
|
6
8
|
[](https://www.npmjs.com/package/@valkyriestudios/utils)
|
|
7
9
|
|
|
8
10
|
Zero-dependency collection of single-function utilities for common tasks
|
|
9
11
|
|
|
12
|
+
## Installation
|
|
10
13
|
`npm install @valkyriestudios/utils`
|
|
11
14
|
|
|
12
15
|
## Available Functions
|
|
@@ -275,7 +278,7 @@ const memoized_function = memoize((a) => {
|
|
|
275
278
|
- **isDate(val:any)**
|
|
276
279
|
Check if a variable is of type Date
|
|
277
280
|
```js
|
|
278
|
-
isDate(new Date('December 17, 1995 03:24:00'); // TRUE
|
|
281
|
+
isDate(new Date('December 17, 1995 03:24:00')); // TRUE
|
|
279
282
|
isDate('December 17, 1995 03:24:00'); // FALSE
|
|
280
283
|
```
|
|
281
284
|
|
|
@@ -542,6 +545,14 @@ An empty function that returns a promise that will immediately resolve itself an
|
|
|
542
545
|
An empty function that returns a promise that will resolve after X milliseconds, default is set to 1000ms.
|
|
543
546
|
**
|
|
544
547
|
|
|
548
|
+
### formdata
|
|
549
|
+
- **isFormData(val:any)**
|
|
550
|
+
Check if a variable is of type FormData
|
|
551
|
+
```js
|
|
552
|
+
isFormData(new FormData()); // TRUE
|
|
553
|
+
isFormData({hi: 'there'}); // FALSE
|
|
554
|
+
```
|
|
555
|
+
|
|
545
556
|
### hash
|
|
546
557
|
- **guid()**
|
|
547
558
|
Generate a unique identifier (guid) according to RFC4122
|
|
@@ -847,4 +858,4 @@ humanizeNumber(47328748923747923479); // '47,328.75q'
|
|
|
847
858
|
allows passing options to control the output, following options are possible:
|
|
848
859
|
|
|
849
860
|
## Contributors
|
|
850
|
-
- [Peter Vermeulen](
|
|
861
|
+
- [Peter Vermeulen](https://www.linkedin.com/in/petervermeulen1/)
|
package/array/dedupe.d.ts
CHANGED
package/array/dedupe.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = exports.dedupe = void 0;
|
|
3
4
|
const fnv1A_1 = require("../hash/fnv1A");
|
|
4
5
|
function dedupe(val) {
|
|
5
6
|
if (!Array.isArray(val))
|
|
@@ -7,7 +8,7 @@ function dedupe(val) {
|
|
|
7
8
|
const set = new Set();
|
|
8
9
|
const acc = [];
|
|
9
10
|
for (const item of val) {
|
|
10
|
-
const hash = (0, fnv1A_1.
|
|
11
|
+
const hash = (0, fnv1A_1.fnv1A)(item);
|
|
11
12
|
if (set.has(hash))
|
|
12
13
|
continue;
|
|
13
14
|
set.add(hash);
|
|
@@ -15,4 +16,5 @@ function dedupe(val) {
|
|
|
15
16
|
}
|
|
16
17
|
return acc;
|
|
17
18
|
}
|
|
19
|
+
exports.dedupe = dedupe;
|
|
18
20
|
exports.default = dedupe;
|
package/array/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { dedupe } from './dedupe';
|
|
2
|
+
import { isArray } from './is';
|
|
3
|
+
import { isNotEmptyArray } from './isNotEmpty';
|
|
4
|
+
import { join } from './join';
|
|
5
|
+
import { mapFn } from './mapFn';
|
|
6
|
+
import { mapKey } from './mapKey';
|
|
7
|
+
import { mapPrimitive } from './mapPrimitive';
|
|
8
|
+
import { shuffle } from './shuffle';
|
|
9
|
+
import { sort } from './sort';
|
|
10
|
+
export { dedupe, isArray, isArray as is, isNotEmptyArray, isNotEmptyArray as isNotEmpty, isNotEmptyArray as isNeArray, isNotEmptyArray as isNe, join, mapFn, mapKey, mapPrimitive, shuffle, sort };
|
package/array/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sort = exports.shuffle = exports.mapPrimitive = exports.mapKey = exports.mapFn = exports.join = exports.isNe = exports.isNeArray = exports.isNotEmpty = exports.isNotEmptyArray = exports.is = exports.isArray = exports.dedupe = void 0;
|
|
4
|
+
const dedupe_1 = require("./dedupe");
|
|
5
|
+
Object.defineProperty(exports, "dedupe", { enumerable: true, get: function () { return dedupe_1.dedupe; } });
|
|
6
|
+
const is_1 = require("./is");
|
|
7
|
+
Object.defineProperty(exports, "isArray", { enumerable: true, get: function () { return is_1.isArray; } });
|
|
8
|
+
Object.defineProperty(exports, "is", { enumerable: true, get: function () { return is_1.isArray; } });
|
|
9
|
+
const isNotEmpty_1 = require("./isNotEmpty");
|
|
10
|
+
Object.defineProperty(exports, "isNotEmptyArray", { enumerable: true, get: function () { return isNotEmpty_1.isNotEmptyArray; } });
|
|
11
|
+
Object.defineProperty(exports, "isNotEmpty", { enumerable: true, get: function () { return isNotEmpty_1.isNotEmptyArray; } });
|
|
12
|
+
Object.defineProperty(exports, "isNeArray", { enumerable: true, get: function () { return isNotEmpty_1.isNotEmptyArray; } });
|
|
13
|
+
Object.defineProperty(exports, "isNe", { enumerable: true, get: function () { return isNotEmpty_1.isNotEmptyArray; } });
|
|
14
|
+
const join_1 = require("./join");
|
|
15
|
+
Object.defineProperty(exports, "join", { enumerable: true, get: function () { return join_1.join; } });
|
|
16
|
+
const mapFn_1 = require("./mapFn");
|
|
17
|
+
Object.defineProperty(exports, "mapFn", { enumerable: true, get: function () { return mapFn_1.mapFn; } });
|
|
18
|
+
const mapKey_1 = require("./mapKey");
|
|
19
|
+
Object.defineProperty(exports, "mapKey", { enumerable: true, get: function () { return mapKey_1.mapKey; } });
|
|
20
|
+
const mapPrimitive_1 = require("./mapPrimitive");
|
|
21
|
+
Object.defineProperty(exports, "mapPrimitive", { enumerable: true, get: function () { return mapPrimitive_1.mapPrimitive; } });
|
|
22
|
+
const shuffle_1 = require("./shuffle");
|
|
23
|
+
Object.defineProperty(exports, "shuffle", { enumerable: true, get: function () { return shuffle_1.shuffle; } });
|
|
24
|
+
const sort_1 = require("./sort");
|
|
25
|
+
Object.defineProperty(exports, "sort", { enumerable: true, get: function () { return sort_1.sort; } });
|
package/array/is.d.ts
CHANGED
package/array/is.js
CHANGED
package/array/isNotEmpty.d.ts
CHANGED
|
@@ -5,4 +5,5 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @returns Whether or not the value is an array with content
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
declare function isNotEmptyArray(val: unknown): val is unknown[];
|
|
9
|
+
export { isNotEmptyArray, isNotEmptyArray as default };
|
package/array/isNotEmpty.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = exports.isNotEmptyArray = void 0;
|
|
3
4
|
function isNotEmptyArray(val) {
|
|
4
5
|
return Array.isArray(val) && val.length !== 0;
|
|
5
6
|
}
|
|
7
|
+
exports.isNotEmptyArray = isNotEmptyArray;
|
|
6
8
|
exports.default = isNotEmptyArray;
|
package/array/join.d.ts
CHANGED
|
@@ -32,5 +32,5 @@ interface joinOptions {
|
|
|
32
32
|
*
|
|
33
33
|
* @returns Joined array as string
|
|
34
34
|
*/
|
|
35
|
-
|
|
36
|
-
export {};
|
|
35
|
+
declare function join(val: unknown[], opts?: joinOptions): string;
|
|
36
|
+
export { join, join as default };
|
package/array/join.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = exports.join = void 0;
|
|
3
4
|
const round_1 = require("../number/round");
|
|
4
5
|
function join(val, opts) {
|
|
5
6
|
if (!Array.isArray(val) || !val.length)
|
|
@@ -24,9 +25,10 @@ function join(val, opts) {
|
|
|
24
25
|
filtered.push(VALTRIM ? el.trim() : el);
|
|
25
26
|
}
|
|
26
27
|
else if (Number.isFinite(el)) {
|
|
27
|
-
filtered.push(VALROUND !== false ? (0, round_1.
|
|
28
|
+
filtered.push(VALROUND !== false ? (0, round_1.round)(el, VALROUND) : el);
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
31
|
return TRIM ? filtered.join(DELIM).trim() : filtered.join(DELIM);
|
|
31
32
|
}
|
|
33
|
+
exports.join = join;
|
|
32
34
|
exports.default = join;
|
package/array/mapFn.d.ts
CHANGED
|
@@ -12,10 +12,7 @@ interface mapOptions {
|
|
|
12
12
|
*/
|
|
13
13
|
merge?: boolean;
|
|
14
14
|
}
|
|
15
|
-
type mapFn = (entry:
|
|
16
|
-
[key: string]: any;
|
|
17
|
-
}) => (string | number | boolean);
|
|
18
|
-
type mapReturn = Record<string, Record<string, any>>;
|
|
15
|
+
type mapFn<T extends Record<string, any>> = (entry: T) => (string | number | boolean);
|
|
19
16
|
/**
|
|
20
17
|
* Map an object array into a kv-object through a function that generates a key. Returning a non-string,
|
|
21
18
|
* non-numeric value from the function (eg: false) will filter out the object.
|
|
@@ -29,7 +26,7 @@ type mapReturn = Record<string, Record<string, any>>;
|
|
|
29
26
|
* @param {mapFn} fn - Handler function which is run for each of the objects and should return a string or number
|
|
30
27
|
* @param {mapOptions?} opts - Options object to override built-in defaults
|
|
31
28
|
*
|
|
32
|
-
* @returns {
|
|
29
|
+
* @returns {Record<string, T>} KV-Map object
|
|
33
30
|
*/
|
|
34
|
-
|
|
35
|
-
export {};
|
|
31
|
+
declare function mapFn<T extends Record<string, any>>(arr: T[], fn: mapFn<T>, opts?: mapOptions): Record<string, T>;
|
|
32
|
+
export { mapFn, mapFn as default };
|
package/array/mapFn.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = exports.mapFn = void 0;
|
|
3
4
|
function mapFn(arr, fn, opts) {
|
|
4
5
|
if ((!Array.isArray(arr) || !arr.length) ||
|
|
5
6
|
typeof fn !== 'function')
|
|
@@ -18,4 +19,5 @@ function mapFn(arr, fn, opts) {
|
|
|
18
19
|
}
|
|
19
20
|
return map;
|
|
20
21
|
}
|
|
22
|
+
exports.mapFn = mapFn;
|
|
21
23
|
exports.default = mapFn;
|
package/array/mapKey.d.ts
CHANGED
|
@@ -12,7 +12,6 @@ interface mapOptions {
|
|
|
12
12
|
*/
|
|
13
13
|
merge?: boolean;
|
|
14
14
|
}
|
|
15
|
-
type kvMap = Record<string, Record<string, any>>;
|
|
16
15
|
/**
|
|
17
16
|
* Map an object array into a kv-object by passing a common key that exists on the objects. Objects for
|
|
18
17
|
* which the key doesn't exist will be filtered out automatically
|
|
@@ -26,7 +25,7 @@ type kvMap = Record<string, Record<string, any>>;
|
|
|
26
25
|
* @param {string} key - Key to map by
|
|
27
26
|
* @param {mapOptions?} opts - Options object to override built-in defaults
|
|
28
27
|
*
|
|
29
|
-
* @returns {
|
|
28
|
+
* @returns {Record<string, T>} KV-Map object
|
|
30
29
|
*/
|
|
31
|
-
|
|
32
|
-
export {};
|
|
30
|
+
declare function mapKey<T extends Record<string, any>>(arr: T[], key: string, opts?: mapOptions): Record<string, T>;
|
|
31
|
+
export { mapKey, mapKey as default };
|
package/array/mapKey.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = exports.mapKey = void 0;
|
|
3
4
|
function mapKey(arr, key, opts) {
|
|
4
5
|
if ((!Array.isArray(arr) || !arr.length) ||
|
|
5
6
|
typeof key !== 'string')
|
|
@@ -17,4 +18,5 @@ function mapKey(arr, key, opts) {
|
|
|
17
18
|
}
|
|
18
19
|
return map;
|
|
19
20
|
}
|
|
21
|
+
exports.mapKey = mapKey;
|
|
20
22
|
exports.default = mapKey;
|
package/array/mapPrimitive.d.ts
CHANGED
|
@@ -34,5 +34,5 @@ type mapReturn = Record<string, string | number>;
|
|
|
34
34
|
*
|
|
35
35
|
* @returns {mapReturn} KV-Map object
|
|
36
36
|
*/
|
|
37
|
-
|
|
38
|
-
export {};
|
|
37
|
+
declare function mapPrimitive(arr: unknown[], opts?: mapOptions): mapReturn;
|
|
38
|
+
export { mapPrimitive, mapPrimitive as default };
|
package/array/mapPrimitive.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = exports.mapPrimitive = void 0;
|
|
3
4
|
const round_1 = require("../number/round");
|
|
4
5
|
function mapPrimitive(arr, opts) {
|
|
5
6
|
if (!Array.isArray(arr) || !arr.length)
|
|
@@ -29,9 +30,10 @@ function mapPrimitive(arr, opts) {
|
|
|
29
30
|
? el
|
|
30
31
|
: VALROUND === true
|
|
31
32
|
? Math.round(el)
|
|
32
|
-
: (0, round_1.
|
|
33
|
+
: (0, round_1.round)(el, VALROUND);
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
return map;
|
|
36
37
|
}
|
|
38
|
+
exports.mapPrimitive = mapPrimitive;
|
|
37
39
|
exports.default = mapPrimitive;
|
package/array/shuffle.d.ts
CHANGED
package/array/shuffle.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = exports.shuffle = void 0;
|
|
3
4
|
function shuffle(arr) {
|
|
4
5
|
if (!Array.isArray(arr))
|
|
5
6
|
return;
|
|
@@ -8,4 +9,5 @@ function shuffle(arr) {
|
|
|
8
9
|
[arr[i], arr[j]] = [arr[j], arr[i]];
|
|
9
10
|
}
|
|
10
11
|
}
|
|
12
|
+
exports.shuffle = shuffle;
|
|
11
13
|
exports.default = shuffle;
|
package/array/sort.d.ts
CHANGED
|
@@ -54,5 +54,5 @@ type sortByFunction = (el: sortObject) => string;
|
|
|
54
54
|
* @returns Sorted array
|
|
55
55
|
* @throws {Error}
|
|
56
56
|
*/
|
|
57
|
-
|
|
58
|
-
export {};
|
|
57
|
+
declare function sort(arr: sortObject[], by: string | sortByFunction, dir?: 'asc' | 'desc', opts?: sortOptions): sortObject[];
|
|
58
|
+
export { sort, sort as default };
|
package/array/sort.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = exports.sort = void 0;
|
|
3
4
|
const isNotEmpty_1 = require("../object/isNotEmpty");
|
|
4
5
|
function partition(arr, start_ix, end_ix) {
|
|
5
6
|
const pivot_val = arr[Math.floor((start_ix + end_ix) / 2)].t;
|
|
@@ -35,7 +36,7 @@ function sort(arr, by, dir = 'asc', opts) {
|
|
|
35
36
|
throw new Error('Direction should be either asc or desc');
|
|
36
37
|
let NOKEY_HIDE = false;
|
|
37
38
|
let NOKEY_AT_END = true;
|
|
38
|
-
let FILTER_FN = isNotEmpty_1.
|
|
39
|
+
let FILTER_FN = isNotEmpty_1.isNotEmptyObject;
|
|
39
40
|
if (opts && Object.prototype.toString.call(opts) === '[object Object]') {
|
|
40
41
|
if (opts.nokey_hide === true)
|
|
41
42
|
NOKEY_HIDE = true;
|
|
@@ -43,7 +44,7 @@ function sort(arr, by, dir = 'asc', opts) {
|
|
|
43
44
|
NOKEY_AT_END = false;
|
|
44
45
|
if (typeof opts.filter_fn === 'function') {
|
|
45
46
|
const fn = opts.filter_fn;
|
|
46
|
-
FILTER_FN = (el => (0, isNotEmpty_1.
|
|
47
|
+
FILTER_FN = (el => (0, isNotEmpty_1.isNotEmptyObject)(el) && fn(el));
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
50
|
const prepared_arr = [];
|
|
@@ -102,4 +103,5 @@ function sort(arr, by, dir = 'asc', opts) {
|
|
|
102
103
|
}
|
|
103
104
|
return result;
|
|
104
105
|
}
|
|
106
|
+
exports.sort = sort;
|
|
105
107
|
exports.default = sort;
|
package/boolean/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.is = exports.isBoolean = void 0;
|
|
4
|
+
const is_1 = require("./is");
|
|
5
|
+
Object.defineProperty(exports, "isBoolean", { enumerable: true, get: function () { return is_1.isBoolean; } });
|
|
6
|
+
Object.defineProperty(exports, "is", { enumerable: true, get: function () { return is_1.isBoolean; } });
|
package/boolean/is.d.ts
CHANGED
package/boolean/is.js
CHANGED
package/caching/index.js
ADDED
package/caching/memoize.d.ts
CHANGED
|
@@ -7,4 +7,5 @@
|
|
|
7
7
|
* @param fn - Function to memoize
|
|
8
8
|
* @param resolver - Optional resolver function to generate cache key. If not passed the first argument is used as map key
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
declare function memoize(fn: Function, resolver?: Function): Function;
|
|
11
|
+
export { memoize, memoize as default };
|
package/caching/memoize.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = exports.memoize = void 0;
|
|
3
4
|
function memoize(fn, resolver) {
|
|
4
5
|
const memoized = function () {
|
|
5
6
|
const key = typeof resolver === 'function' ? resolver.apply(this, arguments) : arguments[0];
|
|
@@ -12,4 +13,5 @@ function memoize(fn, resolver) {
|
|
|
12
13
|
memoized.cache = new Map();
|
|
13
14
|
return memoized;
|
|
14
15
|
}
|
|
16
|
+
exports.memoize = memoize;
|
|
15
17
|
exports.default = memoize;
|
package/date/addUTC.d.ts
CHANGED
|
@@ -7,4 +7,5 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @returns New date with provided amount of key added
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
declare function addUTC(val: Date, amt?: number, key?: 'years' | 'year' | 'months' | 'month' | 'days' | 'day' | 'hours' | 'hour' | 'minutes' | 'minute' | 'seconds' | 'second' | 'milliseconds' | 'millisecond'): Date;
|
|
11
|
+
export { addUTC, addUTC as default };
|
package/date/addUTC.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = exports.addUTC = void 0;
|
|
3
4
|
const is_1 = require("./is");
|
|
4
5
|
function addUTC(val, amt = 0, key = 'millisecond') {
|
|
5
|
-
if (!(0, is_1.
|
|
6
|
+
if (!(0, is_1.isDate)(val))
|
|
6
7
|
throw new TypeError('addUTC requires a date object');
|
|
7
8
|
if (!Number.isInteger(amt))
|
|
8
9
|
throw new TypeError('Amount needs to be an integer');
|
|
9
|
-
if (typeof key !== 'string')
|
|
10
|
-
throw new TypeError('Key needs to be a string with content');
|
|
11
10
|
const year = val.getUTCFullYear();
|
|
12
11
|
const month = val.getUTCMonth();
|
|
13
12
|
const date = val.getUTCDate();
|
|
@@ -41,4 +40,5 @@ function addUTC(val, amt = 0, key = 'millisecond') {
|
|
|
41
40
|
return new Date(Date.UTC(year, month, date, hour, min, sec, ms));
|
|
42
41
|
}
|
|
43
42
|
}
|
|
43
|
+
exports.addUTC = addUTC;
|
|
44
44
|
exports.default = addUTC;
|
package/date/diff.d.ts
CHANGED
|
@@ -7,4 +7,5 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @returns Numerical diff between two dates
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
declare function diff(val_a: Date, val_b: Date, key?: 'week' | 'weeks' | 'day' | 'days' | 'hour' | 'hours' | 'minute' | 'minutes' | 'second' | 'seconds' | 'millisecond' | 'milliseconds'): number;
|
|
11
|
+
export { diff, diff as default };
|
package/date/diff.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = exports.diff = void 0;
|
|
3
4
|
const is_1 = require("./is");
|
|
4
5
|
const SECOND_IN_MILLISECONDS = 1000;
|
|
5
6
|
const MINUTE_IN_MILLISECONDS = SECOND_IN_MILLISECONDS * 60;
|
|
@@ -7,8 +8,8 @@ const HOUR_IN_MILLISECONDS = MINUTE_IN_MILLISECONDS * 60;
|
|
|
7
8
|
const DAY_IN_MILLISECONDS = HOUR_IN_MILLISECONDS * 24;
|
|
8
9
|
const WEEK_IN_MILLISECONDS = DAY_IN_MILLISECONDS * 7;
|
|
9
10
|
function diff(val_a, val_b, key = 'millisecond') {
|
|
10
|
-
if (!(0, is_1.
|
|
11
|
-
!(0, is_1.
|
|
11
|
+
if (!(0, is_1.isDate)(val_a) ||
|
|
12
|
+
!(0, is_1.isDate)(val_b))
|
|
12
13
|
throw new TypeError('Diff requires date objects for both values');
|
|
13
14
|
if (typeof key !== 'string')
|
|
14
15
|
throw new TypeError('Key needs to be a string');
|
|
@@ -33,4 +34,5 @@ function diff(val_a, val_b, key = 'millisecond') {
|
|
|
33
34
|
return diff_in_ms;
|
|
34
35
|
}
|
|
35
36
|
}
|
|
37
|
+
exports.diff = diff;
|
|
36
38
|
exports.default = diff;
|
package/date/endOfUTC.d.ts
CHANGED
|
@@ -6,4 +6,5 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @returns New date set to end of key
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
declare 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;
|
|
10
|
+
export { endOfUTC, endOfUTC as default };
|
package/date/endOfUTC.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = exports.endOfUTC = void 0;
|
|
3
4
|
const is_1 = require("./is");
|
|
4
5
|
const WEEK_END = new Map([
|
|
5
6
|
['week', 0],
|
|
@@ -12,10 +13,8 @@ const WEEK_END = new Map([
|
|
|
12
13
|
['week_sat', 5],
|
|
13
14
|
]);
|
|
14
15
|
function endOfUTC(val, key = 'millisecond') {
|
|
15
|
-
if (!(0, is_1.
|
|
16
|
+
if (!(0, is_1.isDate)(val))
|
|
16
17
|
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
18
|
switch (key) {
|
|
20
19
|
case 'year':
|
|
21
20
|
return new Date(Date.UTC(val.getUTCFullYear(), 11, 31, 23, 59, 59, 999));
|
|
@@ -49,4 +48,5 @@ function endOfUTC(val, key = 'millisecond') {
|
|
|
49
48
|
return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), val.getUTCHours(), val.getUTCMinutes(), val.getUTCSeconds(), val.getUTCMilliseconds()));
|
|
50
49
|
}
|
|
51
50
|
}
|
|
51
|
+
exports.endOfUTC = endOfUTC;
|
|
52
52
|
exports.default = endOfUTC;
|
package/date/format.d.ts
CHANGED
|
@@ -8,4 +8,5 @@
|
|
|
8
8
|
* @returns {string} Formatted date as string
|
|
9
9
|
* @throws {TypeError} When provided invalid payload
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
declare function format(val: Date, spec: string, locale?: string, zone?: string): string;
|
|
12
|
+
export { format, format as default };
|
package/date/format.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = exports.format = void 0;
|
|
3
4
|
const is_1 = require("./is");
|
|
4
5
|
const DEFAULT_LOCALE = 'en-US';
|
|
5
6
|
let DEFAULT_TZ = 'UTC';
|
|
@@ -91,7 +92,7 @@ function getSpecChain(spec) {
|
|
|
91
92
|
return spec_chain;
|
|
92
93
|
}
|
|
93
94
|
function format(val, spec, locale = DEFAULT_LOCALE, zone = DEFAULT_TZ) {
|
|
94
|
-
if (!(0, is_1.
|
|
95
|
+
if (!(0, is_1.isDate)(val))
|
|
95
96
|
throw new TypeError('format: val must be a Date');
|
|
96
97
|
if (typeof spec !== 'string' || !spec.trim().length)
|
|
97
98
|
throw new TypeError('format: spec must be a non-empty string');
|
|
@@ -122,4 +123,5 @@ function format(val, spec, locale = DEFAULT_LOCALE, zone = DEFAULT_TZ) {
|
|
|
122
123
|
}
|
|
123
124
|
return formatted_string;
|
|
124
125
|
}
|
|
126
|
+
exports.format = format;
|
|
125
127
|
exports.default = format;
|
package/date/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { addUTC } from './addUTC';
|
|
2
|
+
import { diff } from './diff';
|
|
3
|
+
import { endOfUTC } from './endOfUTC';
|
|
4
|
+
import { format } from './format';
|
|
5
|
+
import { isDate } from './is';
|
|
6
|
+
import { nowUnix } from './nowUnix';
|
|
7
|
+
import { nowUnixMs } from './nowUnixMs';
|
|
8
|
+
import { startOfUTC } from './startOfUTC';
|
|
9
|
+
import { toUnix } from './toUnix';
|
|
10
|
+
import { toUTC } from './toUTC';
|
|
11
|
+
export { addUTC, diff, endOfUTC, format, isDate, isDate as is, nowUnix, nowUnixMs, startOfUTC, toUnix, toUTC };
|
package/date/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toUTC = exports.toUnix = exports.startOfUTC = exports.nowUnixMs = exports.nowUnix = exports.is = exports.isDate = exports.format = exports.endOfUTC = exports.diff = exports.addUTC = void 0;
|
|
4
|
+
const addUTC_1 = require("./addUTC");
|
|
5
|
+
Object.defineProperty(exports, "addUTC", { enumerable: true, get: function () { return addUTC_1.addUTC; } });
|
|
6
|
+
const diff_1 = require("./diff");
|
|
7
|
+
Object.defineProperty(exports, "diff", { enumerable: true, get: function () { return diff_1.diff; } });
|
|
8
|
+
const endOfUTC_1 = require("./endOfUTC");
|
|
9
|
+
Object.defineProperty(exports, "endOfUTC", { enumerable: true, get: function () { return endOfUTC_1.endOfUTC; } });
|
|
10
|
+
const format_1 = require("./format");
|
|
11
|
+
Object.defineProperty(exports, "format", { enumerable: true, get: function () { return format_1.format; } });
|
|
12
|
+
const is_1 = require("./is");
|
|
13
|
+
Object.defineProperty(exports, "isDate", { enumerable: true, get: function () { return is_1.isDate; } });
|
|
14
|
+
Object.defineProperty(exports, "is", { enumerable: true, get: function () { return is_1.isDate; } });
|
|
15
|
+
const nowUnix_1 = require("./nowUnix");
|
|
16
|
+
Object.defineProperty(exports, "nowUnix", { enumerable: true, get: function () { return nowUnix_1.nowUnix; } });
|
|
17
|
+
const nowUnixMs_1 = require("./nowUnixMs");
|
|
18
|
+
Object.defineProperty(exports, "nowUnixMs", { enumerable: true, get: function () { return nowUnixMs_1.nowUnixMs; } });
|
|
19
|
+
const startOfUTC_1 = require("./startOfUTC");
|
|
20
|
+
Object.defineProperty(exports, "startOfUTC", { enumerable: true, get: function () { return startOfUTC_1.startOfUTC; } });
|
|
21
|
+
const toUnix_1 = require("./toUnix");
|
|
22
|
+
Object.defineProperty(exports, "toUnix", { enumerable: true, get: function () { return toUnix_1.toUnix; } });
|
|
23
|
+
const toUTC_1 = require("./toUTC");
|
|
24
|
+
Object.defineProperty(exports, "toUTC", { enumerable: true, get: function () { return toUTC_1.toUTC; } });
|
package/date/is.d.ts
CHANGED
package/date/is.js
CHANGED
package/date/nowUnix.d.ts
CHANGED
package/date/nowUnix.js
CHANGED
package/date/nowUnixMs.d.ts
CHANGED
package/date/nowUnixMs.js
CHANGED