@omnific/utils 0.2.0 → 0.3.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/dist/createChainedFunction.js +2 -1
- package/dist/debounce.js +1 -1
- package/dist/get.js +2 -1
- package/dist/isArrayEmpty.d.ts +9 -0
- package/dist/isArrayEmpty.js +13 -0
- package/dist/isNumber.js +2 -1
- package/dist/isPromise.js +2 -1
- package/dist/isStringEmpty.d.ts +9 -0
- package/dist/isStringEmpty.js +13 -0
- package/dist/main.d.ts +3 -1
- package/dist/main.js +6 -4
- package/dist/parseJson.js +2 -1
- package/dist/utils/toPath.js +2 -1
- package/package.json +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isArrayEmpty } from "./isArrayEmpty.js";
|
|
1
2
|
import { isFunction } from "./isFunction.js";
|
|
2
3
|
//#region createChainedFunction.ts
|
|
3
4
|
/**
|
|
@@ -13,7 +14,7 @@ import { isFunction } from "./isFunction.js";
|
|
|
13
14
|
*/
|
|
14
15
|
function createChainedFunction(...funcs) {
|
|
15
16
|
const validFuncs = funcs.filter((function_) => isFunction(function_));
|
|
16
|
-
if (validFuncs
|
|
17
|
+
if (isArrayEmpty(validFuncs)) return function() {};
|
|
17
18
|
if (validFuncs.length === 1) return validFuncs[0];
|
|
18
19
|
return function(...arguments_) {
|
|
19
20
|
for (const function_ of validFuncs) function_.apply(this, arguments_);
|
package/dist/debounce.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import hasValue from "./hasValue.js";
|
|
2
1
|
import { isUndefined } from "./isUndefined.js";
|
|
3
2
|
import { isNil } from "./isNil.js";
|
|
3
|
+
import hasValue from "./hasValue.js";
|
|
4
4
|
//#region debounce.ts
|
|
5
5
|
/**
|
|
6
6
|
* Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds
|
package/dist/get.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isUndefined } from "./isUndefined.js";
|
|
2
2
|
import { isNil } from "./isNil.js";
|
|
3
|
+
import { isArrayEmpty } from "./isArrayEmpty.js";
|
|
3
4
|
import { isNumber } from "./isNumber.js";
|
|
4
5
|
import { isString } from "./isString.js";
|
|
5
6
|
import { isUnsafeProperty } from "./_internal/isUnsafeProperty.js";
|
|
@@ -41,7 +42,7 @@ function get(object, path, defaultValue) {
|
|
|
41
42
|
return getDirect(object, normalizeKey(path), defaultValue);
|
|
42
43
|
}
|
|
43
44
|
function getWithPath(object, path, defaultValue) {
|
|
44
|
-
if (path
|
|
45
|
+
if (isArrayEmpty(path)) return defaultValue;
|
|
45
46
|
let current = object;
|
|
46
47
|
for (const element of path) {
|
|
47
48
|
if (isNil(current) || isUnsafeProperty(element)) return defaultValue;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region isArrayEmpty.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Checks whether a value is nullish or an empty array.
|
|
4
|
+
*
|
|
5
|
+
* `null`, `undefined`, and arrays without elements are considered empty.
|
|
6
|
+
*/
|
|
7
|
+
declare function isArrayEmpty<T>(value: readonly T[] | null | undefined): value is null | undefined | readonly [];
|
|
8
|
+
//#endregion
|
|
9
|
+
export { isArrayEmpty };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isNil } from "./isNil.js";
|
|
2
|
+
//#region isArrayEmpty.ts
|
|
3
|
+
/**
|
|
4
|
+
* Checks whether a value is nullish or an empty array.
|
|
5
|
+
*
|
|
6
|
+
* `null`, `undefined`, and arrays without elements are considered empty.
|
|
7
|
+
*/
|
|
8
|
+
function isArrayEmpty(value) {
|
|
9
|
+
if (isNil(value)) return true;
|
|
10
|
+
return value.length === 0;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { isArrayEmpty };
|
package/dist/isNumber.js
CHANGED
package/dist/isPromise.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import hasValue from "./hasValue.js";
|
|
1
2
|
import { isFunction } from "./isFunction.js";
|
|
2
3
|
import { isObject } from "./isObject.js";
|
|
3
4
|
//#region isPromise.ts
|
|
@@ -19,7 +20,7 @@ import { isObject } from "./isObject.js";
|
|
|
19
20
|
* console.log(isPromise(value3)); // false
|
|
20
21
|
*/
|
|
21
22
|
function isPromise(value) {
|
|
22
|
-
return value
|
|
23
|
+
return hasValue(value) && (isObject(value) || isFunction(value)) && isFunction(value.then);
|
|
23
24
|
}
|
|
24
25
|
//#endregion
|
|
25
26
|
export { isPromise };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region isStringEmpty.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Checks whether a value is nullish or an empty string.
|
|
4
|
+
*
|
|
5
|
+
* `null`, `undefined`, and whitespace-only strings are considered empty.
|
|
6
|
+
*/
|
|
7
|
+
declare function isStringEmpty(value: string | null | undefined): value is null | undefined;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { isStringEmpty };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isNil } from "./isNil.js";
|
|
2
|
+
//#region isStringEmpty.ts
|
|
3
|
+
/**
|
|
4
|
+
* Checks whether a value is nullish or an empty string.
|
|
5
|
+
*
|
|
6
|
+
* `null`, `undefined`, and whitespace-only strings are considered empty.
|
|
7
|
+
*/
|
|
8
|
+
function isStringEmpty(value) {
|
|
9
|
+
if (isNil(value)) return true;
|
|
10
|
+
return value.trim().length === 0;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { isStringEmpty };
|
package/dist/main.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { get } from "./get.js";
|
|
|
4
4
|
import hasValue from "./hasValue.js";
|
|
5
5
|
import { isArray } from "./isArray.js";
|
|
6
6
|
import { isArrayBuffer } from "./isArrayBuffer.js";
|
|
7
|
+
import { isArrayEmpty } from "./isArrayEmpty.js";
|
|
7
8
|
import { isBlob } from "./isBlob.js";
|
|
8
9
|
import { isBoolean } from "./isBoolean.js";
|
|
9
10
|
import { isFormData } from "./isFormData.js";
|
|
@@ -15,6 +16,7 @@ import { isObject } from "./isObject.js";
|
|
|
15
16
|
import { isPlainObject } from "./isPlainObject.js";
|
|
16
17
|
import { isPromise } from "./isPromise.js";
|
|
17
18
|
import { isString } from "./isString.js";
|
|
19
|
+
import { isStringEmpty } from "./isStringEmpty.js";
|
|
18
20
|
import { isSymbol } from "./isSymbol.js";
|
|
19
21
|
import { isURLSearchParameters } from "./isURLSearchParameters.js";
|
|
20
22
|
import { isUndefined } from "./isUndefined.js";
|
|
@@ -22,4 +24,4 @@ import { parseJson } from "./parseJson.js";
|
|
|
22
24
|
import { ThrottleOptions, ThrottledFunction, throttle } from "./throttle.js";
|
|
23
25
|
import resolveValue from "./resolveValue.js";
|
|
24
26
|
import { uniqueId } from "./uniqueId.js";
|
|
25
|
-
export { type ChainedFunction, type DebounceOptions, type DebouncedFunction, type ThrottleOptions, type ThrottledFunction, createChainedFunction, debounce, get, hasValue, isArray, isArrayBuffer, isBlob, isBoolean, isFormData, isFunction, isNil, isNull, isNumber, isObject, isPlainObject, isPromise, isString,
|
|
27
|
+
export { type ChainedFunction, type DebounceOptions, type DebouncedFunction, type ThrottleOptions, type ThrottledFunction, createChainedFunction, debounce, get, hasValue, isArray, isArrayBuffer, isArrayEmpty, isBlob, isBoolean, isFormData, isFunction, isNil, isNull, isNumber, isObject, isPlainObject, isPromise, isString, isStringEmpty, isSymbol, isURLSearchParameters, isUndefined, parseJson, resolveValue, throttle, uniqueId };
|
package/dist/main.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { isArray } from "./isArray.js";
|
|
2
|
+
import { isUndefined } from "./isUndefined.js";
|
|
3
|
+
import { isNull } from "./isNull.js";
|
|
4
|
+
import { isNil } from "./isNil.js";
|
|
5
|
+
import { isArrayEmpty } from "./isArrayEmpty.js";
|
|
2
6
|
import { isBoolean } from "./isBoolean.js";
|
|
3
7
|
import hasValue from "./hasValue.js";
|
|
4
8
|
import { isBlob } from "./isBlob.js";
|
|
5
9
|
import { isFunction } from "./isFunction.js";
|
|
6
10
|
import { createChainedFunction } from "./createChainedFunction.js";
|
|
7
|
-
import { isUndefined } from "./isUndefined.js";
|
|
8
|
-
import { isNull } from "./isNull.js";
|
|
9
|
-
import { isNil } from "./isNil.js";
|
|
10
11
|
import { debounce } from "./debounce.js";
|
|
11
12
|
import { isFormData } from "./isFormData.js";
|
|
12
13
|
import { isNumber } from "./isNumber.js";
|
|
13
14
|
import { isObject } from "./isObject.js";
|
|
14
15
|
import { isPlainObject } from "./isPlainObject.js";
|
|
15
16
|
import { isString } from "./isString.js";
|
|
17
|
+
import { isStringEmpty } from "./isStringEmpty.js";
|
|
16
18
|
import { isPromise } from "./isPromise.js";
|
|
17
19
|
import { isArrayBuffer } from "./isArrayBuffer.js";
|
|
18
20
|
import { isURLSearchParameters } from "./isURLSearchParameters.js";
|
|
@@ -22,4 +24,4 @@ import { get } from "./get.js";
|
|
|
22
24
|
import { throttle } from "./throttle.js";
|
|
23
25
|
import resolveValue from "./resolveValue.js";
|
|
24
26
|
import { uniqueId } from "./uniqueId.js";
|
|
25
|
-
export { createChainedFunction, debounce, get, hasValue, isArray, isArrayBuffer, isBlob, isBoolean, isFormData, isFunction, isNil, isNull, isNumber, isObject, isPlainObject, isPromise, isString,
|
|
27
|
+
export { createChainedFunction, debounce, get, hasValue, isArray, isArrayBuffer, isArrayEmpty, isBlob, isBoolean, isFormData, isFunction, isNil, isNull, isNumber, isObject, isPlainObject, isPromise, isString, isStringEmpty, isSymbol, isURLSearchParameters, isUndefined, parseJson, resolveValue, throttle, uniqueId };
|
package/dist/parseJson.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isStringEmpty } from "./isStringEmpty.js";
|
|
1
2
|
//#region parseJson.ts
|
|
2
3
|
/**
|
|
3
4
|
* Parses JSON text into a value.
|
|
@@ -6,7 +7,7 @@
|
|
|
6
7
|
* returns the fallback instead of throwing.
|
|
7
8
|
*/
|
|
8
9
|
function parseJson(text, fallback) {
|
|
9
|
-
if (
|
|
10
|
+
if (isStringEmpty(text)) return;
|
|
10
11
|
try {
|
|
11
12
|
return JSON.parse(text);
|
|
12
13
|
} catch (error) {
|
package/dist/utils/toPath.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isSymbol } from "../isSymbol.js";
|
|
1
2
|
import { toKey } from "../_internal/toKey.js";
|
|
2
3
|
import { toString } from "./toString.js";
|
|
3
4
|
//#region utils/toPath.ts
|
|
@@ -20,7 +21,7 @@ import { toString } from "./toString.js";
|
|
|
20
21
|
*/
|
|
21
22
|
function toPath(deepKey) {
|
|
22
23
|
if (Array.isArray(deepKey)) return deepKey.map((item) => toKey(item));
|
|
23
|
-
if (
|
|
24
|
+
if (isSymbol(deepKey)) return [deepKey];
|
|
24
25
|
deepKey = toString(deepKey);
|
|
25
26
|
const result = [];
|
|
26
27
|
const length = deepKey.length;
|