@giveback007/util-lib 0.25.3 → 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.
Files changed (58) hide show
  1. package/README.md +7 -7
  2. package/dist/@types.d.ts +40 -42
  3. package/dist/@types.js +2 -2
  4. package/dist/array.d.ts +66 -66
  5. package/dist/array.js +128 -128
  6. package/dist/array.js.map +1 -1
  7. package/dist/clone.d.ts +2 -2
  8. package/dist/clone.js +44 -45
  9. package/dist/clone.js.map +1 -1
  10. package/dist/equality.d.ts +1 -1
  11. package/dist/equality.js +81 -82
  12. package/dist/equality.js.map +1 -1
  13. package/dist/general.d.ts +44 -37
  14. package/dist/general.js +172 -139
  15. package/dist/general.js.map +1 -1
  16. package/dist/index.d.ts +11 -11
  17. package/dist/index.js +27 -23
  18. package/dist/index.js.map +1 -1
  19. package/dist/iterate.d.ts +44 -44
  20. package/dist/iterate.js +43 -44
  21. package/dist/iterate.js.map +1 -1
  22. package/dist/number.d.ts +33 -32
  23. package/dist/number.js +57 -55
  24. package/dist/number.js.map +1 -1
  25. package/dist/object.d.ts +45 -49
  26. package/dist/object.js +82 -92
  27. package/dist/object.js.map +1 -1
  28. package/dist/string.d.ts +3 -4
  29. package/dist/string.js +8 -18
  30. package/dist/string.js.map +1 -1
  31. package/dist/test.d.ts +40 -41
  32. package/dist/test.js +65 -67
  33. package/dist/test.js.map +1 -1
  34. package/dist/time.d.ts +87 -93
  35. package/dist/time.js +230 -174
  36. package/dist/time.js.map +1 -1
  37. package/package.json +33 -45
  38. package/src/@types/types.d.ts +34 -0
  39. package/src/@types.ts +67 -67
  40. package/src/array.ts +175 -175
  41. package/src/clone.ts +34 -35
  42. package/src/equality.ts +80 -80
  43. package/src/general.ts +192 -152
  44. package/src/index.ts +11 -11
  45. package/src/iterate.ts +86 -86
  46. package/src/number.ts +64 -62
  47. package/src/object.ts +109 -123
  48. package/src/string.ts +6 -20
  49. package/src/test.ts +71 -74
  50. package/src/time.ts +268 -219
  51. package/dist/node/file-systems.d.ts +0 -1
  52. package/dist/node/file-systems.js +0 -16
  53. package/dist/node/file-systems.js.map +0 -1
  54. package/dist/node/index.d.ts +0 -1
  55. package/dist/node/index.js +0 -14
  56. package/dist/node/index.js.map +0 -1
  57. package/src/node/file-systems.ts +0 -16
  58. 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.objPromiseAll = exports.objSortKeys = exports.objResolve = exports.objExtract = exports.objKeyVals = exports.objVals = exports.objKeys = exports.objRemoveKeys = exports.objFilter = exports.objMap = void 0;
