@omnific/utils 0.0.2 → 0.0.4
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/@types/GetFieldType.d.ts +13 -0
- package/dist/@types/Many.d.ts +4 -0
- package/dist/@types/PropertyPath.d.ts +6 -0
- package/dist/_internal/isDeepKey.js +25 -0
- package/dist/_internal/isUnsafeProperty.js +16 -0
- package/dist/_internal/toKey.js +19 -0
- package/dist/createChainedFunction.d.ts +19 -0
- package/dist/createChainedFunction.js +23 -0
- package/dist/get.d.ts +328 -0
- package/dist/get.js +58 -0
- package/dist/hasValue.d.ts +20 -0
- package/dist/hasValue.js +23 -0
- package/dist/isArray.d.ts +24 -0
- package/dist/isArray.js +26 -0
- package/dist/isBoolean.d.ts +26 -0
- package/dist/isBoolean.js +28 -0
- package/dist/isFunction.d.ts +17 -0
- package/dist/isFunction.js +19 -0
- package/dist/isNil.d.ts +23 -0
- package/dist/isNil.js +27 -0
- package/dist/isNull.d.ts +24 -0
- package/dist/isNull.js +26 -0
- package/dist/isNumber.d.ts +26 -0
- package/dist/isNumber.js +28 -0
- package/dist/isObject.d.ts +27 -0
- package/dist/isObject.js +29 -0
- package/dist/isPromise.d.ts +21 -0
- package/dist/isPromise.js +25 -0
- package/dist/isString.d.ts +21 -0
- package/dist/isString.js +23 -0
- package/dist/isSymbol.d.ts +27 -0
- package/dist/isSymbol.js +29 -0
- package/dist/isUndefined.d.ts +24 -0
- package/dist/isUndefined.js +26 -0
- package/dist/main.d.ts +16 -155
- package/dist/main.js +16 -194
- package/dist/resolveValue.d.ts +17 -0
- package/dist/resolveValue.js +21 -0
- package/dist/utils/toPath.js +67 -0
- package/dist/utils/toString.js +28 -0
- package/package.json +8 -3
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region isBoolean.ts
|
|
2
|
+
/**
|
|
3
|
+
* Checks if the given value is boolean.
|
|
4
|
+
*
|
|
5
|
+
* This function tests whether the provided value is strictly `boolean`.
|
|
6
|
+
* It returns `true` if the value is `boolean`, and `false` otherwise.
|
|
7
|
+
*
|
|
8
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `boolean`.
|
|
9
|
+
*
|
|
10
|
+
* @param {unknown} x - The Value to test if it is boolean.
|
|
11
|
+
* @returns {x is boolean} True if the value is boolean, false otherwise.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
*
|
|
15
|
+
* const value1 = true;
|
|
16
|
+
* const value2 = 0;
|
|
17
|
+
* const value3 = 'abc';
|
|
18
|
+
*
|
|
19
|
+
* console.log(isBoolean(value1)); // true
|
|
20
|
+
* console.log(isBoolean(value2)); // false
|
|
21
|
+
* console.log(isBoolean(value3)); // false
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
function isBoolean(x) {
|
|
25
|
+
return typeof x === "boolean";
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { isBoolean };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region isFunction.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Checks if `value` is a function.
|
|
4
|
+
*
|
|
5
|
+
* @param {any} value The value to check.
|
|
6
|
+
* @returns {boolean} Returns `true` if `value` is a function, else `false`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* isFunction(Array.prototype.slice); // true
|
|
10
|
+
* isFunction(async function () {}); // true
|
|
11
|
+
* isFunction(function* () {}); // true
|
|
12
|
+
* isFunction(Proxy); // true
|
|
13
|
+
* isFunction(Int8Array); // true
|
|
14
|
+
*/
|
|
15
|
+
declare function isFunction(value: any): value is (...args: any[]) => any;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { isFunction };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region isFunction.ts
|
|
2
|
+
/**
|
|
3
|
+
* Checks if `value` is a function.
|
|
4
|
+
*
|
|
5
|
+
* @param {any} value The value to check.
|
|
6
|
+
* @returns {boolean} Returns `true` if `value` is a function, else `false`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* isFunction(Array.prototype.slice); // true
|
|
10
|
+
* isFunction(async function () {}); // true
|
|
11
|
+
* isFunction(function* () {}); // true
|
|
12
|
+
* isFunction(Proxy); // true
|
|
13
|
+
* isFunction(Int8Array); // true
|
|
14
|
+
*/
|
|
15
|
+
function isFunction(value) {
|
|
16
|
+
return typeof value === "function";
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { isFunction };
|
package/dist/isNil.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region isNil.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a given value is null or undefined.
|
|
4
|
+
*
|
|
5
|
+
* This function tests whether the provided value is either `null` or `undefined`.
|
|
6
|
+
* It returns `true` if the value is `null` or `undefined`, and `false` otherwise.
|
|
7
|
+
*
|
|
8
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `null` or `undefined`.
|
|
9
|
+
*
|
|
10
|
+
* @param {unknown} x - The value to test for null or undefined.
|
|
11
|
+
* @returns {boolean} `true` if the value is null or undefined, `false` otherwise.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const value1 = null;
|
|
15
|
+
* const value2 = undefined;
|
|
16
|
+
* const value3 = 42;
|
|
17
|
+
* const result1 = isNil(value1); // true
|
|
18
|
+
* const result2 = isNil(value2); // true
|
|
19
|
+
* const result3 = isNil(value3); // false
|
|
20
|
+
*/
|
|
21
|
+
declare function isNil(x: unknown): x is null | undefined;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { isNil };
|
package/dist/isNil.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { isUndefined } from "./isUndefined.js";
|
|
2
|
+
import { isNull } from "./isNull.js";
|
|
3
|
+
//#region isNil.ts
|
|
4
|
+
/**
|
|
5
|
+
* Checks if a given value is null or undefined.
|
|
6
|
+
*
|
|
7
|
+
* This function tests whether the provided value is either `null` or `undefined`.
|
|
8
|
+
* It returns `true` if the value is `null` or `undefined`, and `false` otherwise.
|
|
9
|
+
*
|
|
10
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `null` or `undefined`.
|
|
11
|
+
*
|
|
12
|
+
* @param {unknown} x - The value to test for null or undefined.
|
|
13
|
+
* @returns {boolean} `true` if the value is null or undefined, `false` otherwise.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const value1 = null;
|
|
17
|
+
* const value2 = undefined;
|
|
18
|
+
* const value3 = 42;
|
|
19
|
+
* const result1 = isNil(value1); // true
|
|
20
|
+
* const result2 = isNil(value2); // true
|
|
21
|
+
* const result3 = isNil(value3); // false
|
|
22
|
+
*/
|
|
23
|
+
function isNil(x) {
|
|
24
|
+
return isNull(x) || isUndefined(x);
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { isNil };
|
package/dist/isNull.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region isNull.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Checks if the given value is null.
|
|
4
|
+
*
|
|
5
|
+
* This function tests whether the provided value is strictly equal to `null`.
|
|
6
|
+
* It returns `true` if the value is `null`, and `false` otherwise.
|
|
7
|
+
*
|
|
8
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `null`.
|
|
9
|
+
*
|
|
10
|
+
* @param {unknown} x - The value to test if it is null.
|
|
11
|
+
* @returns {x is null} True if the value is null, false otherwise.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const value1 = null;
|
|
15
|
+
* const value2 = undefined;
|
|
16
|
+
* const value3 = 42;
|
|
17
|
+
*
|
|
18
|
+
* console.log(isNull(value1)); // true
|
|
19
|
+
* console.log(isNull(value2)); // false
|
|
20
|
+
* console.log(isNull(value3)); // false
|
|
21
|
+
*/
|
|
22
|
+
declare function isNull(x: unknown): x is null;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { isNull };
|
package/dist/isNull.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region isNull.ts
|
|
2
|
+
/**
|
|
3
|
+
* Checks if the given value is null.
|
|
4
|
+
*
|
|
5
|
+
* This function tests whether the provided value is strictly equal to `null`.
|
|
6
|
+
* It returns `true` if the value is `null`, and `false` otherwise.
|
|
7
|
+
*
|
|
8
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `null`.
|
|
9
|
+
*
|
|
10
|
+
* @param {unknown} x - The value to test if it is null.
|
|
11
|
+
* @returns {x is null} True if the value is null, false otherwise.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const value1 = null;
|
|
15
|
+
* const value2 = undefined;
|
|
16
|
+
* const value3 = 42;
|
|
17
|
+
*
|
|
18
|
+
* console.log(isNull(value1)); // true
|
|
19
|
+
* console.log(isNull(value2)); // false
|
|
20
|
+
* console.log(isNull(value3)); // false
|
|
21
|
+
*/
|
|
22
|
+
function isNull(x) {
|
|
23
|
+
return x === null;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { isNull };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region isNumber.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Checks if the given value is a number.
|
|
4
|
+
*
|
|
5
|
+
* This function tests whether the provided value is strictly a `number`.
|
|
6
|
+
* It returns `true` if the value is a `number`, and `false` otherwise.
|
|
7
|
+
*
|
|
8
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `number`.
|
|
9
|
+
*
|
|
10
|
+
* @param {unknown} x - The value to test if it is a number.
|
|
11
|
+
* @returns {x is number} True if the value is a number, false otherwise.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
*
|
|
15
|
+
* const value1 = 123;
|
|
16
|
+
* const value2 = 'abc';
|
|
17
|
+
* const value3 = true;
|
|
18
|
+
*
|
|
19
|
+
* console.log(isNumber(value1)); // true
|
|
20
|
+
* console.log(isNumber(value2)); // false
|
|
21
|
+
* console.log(isNumber(value3)); // false
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
declare function isNumber(value: unknown): value is number;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { isNumber };
|
package/dist/isNumber.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region isNumber.ts
|
|
2
|
+
/**
|
|
3
|
+
* Checks if the given value is a number.
|
|
4
|
+
*
|
|
5
|
+
* This function tests whether the provided value is strictly a `number`.
|
|
6
|
+
* It returns `true` if the value is a `number`, and `false` otherwise.
|
|
7
|
+
*
|
|
8
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `number`.
|
|
9
|
+
*
|
|
10
|
+
* @param {unknown} x - The value to test if it is a number.
|
|
11
|
+
* @returns {x is number} True if the value is a number, false otherwise.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
*
|
|
15
|
+
* const value1 = 123;
|
|
16
|
+
* const value2 = 'abc';
|
|
17
|
+
* const value3 = true;
|
|
18
|
+
*
|
|
19
|
+
* console.log(isNumber(value1)); // true
|
|
20
|
+
* console.log(isNumber(value2)); // false
|
|
21
|
+
* console.log(isNumber(value3)); // false
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
function isNumber(value) {
|
|
25
|
+
return typeof value === "number" && !Number.isNaN(value);
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { isNumber };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region isObject.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Checks if the given value is an object. An object is a value that is
|
|
4
|
+
* not a primitive type (string, number, boolean, symbol, null, or undefined).
|
|
5
|
+
*
|
|
6
|
+
* This function tests whether the provided value is an object or not.
|
|
7
|
+
* It returns `true` if the value is an object, and `false` otherwise.
|
|
8
|
+
*
|
|
9
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to an object value.
|
|
10
|
+
*
|
|
11
|
+
* @param {any} value - The value to check if it is an object.
|
|
12
|
+
* @returns {value is object} `true` if the value is an object, `false` otherwise.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const value1 = {};
|
|
16
|
+
* const value2 = [1, 2, 3];
|
|
17
|
+
* const value3 = () => {};
|
|
18
|
+
* const value4 = null;
|
|
19
|
+
*
|
|
20
|
+
* console.log(isObject(value1)); // true
|
|
21
|
+
* console.log(isObject(value2)); // true
|
|
22
|
+
* console.log(isObject(value3)); // true
|
|
23
|
+
* console.log(isObject(value4)); // false
|
|
24
|
+
*/
|
|
25
|
+
declare function isObject(value?: any): value is object;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { isObject };
|
package/dist/isObject.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region isObject.ts
|
|
2
|
+
/**
|
|
3
|
+
* Checks if the given value is an object. An object is a value that is
|
|
4
|
+
* not a primitive type (string, number, boolean, symbol, null, or undefined).
|
|
5
|
+
*
|
|
6
|
+
* This function tests whether the provided value is an object or not.
|
|
7
|
+
* It returns `true` if the value is an object, and `false` otherwise.
|
|
8
|
+
*
|
|
9
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to an object value.
|
|
10
|
+
*
|
|
11
|
+
* @param {any} value - The value to check if it is an object.
|
|
12
|
+
* @returns {value is object} `true` if the value is an object, `false` otherwise.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const value1 = {};
|
|
16
|
+
* const value2 = [1, 2, 3];
|
|
17
|
+
* const value3 = () => {};
|
|
18
|
+
* const value4 = null;
|
|
19
|
+
*
|
|
20
|
+
* console.log(isObject(value1)); // true
|
|
21
|
+
* console.log(isObject(value2)); // true
|
|
22
|
+
* console.log(isObject(value3)); // true
|
|
23
|
+
* console.log(isObject(value4)); // false
|
|
24
|
+
*/
|
|
25
|
+
function isObject(value) {
|
|
26
|
+
return value !== null && (typeof value === "object" || typeof value === "function");
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { isObject };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region isPromise.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a given value is `Promise`.
|
|
4
|
+
*
|
|
5
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `Promise`.
|
|
6
|
+
*
|
|
7
|
+
* @param {unknown} value The value to check if it is a `Promise`.
|
|
8
|
+
* @returns {value is Promise<any>} Returns `true` if `value` is a `Promise`, else `false`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const value1 = new Promise((resolve) => resolve());
|
|
12
|
+
* const value2 = {};
|
|
13
|
+
* const value3 = 123;
|
|
14
|
+
*
|
|
15
|
+
* console.log(isPromise(value1)); // true
|
|
16
|
+
* console.log(isPromise(value2)); // false
|
|
17
|
+
* console.log(isPromise(value3)); // false
|
|
18
|
+
*/
|
|
19
|
+
declare function isPromise(value: unknown): value is Promise<any>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { isPromise };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { isFunction } from "./isFunction.js";
|
|
2
|
+
import { isObject } from "./isObject.js";
|
|
3
|
+
//#region isPromise.ts
|
|
4
|
+
/**
|
|
5
|
+
* Checks if a given value is `Promise`.
|
|
6
|
+
*
|
|
7
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `Promise`.
|
|
8
|
+
*
|
|
9
|
+
* @param {unknown} value The value to check if it is a `Promise`.
|
|
10
|
+
* @returns {value is Promise<any>} Returns `true` if `value` is a `Promise`, else `false`.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const value1 = new Promise((resolve) => resolve());
|
|
14
|
+
* const value2 = {};
|
|
15
|
+
* const value3 = 123;
|
|
16
|
+
*
|
|
17
|
+
* console.log(isPromise(value1)); // true
|
|
18
|
+
* console.log(isPromise(value2)); // false
|
|
19
|
+
* console.log(isPromise(value3)); // false
|
|
20
|
+
*/
|
|
21
|
+
function isPromise(value) {
|
|
22
|
+
return value !== null && (isObject(value) || isFunction(value)) && typeof value.then === "function";
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { isPromise };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region isString.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a given value is string.
|
|
4
|
+
*
|
|
5
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `string`.
|
|
6
|
+
*
|
|
7
|
+
* @param {unknown} value The value to check if it is string.
|
|
8
|
+
* @returns {value is string} Returns `true` if `value` is a string, else `false`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const value1 = 'abc';
|
|
12
|
+
* const value2 = 123;
|
|
13
|
+
* const value3 = true;
|
|
14
|
+
*
|
|
15
|
+
* console.log(isString(value1)); // true
|
|
16
|
+
* console.log(isString(value2)); // false
|
|
17
|
+
* console.log(isString(value3)); // false
|
|
18
|
+
*/
|
|
19
|
+
declare function isString(value: unknown): value is string;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { isString };
|
package/dist/isString.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region isString.ts
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a given value is string.
|
|
4
|
+
*
|
|
5
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `string`.
|
|
6
|
+
*
|
|
7
|
+
* @param {unknown} value The value to check if it is string.
|
|
8
|
+
* @returns {value is string} Returns `true` if `value` is a string, else `false`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const value1 = 'abc';
|
|
12
|
+
* const value2 = 123;
|
|
13
|
+
* const value3 = true;
|
|
14
|
+
*
|
|
15
|
+
* console.log(isString(value1)); // true
|
|
16
|
+
* console.log(isString(value2)); // false
|
|
17
|
+
* console.log(isString(value3)); // false
|
|
18
|
+
*/
|
|
19
|
+
function isString(value) {
|
|
20
|
+
return typeof value === "string";
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { isString };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region isSymbol.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Check whether a value is a symbol.
|
|
4
|
+
*
|
|
5
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `symbol`.
|
|
6
|
+
*
|
|
7
|
+
* @param {unknown} value The value to check.
|
|
8
|
+
* @returns {value is symbol} Returns `true` if `value` is a symbol, else `false`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* import { isSymbol } from 'es-toolkit/predicate';
|
|
12
|
+
*
|
|
13
|
+
* isSymbol(Symbol('a')); // true
|
|
14
|
+
* isSymbol(Symbol.for('a')); // true
|
|
15
|
+
* isSymbol(Symbol.iterator); // true
|
|
16
|
+
*
|
|
17
|
+
* isSymbol(null); // false
|
|
18
|
+
* isSymbol(undefined); // false
|
|
19
|
+
* isSymbol('123'); // false
|
|
20
|
+
* isSymbol(false); // false
|
|
21
|
+
* isSymbol(123n); // false
|
|
22
|
+
* isSymbol({}); // false
|
|
23
|
+
* isSymbol([1, 2, 3]); // false
|
|
24
|
+
*/
|
|
25
|
+
declare function isSymbol(value: unknown): value is symbol;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { isSymbol };
|
package/dist/isSymbol.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region isSymbol.ts
|
|
2
|
+
/**
|
|
3
|
+
* Check whether a value is a symbol.
|
|
4
|
+
*
|
|
5
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `symbol`.
|
|
6
|
+
*
|
|
7
|
+
* @param {unknown} value The value to check.
|
|
8
|
+
* @returns {value is symbol} Returns `true` if `value` is a symbol, else `false`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* import { isSymbol } from 'es-toolkit/predicate';
|
|
12
|
+
*
|
|
13
|
+
* isSymbol(Symbol('a')); // true
|
|
14
|
+
* isSymbol(Symbol.for('a')); // true
|
|
15
|
+
* isSymbol(Symbol.iterator); // true
|
|
16
|
+
*
|
|
17
|
+
* isSymbol(null); // false
|
|
18
|
+
* isSymbol(undefined); // false
|
|
19
|
+
* isSymbol('123'); // false
|
|
20
|
+
* isSymbol(false); // false
|
|
21
|
+
* isSymbol(123n); // false
|
|
22
|
+
* isSymbol({}); // false
|
|
23
|
+
* isSymbol([1, 2, 3]); // false
|
|
24
|
+
*/
|
|
25
|
+
function isSymbol(value) {
|
|
26
|
+
return typeof value === "symbol";
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { isSymbol };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region isUndefined.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Checks if the given value is undefined.
|
|
4
|
+
*
|
|
5
|
+
* This function tests whether the provided value is strictly equal to `undefined`.
|
|
6
|
+
* It returns `true` if the value is `undefined`, and `false` otherwise.
|
|
7
|
+
*
|
|
8
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `undefined`.
|
|
9
|
+
*
|
|
10
|
+
* @param {unknown} value - The value to test if it is undefined.
|
|
11
|
+
* @returns {value is undefined} True if the value is undefined, false otherwise.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const value1 = undefined;
|
|
15
|
+
* const value2 = null;
|
|
16
|
+
* const value3 = 42;
|
|
17
|
+
*
|
|
18
|
+
* console.log(isUndefined(value1)); // true
|
|
19
|
+
* console.log(isUndefined(value2)); // false
|
|
20
|
+
* console.log(isUndefined(value3)); // false
|
|
21
|
+
*/
|
|
22
|
+
declare const isUndefined: (value: unknown) => value is undefined;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { isUndefined };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region isUndefined.ts
|
|
2
|
+
/**
|
|
3
|
+
* Checks if the given value is undefined.
|
|
4
|
+
*
|
|
5
|
+
* This function tests whether the provided value is strictly equal to `undefined`.
|
|
6
|
+
* It returns `true` if the value is `undefined`, and `false` otherwise.
|
|
7
|
+
*
|
|
8
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `undefined`.
|
|
9
|
+
*
|
|
10
|
+
* @param {unknown} value - The value to test if it is undefined.
|
|
11
|
+
* @returns {value is undefined} True if the value is undefined, false otherwise.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const value1 = undefined;
|
|
15
|
+
* const value2 = null;
|
|
16
|
+
* const value3 = 42;
|
|
17
|
+
*
|
|
18
|
+
* console.log(isUndefined(value1)); // true
|
|
19
|
+
* console.log(isUndefined(value2)); // false
|
|
20
|
+
* console.log(isUndefined(value3)); // false
|
|
21
|
+
*/
|
|
22
|
+
const isUndefined = (value) => {
|
|
23
|
+
return value === void 0;
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
export { isUndefined };
|
package/dist/main.d.ts
CHANGED
|
@@ -1,155 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*
|
|
18
|
-
* console.log(isArray(value1)); // true
|
|
19
|
-
* console.log(isArray(value2)); // false
|
|
20
|
-
* console.log(isArray(value3)); // false
|
|
21
|
-
*/
|
|
22
|
-
declare function isArray<T = unknown>(value: unknown): value is T[];
|
|
23
|
-
//#endregion
|
|
24
|
-
//#region isBoolean.d.ts
|
|
25
|
-
/**
|
|
26
|
-
* Checks if the given value is boolean.
|
|
27
|
-
*
|
|
28
|
-
* This function tests whether the provided value is strictly `boolean`.
|
|
29
|
-
* It returns `true` if the value is `boolean`, and `false` otherwise.
|
|
30
|
-
*
|
|
31
|
-
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `boolean`.
|
|
32
|
-
*
|
|
33
|
-
* @param {unknown} x - The Value to test if it is boolean.
|
|
34
|
-
* @returns {x is boolean} True if the value is boolean, false otherwise.
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
*
|
|
38
|
-
* const value1 = true;
|
|
39
|
-
* const value2 = 0;
|
|
40
|
-
* const value3 = 'abc';
|
|
41
|
-
*
|
|
42
|
-
* console.log(isBoolean(value1)); // true
|
|
43
|
-
* console.log(isBoolean(value2)); // false
|
|
44
|
-
* console.log(isBoolean(value3)); // false
|
|
45
|
-
*
|
|
46
|
-
*/
|
|
47
|
-
declare function isBoolean(x: unknown): x is boolean;
|
|
48
|
-
//#endregion
|
|
49
|
-
//#region isFunction.d.ts
|
|
50
|
-
/**
|
|
51
|
-
* Checks if `value` is a function.
|
|
52
|
-
*
|
|
53
|
-
* @param {any} value The value to check.
|
|
54
|
-
* @returns {boolean} Returns `true` if `value` is a function, else `false`.
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* isFunction(Array.prototype.slice); // true
|
|
58
|
-
* isFunction(async function () {}); // true
|
|
59
|
-
* isFunction(function* () {}); // true
|
|
60
|
-
* isFunction(Proxy); // true
|
|
61
|
-
* isFunction(Int8Array); // true
|
|
62
|
-
*/
|
|
63
|
-
declare function isFunction(value: any): value is (...args: any[]) => any;
|
|
64
|
-
//#endregion
|
|
65
|
-
//#region isNil.d.ts
|
|
66
|
-
/**
|
|
67
|
-
* Checks if a given value is null or undefined.
|
|
68
|
-
*
|
|
69
|
-
* This function tests whether the provided value is either `null` or `undefined`.
|
|
70
|
-
* It returns `true` if the value is `null` or `undefined`, and `false` otherwise.
|
|
71
|
-
*
|
|
72
|
-
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `null` or `undefined`.
|
|
73
|
-
*
|
|
74
|
-
* @param {unknown} x - The value to test for null or undefined.
|
|
75
|
-
* @returns {boolean} `true` if the value is null or undefined, `false` otherwise.
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* const value1 = null;
|
|
79
|
-
* const value2 = undefined;
|
|
80
|
-
* const value3 = 42;
|
|
81
|
-
* const result1 = isNil(value1); // true
|
|
82
|
-
* const result2 = isNil(value2); // true
|
|
83
|
-
* const result3 = isNil(value3); // false
|
|
84
|
-
*/
|
|
85
|
-
declare function isNil(x: unknown): x is null | undefined;
|
|
86
|
-
//#endregion
|
|
87
|
-
//#region isNumber.d.ts
|
|
88
|
-
/**
|
|
89
|
-
* Checks if the given value is a number.
|
|
90
|
-
*
|
|
91
|
-
* This function tests whether the provided value is strictly a `number`.
|
|
92
|
-
* It returns `true` if the value is a `number`, and `false` otherwise.
|
|
93
|
-
*
|
|
94
|
-
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `number`.
|
|
95
|
-
*
|
|
96
|
-
* @param {unknown} x - The value to test if it is a number.
|
|
97
|
-
* @returns {x is number} True if the value is a number, false otherwise.
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
*
|
|
101
|
-
* const value1 = 123;
|
|
102
|
-
* const value2 = 'abc';
|
|
103
|
-
* const value3 = true;
|
|
104
|
-
*
|
|
105
|
-
* console.log(isNumber(value1)); // true
|
|
106
|
-
* console.log(isNumber(value2)); // false
|
|
107
|
-
* console.log(isNumber(value3)); // false
|
|
108
|
-
*
|
|
109
|
-
*/
|
|
110
|
-
declare function isNumber(value: unknown): value is number;
|
|
111
|
-
//#endregion
|
|
112
|
-
//#region isString.d.ts
|
|
113
|
-
/**
|
|
114
|
-
* Checks if a given value is string.
|
|
115
|
-
*
|
|
116
|
-
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `string`.
|
|
117
|
-
*
|
|
118
|
-
* @param {unknown} value The value to check if it is string.
|
|
119
|
-
* @returns {value is string} Returns `true` if `value` is a string, else `false`.
|
|
120
|
-
*
|
|
121
|
-
* @example
|
|
122
|
-
* const value1 = 'abc';
|
|
123
|
-
* const value2 = 123;
|
|
124
|
-
* const value3 = true;
|
|
125
|
-
*
|
|
126
|
-
* console.log(isString(value1)); // true
|
|
127
|
-
* console.log(isString(value2)); // false
|
|
128
|
-
* console.log(isString(value3)); // false
|
|
129
|
-
*/
|
|
130
|
-
declare function isString(value: unknown): value is string;
|
|
131
|
-
//#endregion
|
|
132
|
-
//#region isUndefined.d.ts
|
|
133
|
-
/**
|
|
134
|
-
* Checks if the given value is undefined.
|
|
135
|
-
*
|
|
136
|
-
* This function tests whether the provided value is strictly equal to `undefined`.
|
|
137
|
-
* It returns `true` if the value is `undefined`, and `false` otherwise.
|
|
138
|
-
*
|
|
139
|
-
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `undefined`.
|
|
140
|
-
*
|
|
141
|
-
* @param {unknown} value - The value to test if it is undefined.
|
|
142
|
-
* @returns {value is undefined} True if the value is undefined, false otherwise.
|
|
143
|
-
*
|
|
144
|
-
* @example
|
|
145
|
-
* const value1 = undefined;
|
|
146
|
-
* const value2 = null;
|
|
147
|
-
* const value3 = 42;
|
|
148
|
-
*
|
|
149
|
-
* console.log(isUndefined(value1)); // true
|
|
150
|
-
* console.log(isUndefined(value2)); // false
|
|
151
|
-
* console.log(isUndefined(value3)); // false
|
|
152
|
-
*/
|
|
153
|
-
declare const isUndefined: (value: unknown) => value is undefined;
|
|
154
|
-
//#endregion
|
|
155
|
-
export { isArray, isBoolean, isFunction, isNil, isNumber, isString, isUndefined };
|
|
1
|
+
import { ChainedFunction, createChainedFunction } from "./createChainedFunction.js";
|
|
2
|
+
import { get } from "./get.js";
|
|
3
|
+
import hasValue from "./hasValue.js";
|
|
4
|
+
import { isArray } from "./isArray.js";
|
|
5
|
+
import { isBoolean } from "./isBoolean.js";
|
|
6
|
+
import { isFunction } from "./isFunction.js";
|
|
7
|
+
import { isNil } from "./isNil.js";
|
|
8
|
+
import { isNull } from "./isNull.js";
|
|
9
|
+
import { isNumber } from "./isNumber.js";
|
|
10
|
+
import { isObject } from "./isObject.js";
|
|
11
|
+
import { isPromise } from "./isPromise.js";
|
|
12
|
+
import { isString } from "./isString.js";
|
|
13
|
+
import { isSymbol } from "./isSymbol.js";
|
|
14
|
+
import { isUndefined } from "./isUndefined.js";
|
|
15
|
+
import resolveValue from "./resolveValue.js";
|
|
16
|
+
export { type ChainedFunction, createChainedFunction, get, hasValue, isArray, isBoolean, isFunction, isNil, isNull, isNumber, isObject, isPromise, isString, isSymbol, isUndefined, resolveValue };
|