@omnific/utils 0.0.2 → 0.0.3

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/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 };
@@ -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 };
@@ -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 };
@@ -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 };
@@ -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 };
@@ -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,13 @@
1
- //#region isArray.d.ts
2
- /**
3
- * Checks if the given value is an array.
4
- *
5
- * This function tests whether the provided value is strictly an array.
6
- * It returns `true` if the value is an array, and `false` otherwise.
7
- *
8
- * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to an array.
9
- *
10
- * @param {unknown} value - The value to test if it is an array.
11
- * @returns {value is T[]} True if the value is an array, false otherwise.
12
- *
13
- * @example
14
- * const value1 = [];
15
- * const value2 = {};
16
- * const value3 = 'abc';
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 { get } from "./get.js";
2
+ import { isArray } from "./isArray.js";
3
+ import { isBoolean } from "./isBoolean.js";
4
+ import { isFunction } from "./isFunction.js";
5
+ import { isNil } from "./isNil.js";
6
+ import { isNull } from "./isNull.js";
7
+ import { isNumber } from "./isNumber.js";
8
+ import { isObject } from "./isObject.js";
9
+ import { isPromise } from "./isPromise.js";
10
+ import { isString } from "./isString.js";
11
+ import { isSymbol } from "./isSymbol.js";
12
+ import { isUndefined } from "./isUndefined.js";
13
+ export { get, isArray, isBoolean, isFunction, isNil, isNull, isNumber, isObject, isPromise, isString, isSymbol, isUndefined };