4
- /** Maps over an object just as a [ ].map would on an array */
5
- function objMap(o, funct) {
6
- const newObj = {};
7
- for (const key in o) {
8
- newObj[key] = funct({ key, val: o[key] });
9
- }
10
- return newObj;
11
- }
12
- exports.objMap = objMap;
13
- /** Filters out keys based on bool value returned by function */
14
- function objFilter(o, funct) {
15
- const newObj = Object.assign({}, o);
16
- for (const key in o) {
17
- if (!funct({ key, val: o[key] }))
18
- delete newObj[key];
19
- }
20
- return newObj;
21
- }
22
- exports.objFilter = objFilter;
23
- /**
24
- * Removes all keys from object in the `filterOut` array.
25
- * The original object is not mutated.
26
- */
27
- function objRemoveKeys(obj, filterOut) {
28
- const newObj = Object.assign({}, obj);
29
- filterOut.forEach((key) => delete newObj[key]);
30
- return newObj;
31
- }
32
- exports.objRemoveKeys = objRemoveKeys;
33
- function objKeys(o) {
34
- if (Object.keys)
35
- return Object.keys(o);
36
- const keys = [];
37
- for (const k in o)
38
- keys.push(k);
39
- return keys;
40
- }
41
- exports.objKeys = objKeys;
42
- const objVals = (o) => Object.values ? Object.values(o) : objKeys(o).map((key) => o[key]);
43
- exports.objVals = objVals;
44
- const objKeyVals = (o) => objKeys(o).map((key) => ({ key, val: o[key] }));
45
- exports.objKeyVals = objKeyVals;
46
- /**
47
- * Creates a new object from `extract` object and an array of `keys` to
48
- * transfer
49
- */
50
- function objExtract(extract, keys) {
51
- const newObj = {};
52
- keys.forEach((key) => newObj[key] = extract[key]);
53
- return newObj;
54
- }
55
- exports.objExtract = objExtract;
56
- /**
57
- * @param o the object that is to be resolved
58
- * @param path path to the desired value eg:
59
- * ```ts
60
- * "first.second.stuff" => obj.first.second.stuff
61
- * ```
62
- */
63
- const objResolve = (o, path) => path.split('.').reduce((prev, key) => prev[key], o);
64
- exports.objResolve = objResolve;
65
- /**
66
- * returns a new obj with the keys being sorted
67
- */
68
- const objSortKeys = (o, compareFn) => {
69
- const newObj = {};
70
- const keys = objKeys(o).sort(compareFn);
71
- keys.map((k) => newObj[k] = o[k]);
72
- return newObj;
73
- };
74
- exports.objSortKeys = objSortKeys;
75
- /**
76
- * Takes a dictionary/object made of Promises and Observables and
77
- * extracts all values. This function will return resolved values from all
78
- * Observable/Promise on the obj when all promises on object resolve.
79
- */
80
- function objPromiseAll(obj) {
81
- const keyValues = exports.objKeyVals(obj);
82
- const toEqual = keyValues.length;
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
@@ -1 +1 @@
1
- {"version":3,"file":"object.js","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":";;;AAEA,8DA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AAU,cAC6B;AAEpD;;;GAGG;AACH,SAAgB,UAAU,CAIxB,OAAU,EAAE,IAAS;IAEnB,MAAM,MAAM,GAAG,EAAQ,CAAC;IACxB,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAE,MAAM,CAAC,GAAG,CAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;IAEnE,OAAO,MAAM,CAAC;AAClB,CAAC;AAED;;;;;;GAMG;AACI,MAAM,UAAU,GAAG,CAAC,CAAS,EAAE,IAAY,EAAO,EAAE,CACvD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;AAD3C,QAAA,UAAU,cACiC;AAExD;;;;GAIG;AACH,SAAgB,aAAa,CAA+B,GAAM;IAC9D,MAAM,SAAS,GAAG,IAAA,kBAAU,EAAC,GAAG,CAAC,CAAC;IAClC,MAAM,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC;IACjC,MAAM,MAAM,GAAG,EAA8C,CAAC;IAE9D,IAAI,KAAK,GAAG,CAAC,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 strRemove: (str: string, remove: string | RegExp) => string;
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.minAppend = exports.strRemove = 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 strRemove = (str, remove) => str.replace(new RegExp(remove, 'g'), '');
8
- exports.strRemove = strRemove;
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
@@ -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,SAAS,GAAG,CAAC,GAAW,EAAE,MAAuB,EAAE,EAAE,CAC9D,GAAG,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;AADhC,QAAA,SAAS,aACuB;AAE7C,6BAA6B;AAC7B,0DAA0D;AAC1D,SAAS;AACT,wBAAwB;AACxB,8EAA8E;AAC9E,mFAAmF;AAEnF,iEAAiE;AACjE,IAAI;AAEG,MAAM,SAAS,GAAG,CACrB,IAAqB,EAAE,MAAc,EAAE,MAAM,GAAG,GAAG,EACrD,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAF5C,QAAA,SAAS,aAEmC"}
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 nonValue: (val: any) => val is null | undefined;
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.isValidEmail = exports.nonValue = exports.nullOrEmpty = exports.isType = exports.hasKeys = exports.hasKey = exports.equalAny = void 0;
4
- const _1 = require(".");
5
- const _2 = require(".");
6
- /** Check if `x` is equal to any of the values in the array. */
7
- const equalAny = (x, equals) => !!equals.find((y) => _1.equal(x, y));
8
- exports.equalAny = equalAny;
9
- /**
10
- * Checks if object has the key, made as a function for type transfer.
11
- *
12
- * Uses `obj.hasOwnProperty(key)` instead of `key in obj`
13
- *
14
- * https://stackoverflow.com/questions/13632999/if-key-in-object-or-ifobject-hasownpropertykey
15
- */
16
- const hasKey = (obj, key) => exports.isType(obj, 'object') && obj.hasOwnProperty(key);
17
- exports.hasKey = hasKey;
18
- /** Checks if object has keys from an array of keys, made as a function for type transfer */
19
- function hasKeys(obj, keys) {
20
- if (!exports.isType(obj, 'object'))
21
- return false;
22
- for (const key of keys)
23
- if (!obj.hasOwnProperty(key))
24
- return false;
25
- return true;
26
- }
27
- exports.hasKeys = hasKeys;
28
- /**
29
- * The function will test if the type of the first
30
- * argument equals testType. Argument testType is a string
31
- * representing a javascript type.
32
- *
33
- * @param val value to be tested
34
- * @param testType to check if typeof val === testType
35
- * @example
36
- * ```js
37
- * isType([], 'array') //=> true
38
- * isType(null, 'undefined') //=> false
39
- * ```
40
- */
41
- const isType = (val, testType) => _2.type(val) === testType;
42
- exports.isType = isType;
43
- /** any of the values in the first "example" return `true`
44
- * @example
45
- * ```js
46
- * nullOrEmpty(null | undefined | '' | [ ] | { }) //=> true
47
- * nullOrEmpty([1, 2] | { key: 'value' } | true) //=> false
48
- * ```
49
- */
50
- function nullOrEmpty(x) {
51
- // null || undefined
52
- if (exports.nonValue(x))
53
- return true;
54
- // (string || array).length === 0
55
- if (exports.isType(x, 'string') || exports.isType(x, 'array'))
56
- return !x.length;
57
- // object // { key: 'val' } => false, { } => true
58
- if (exports.isType(x, 'object'))
59
- return !_2.objVals(x).length;
60
- return false;
61
- }
62
- exports.nullOrEmpty = nullOrEmpty;
63
- /** val `is` (null || undefined) */
64
- const nonValue = (val) => val === null || val === undefined;
65
- exports.nonValue = nonValue;
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":";;;AAAA,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,CA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