@giveback007/util-lib 0.25.4 → 1.0.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 +7 -7
- package/dist/@types.d.ts +40 -42
- package/dist/@types.js +2 -2
- package/dist/array.d.ts +66 -66
- package/dist/array.js +128 -128
- package/dist/array.js.map +1 -1
- package/dist/clone.d.ts +2 -2
- package/dist/clone.js +44 -45
- package/dist/clone.js.map +1 -1
- package/dist/equality.d.ts +1 -1
- package/dist/equality.js +81 -82
- package/dist/equality.js.map +1 -1
- package/dist/general.d.ts +44 -37
- package/dist/general.js +172 -139
- package/dist/general.js.map +1 -1
- package/dist/index.d.ts +11 -11
- package/dist/index.js +27 -23
- package/dist/index.js.map +1 -1
- package/dist/iterate.d.ts +44 -44
- package/dist/iterate.js +43 -44
- package/dist/iterate.js.map +1 -1
- package/dist/number.d.ts +33 -32
- package/dist/number.js +57 -55
- package/dist/number.js.map +1 -1
- package/dist/object.d.ts +45 -49
- package/dist/object.js +82 -92
- package/dist/object.js.map +1 -1
- package/dist/string.d.ts +3 -4
- package/dist/string.js +8 -18
- package/dist/string.js.map +1 -1
- package/dist/test.d.ts +40 -41
- package/dist/test.js +65 -67
- package/dist/test.js.map +1 -1
- package/dist/time.d.ts +87 -93
- package/dist/time.js +230 -174
- package/dist/time.js.map +1 -1
- package/package.json +33 -45
- package/src/@types/types.d.ts +34 -0
- package/src/@types.ts +67 -67
- package/src/array.ts +175 -175
- package/src/clone.ts +34 -35
- package/src/equality.ts +80 -80
- package/src/general.ts +192 -152
- package/src/index.ts +11 -11
- package/src/iterate.ts +86 -86
- package/src/number.ts +64 -62
- package/src/object.ts +109 -123
- package/src/string.ts +6 -20
- package/src/test.ts +71 -74
- package/src/time.ts +268 -219
- package/dist/node/file-systems.d.ts +0 -1
- package/dist/node/file-systems.js +0 -16
- package/dist/node/file-systems.js.map +0 -1
- package/dist/node/index.d.ts +0 -1
- package/dist/node/index.js +0 -14
- package/dist/node/index.js.map +0 -1
- package/src/node/file-systems.ts +0 -16
- package/src/node/index.ts +0 -1
package/dist/object.js
CHANGED
|
@@ -1,93 +1,83 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
keys
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
exports.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
* @param
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const values = {};
|
|
84
|
-
let total = 0;
|
|
85
|
-
return new Promise((resolve) => keyValues.forEach(({ key, val: x }) => x.then((data) => {
|
|
86
|
-
values[key] = data;
|
|
87
|
-
total++;
|
|
88
|
-
if (toEqual === total)
|
|
89
|
-
resolve(values);
|
|
90
|
-
})));
|
|
91
|
-
}
|
|
92
|
-
exports.objPromiseAll = objPromiseAll;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.objResolve = exports.objKeyVals = exports.objVals = void 0;
|
|
4
|
+
exports.objMap = objMap;
|
|
5
|
+
exports.objFilter = objFilter;
|
|
6
|
+
exports.objRemoveKeys = objRemoveKeys;
|
|
7
|
+
exports.objKeys = objKeys;
|
|
8
|
+
exports.objExtract = objExtract;
|
|
9
|
+
exports.objPromiseAll = objPromiseAll;
|
|
10
|
+
/** Maps over an object just as a [ ].map would on an array */
|
|
11
|
+
function objMap(o, funct) {
|
|
12
|
+
const newObj = {};
|
|
13
|
+
for (const key in o) {
|
|
14
|
+
newObj[key] = funct({ key, val: o[key] });
|
|
15
|
+
}
|
|
16
|
+
return newObj;
|
|
17
|
+
}
|
|
18
|
+
/** Filters out keys based on bool value returned by function */
|
|
19
|
+
function objFilter(o, funct) {
|
|
20
|
+
const newObj = { ...o };
|
|
21
|
+
for (const key in o) {
|
|
22
|
+
if (!funct({ key, val: o[key] }))
|
|
23
|
+
delete newObj[key];
|
|
24
|
+
}
|
|
25
|
+
return newObj;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Removes all keys from object in the `filterOut` array.
|
|
29
|
+
* The original object is not mutated.
|
|
30
|
+
*/
|
|
31
|
+
function objRemoveKeys(obj, filterOut) {
|
|
32
|
+
const newObj = { ...obj };
|
|
33
|
+
filterOut.forEach((key) => delete newObj[key]);
|
|
34
|
+
return newObj;
|
|
35
|
+
}
|
|
36
|
+
function objKeys(o) {
|
|
37
|
+
if (Object.keys)
|
|
38
|
+
return Object.keys(o);
|
|
39
|
+
const keys = [];
|
|
40
|
+
for (const k in o)
|
|
41
|
+
keys.push(k);
|
|
42
|
+
return keys;
|
|
43
|
+
}
|
|
44
|
+
const objVals = (o) => Object.values(o);
|
|
45
|
+
exports.objVals = objVals;
|
|
46
|
+
const objKeyVals = (o) => objKeys(o).map((key) => ({ key, val: o[key] }));
|
|
47
|
+
exports.objKeyVals = objKeyVals;
|
|
48
|
+
/**
|
|
49
|
+
* Creates a new object from `extract` object and an array of `keys` to
|
|
50
|
+
* transfer
|
|
51
|
+
*/
|
|
52
|
+
function objExtract(extract, keys) {
|
|
53
|
+
const newObj = {};
|
|
54
|
+
keys.forEach((key) => newObj[key] = extract[key]);
|
|
55
|
+
return newObj;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* @param o the object that is to be resolved
|
|
59
|
+
* @param path path to the desired value eg:
|
|
60
|
+
* ```ts
|
|
61
|
+
* "first.second.stuff" => obj.first.second.stuff
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
const objResolve = (o, path) => path.split('.').reduce((prev, key) => prev[key], o);
|
|
65
|
+
exports.objResolve = objResolve;
|
|
66
|
+
/**
|
|
67
|
+
* Takes a dictionary/object made of Promises and Observables and
|
|
68
|
+
* extracts all values. This function will return resolved values from all
|
|
69
|
+
* Observable/Promise on the obj when all promises on object resolve.
|
|
70
|
+
*/
|
|
71
|
+
function objPromiseAll(obj) {
|
|
72
|
+
const keyValues = (0, exports.objKeyVals)(obj);
|
|
73
|
+
const toEqual = keyValues.length;
|
|
74
|
+
const values = {};
|
|
75
|
+
let total = 0;
|
|
76
|
+
return new Promise((resolve) => keyValues.forEach(({ key, val: x }) => x.then((data) => {
|
|
77
|
+
values[key] = data;
|
|
78
|
+
total++;
|
|
79
|
+
if (toEqual === total)
|
|
80
|
+
resolve(values);
|
|
81
|
+
})));
|
|
82
|
+
}
|
|
93
83
|
//# sourceMappingURL=object.js.map
|
package/dist/object.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.js","sourceRoot":"","sources":["../src/object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,CAAC;IACd,OAAO,IAAI,OAAO,CAAgB,CAAC,OAAO,EAAE,EAAE,CAC1C,SAAS,CAAC,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAE,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;QACpD,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;QACnB,KAAK,EAAE,CAAC;QAER,IAAI,OAAO,KAAK,KAAK;YAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC,CACN,CAAC;AACN,CAAC"}
|
package/dist/string.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/** Checks if string includes a substring */
|
|
2
|
-
export declare const strIncludes: (str: string, subStr: string) => boolean;
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const minAppend: (item: string | number, length: number, append?: string) => string;
|
|
1
|
+
/** Checks if string includes a substring */
|
|
2
|
+
export declare const strIncludes: (str: string, subStr: string) => boolean;
|
|
3
|
+
export declare const strRemoveAll: (str: string, remove: string | RegExp) => string;
|
package/dist/string.js
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
/** Checks if string includes a substring */
|
|
5
|
-
const strIncludes = (str, subStr) => str.indexOf(subStr) !== -1;
|
|
6
|
-
exports.strIncludes = strIncludes;
|
|
7
|
-
const
|
|
8
|
-
exports.
|
|
9
|
-
// export const minAppend = (
|
|
10
|
-
// item: string | number, length: number, append = '0'
|
|
11
|
-
// ) => {
|
|
12
|
-
// item = item + '';
|
|
13
|
-
// if (length < 1) console.error(length, 'length can not be less than 1');
|
|
14
|
-
// if (item.length > length) console.error(item, 'item can not exceed length');
|
|
15
|
-
// return (append.repeat(length - 1) + item).slice(-(length))
|
|
16
|
-
// }
|
|
17
|
-
const minAppend = (item, length, append = '0') => (append.repeat(length - 1) + item).slice(-(length));
|
|
18
|
-
exports.minAppend = minAppend;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.strRemoveAll = exports.strIncludes = void 0;
|
|
4
|
+
/** Checks if string includes a substring */
|
|
5
|
+
const strIncludes = (str, subStr) => str.indexOf(subStr) !== -1;
|
|
6
|
+
exports.strIncludes = strIncludes;
|
|
7
|
+
const strRemoveAll = (str, remove) => str.replace(new RegExp(remove, 'g'), '');
|
|
8
|
+
exports.strRemoveAll = strRemoveAll;
|
|
19
9
|
//# sourceMappingURL=string.js.map
|
package/dist/string.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.js","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":";;;AAAA,4CAA4C;AACrC,MAAM,WAAW,GAAG,CAAC,GAAW,EAAE,MAAc,EAAE,EAAE,CACvD,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AADlB,QAAA,WAAW,eACO;AAExB,MAAM,
|
|
1
|
+
{"version":3,"file":"string.js","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":";;;AAAA,4CAA4C;AACrC,MAAM,WAAW,GAAG,CAAC,GAAW,EAAE,MAAc,EAAE,EAAE,CACvD,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AADlB,QAAA,WAAW,eACO;AAExB,MAAM,YAAY,GAAG,CAAC,GAAW,EAAE,MAAuB,EAAE,EAAE,CACjE,GAAG,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;AADhC,QAAA,YAAY,gBACoB"}
|
package/dist/test.d.ts
CHANGED
|
@@ -1,41 +1,40 @@
|
|
|
1
|
-
import { JsType } from '.';
|
|
2
|
-
import { JsTypeFind } from '.';
|
|
3
|
-
/** Check if `x` is equal to any of the values in the array. */
|
|
4
|
-
export declare const equalAny: (x: any, equals: any[]) => boolean;
|
|
5
|
-
/**
|
|
6
|
-
* Checks if object has the key, made as a function for type transfer.
|
|
7
|
-
*
|
|
8
|
-
* Uses `obj.hasOwnProperty(key)` instead of `key in obj`
|
|
9
|
-
*
|
|
10
|
-
* https://stackoverflow.com/questions/13632999/if-key-in-object-or-ifobject-hasownpropertykey
|
|
11
|
-
*/
|
|
12
|
-
export declare const hasKey: <K extends string | number>(obj: any, key: K) => obj is { [P in K]: any; };
|
|
13
|
-
/** Checks if object has keys from an array of keys, made as a function for type transfer */
|
|
14
|
-
export declare function hasKeys<K extends (string | number)>(obj: any, keys: K[]): obj is {
|
|
15
|
-
[P in K]: any;
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* The function will test if the type of the first
|
|
19
|
-
* argument equals testType. Argument testType is a string
|
|
20
|
-
* representing a javascript type.
|
|
21
|
-
*
|
|
22
|
-
* @param val value to be tested
|
|
23
|
-
* @param testType to check if typeof val === testType
|
|
24
|
-
* @example
|
|
25
|
-
* ```js
|
|
26
|
-
* isType([], 'array') //=> true
|
|
27
|
-
* isType(null, 'undefined') //=> false
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
export declare const isType: <T extends JsType>(val: any, testType: T) => val is JsTypeFind<T>;
|
|
31
|
-
/** any of the values in the first "example" return `true`
|
|
32
|
-
* @example
|
|
33
|
-
* ```js
|
|
34
|
-
* nullOrEmpty(null | undefined | '' | [ ] | { }) //=> true
|
|
35
|
-
* nullOrEmpty([1, 2] | { key: 'value' } | true) //=> false
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export declare function nullOrEmpty(x: any): boolean;
|
|
39
|
-
/** val `is` (null || undefined) */
|
|
40
|
-
export declare const
|
|
41
|
-
export declare const isValidEmail: (email: string) => boolean;
|
|
1
|
+
import { JsType } from '.';
|
|
2
|
+
import { JsTypeFind } from '.';
|
|
3
|
+
/** Check if `x` is equal to any of the values in the array. */
|
|
4
|
+
export declare const equalAny: (x: any, equals: any[]) => boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Checks if object has the key, made as a function for type transfer.
|
|
7
|
+
*
|
|
8
|
+
* Uses `obj.hasOwnProperty(key)` instead of `key in obj`
|
|
9
|
+
*
|
|
10
|
+
* https://stackoverflow.com/questions/13632999/if-key-in-object-or-ifobject-hasownpropertykey
|
|
11
|
+
*/
|
|
12
|
+
export declare const hasKey: <K extends (string | number)>(obj: any, key: K) => obj is { [P in K]: any; };
|
|
13
|
+
/** Checks if object has keys from an array of keys, made as a function for type transfer */
|
|
14
|
+
export declare function hasKeys<K extends (string | number)>(obj: any, keys: K[]): obj is {
|
|
15
|
+
[P in K]: any;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* The function will test if the type of the first
|
|
19
|
+
* argument equals testType. Argument testType is a string
|
|
20
|
+
* representing a javascript type.
|
|
21
|
+
*
|
|
22
|
+
* @param val value to be tested
|
|
23
|
+
* @param testType to check if typeof val === testType
|
|
24
|
+
* @example
|
|
25
|
+
* ```js
|
|
26
|
+
* isType([], 'array') //=> true
|
|
27
|
+
* isType(null, 'undefined') //=> false
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare const isType: <T extends JsType>(val: any, testType: T) => val is JsTypeFind<T>;
|
|
31
|
+
/** any of the values in the first "example" return `true`
|
|
32
|
+
* @example
|
|
33
|
+
* ```js
|
|
34
|
+
* nullOrEmpty(null | undefined | '' | [ ] | { }) //=> true
|
|
35
|
+
* nullOrEmpty([1, 2] | { key: 'value' } | true) //=> false
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function nullOrEmpty(x: any): boolean;
|
|
39
|
+
/** val `is` (null || undefined) */
|
|
40
|
+
export declare const nonVal: <T>(x: T | null | undefined) => x is (undefined | null);
|
package/dist/test.js
CHANGED
|
@@ -1,68 +1,66 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* @param
|
|
35
|
-
* @
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* isType(
|
|
39
|
-
*
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* nullOrEmpty(
|
|
48
|
-
*
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
/** val `is` (null || undefined) */
|
|
64
|
-
const
|
|
65
|
-
exports.
|
|
66
|
-
const isValidEmail = (email) => /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(email);
|
|
67
|
-
exports.isValidEmail = isValidEmail;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nonVal = exports.isType = exports.hasKey = exports.equalAny = void 0;
|
|
4
|
+
exports.hasKeys = hasKeys;
|
|
5
|
+
exports.nullOrEmpty = nullOrEmpty;
|
|
6
|
+
const _1 = require(".");
|
|
7
|
+
const _2 = require(".");
|
|
8
|
+
/** Check if `x` is equal to any of the values in the array. */
|
|
9
|
+
const equalAny = (x, equals) => !!equals.find((y) => (0, _1.equal)(x, y));
|
|
10
|
+
exports.equalAny = equalAny;
|
|
11
|
+
/**
|
|
12
|
+
* Checks if object has the key, made as a function for type transfer.
|
|
13
|
+
*
|
|
14
|
+
* Uses `obj.hasOwnProperty(key)` instead of `key in obj`
|
|
15
|
+
*
|
|
16
|
+
* https://stackoverflow.com/questions/13632999/if-key-in-object-or-ifobject-hasownpropertykey
|
|
17
|
+
*/
|
|
18
|
+
const hasKey = (obj, key) => (0, exports.isType)(obj, 'object') && obj.hasOwnProperty(key);
|
|
19
|
+
exports.hasKey = hasKey;
|
|
20
|
+
/** Checks if object has keys from an array of keys, made as a function for type transfer */
|
|
21
|
+
function hasKeys(obj, keys) {
|
|
22
|
+
if (!(0, exports.isType)(obj, 'object'))
|
|
23
|
+
return false;
|
|
24
|
+
for (const key of keys)
|
|
25
|
+
if (!obj.hasOwnProperty(key))
|
|
26
|
+
return false;
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The function will test if the type of the first
|
|
31
|
+
* argument equals testType. Argument testType is a string
|
|
32
|
+
* representing a javascript type.
|
|
33
|
+
*
|
|
34
|
+
* @param val value to be tested
|
|
35
|
+
* @param testType to check if typeof val === testType
|
|
36
|
+
* @example
|
|
37
|
+
* ```js
|
|
38
|
+
* isType([], 'array') //=> true
|
|
39
|
+
* isType(null, 'undefined') //=> false
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
const isType = (val, testType) => (0, _2.type)(val) === testType;
|
|
43
|
+
exports.isType = isType;
|
|
44
|
+
/** any of the values in the first "example" return `true`
|
|
45
|
+
* @example
|
|
46
|
+
* ```js
|
|
47
|
+
* nullOrEmpty(null | undefined | '' | [ ] | { }) //=> true
|
|
48
|
+
* nullOrEmpty([1, 2] | { key: 'value' } | true) //=> false
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
function nullOrEmpty(x) {
|
|
52
|
+
// null || undefined
|
|
53
|
+
if ((0, exports.nonVal)(x))
|
|
54
|
+
return true;
|
|
55
|
+
// (string || array).length === 0
|
|
56
|
+
if ((0, exports.isType)(x, 'string') || (0, exports.isType)(x, 'array'))
|
|
57
|
+
return !x.length;
|
|
58
|
+
// object // { key: 'val' } => false, { } => true
|
|
59
|
+
if ((0, exports.isType)(x, 'object'))
|
|
60
|
+
return !(0, _2.objVals)(x).length;
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
/** val `is` (null || undefined) */
|
|
64
|
+
const nonVal = (x) => x === null || x === undefined;
|
|
65
|
+
exports.nonVal = nonVal;
|
|
68
66
|
//# sourceMappingURL=test.js.map
|
package/dist/test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test.js","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"test.js","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":";;;AAmBA,0BASC;AA0BD,kCAWC;AAjED,wBAAkC;AAClC,wBAA8C;AAE9C,+DAA+D;AACxD,MAAM,QAAQ,GAAG,CAAC,CAAM,EAAE,MAAa,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,QAAK,EAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAAxE,QAAA,QAAQ,YAAgE;AAErF;;;;;;GAMG;AACI,MAAM,MAAM,GAAG,CAEpB,GAAQ,EAAE,GAAM,EAA4B,EAAE,CAC5C,IAAA,cAAM,EAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,GAAG,CAAC,cAAc,CAAC,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