@jblib/is 0.0.6 → 0.0.7
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/index.d.ts +10 -1
- package/dist/index.js +10 -1
- package/dist/is-empty-array.d.ts +19 -0
- package/dist/is-empty-array.d.ts.map +1 -0
- package/dist/is-empty-array.js +20 -0
- package/dist/is-empty-array.js.map +1 -0
- package/dist/is-falsy.d.ts +30 -0
- package/dist/is-falsy.d.ts.map +1 -0
- package/dist/is-falsy.js +30 -0
- package/dist/is-falsy.js.map +1 -0
- package/dist/is-map.d.ts +20 -0
- package/dist/is-map.d.ts.map +1 -0
- package/dist/is-map.js +21 -0
- package/dist/is-map.js.map +1 -0
- package/dist/is-null.d.ts +20 -0
- package/dist/is-null.d.ts.map +1 -0
- package/dist/is-null.js +21 -0
- package/dist/is-null.js.map +1 -0
- package/dist/is-promise.d.ts +20 -0
- package/dist/is-promise.d.ts.map +1 -0
- package/dist/is-promise.js +21 -0
- package/dist/is-promise.js.map +1 -0
- package/dist/is-reg-exp.d.ts +23 -0
- package/dist/is-reg-exp.d.ts.map +1 -0
- package/dist/is-reg-exp.js +24 -0
- package/dist/is-reg-exp.js.map +1 -0
- package/dist/is-set.d.ts +20 -0
- package/dist/is-set.d.ts.map +1 -0
- package/dist/is-set.js +21 -0
- package/dist/is-set.js.map +1 -0
- package/dist/is-symbol.d.ts +20 -0
- package/dist/is-symbol.d.ts.map +1 -0
- package/dist/is-symbol.js +21 -0
- package/dist/is-symbol.js.map +1 -0
- package/dist/is-truthy.d.ts +31 -0
- package/dist/is-truthy.d.ts.map +1 -0
- package/dist/is-truthy.js +30 -0
- package/dist/is-truthy.js.map +1 -0
- package/dist/is-undefined.js +1 -1
- package/dist/is-undefined.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +9 -0
- package/src/is-empty-array.spec.ts +21 -0
- package/src/is-empty-array.ts +17 -0
- package/src/is-falsy.spec.ts +22 -0
- package/src/is-falsy.ts +31 -0
- package/src/is-map.spec.ts +17 -0
- package/src/is-map.ts +18 -0
- package/src/is-null.spec.ts +17 -0
- package/src/is-null.ts +18 -0
- package/src/is-promise.spec.ts +27 -0
- package/src/is-promise.ts +22 -0
- package/src/is-reg-exp.spec.ts +19 -0
- package/src/is-reg-exp.ts +21 -0
- package/src/is-set.spec.ts +17 -0
- package/src/is-set.ts +18 -0
- package/src/is-symbol.spec.ts +18 -0
- package/src/is-symbol.ts +18 -0
- package/src/is-truthy.spec.ts +22 -0
- package/src/is-truthy.ts +29 -0
- package/src/is-undefined.ts +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,17 +2,26 @@ import { isArray } from "./is-array.js";
|
|
|
2
2
|
import { isBoolean } from "./is-boolean.js";
|
|
3
3
|
import { isDate } from "./is-date.js";
|
|
4
4
|
import { isDefined } from "./is-defined.js";
|
|
5
|
+
import { isEmptyArray } from "./is-empty-array.js";
|
|
5
6
|
import { isEmptyObject } from "./is-empty-object.js";
|
|
6
7
|
import { isError } from "./is-error.js";
|
|
8
|
+
import { isFalsy } from "./is-falsy.js";
|
|
7
9
|
import { isFunction } from "./is-function.js";
|
|
10
|
+
import { isMap } from "./is-map.js";
|
|
8
11
|
import { isNegativeNumber } from "./is-negative-number.js";
|
|
9
12
|
import { isNil } from "./is-nil.js";
|
|
10
13
|
import { isNonEmptyArray } from "./is-non-empty-array.js";
|
|
14
|
+
import { isNull } from "./is-null.js";
|
|
11
15
|
import { isNumber } from "./is-number.js";
|
|
12
16
|
import { isObject } from "./is-object.js";
|
|
13
17
|
import { isPlainObject } from "./is-plain-object.js";
|
|
14
18
|
import { isPositiveNumber } from "./is-positive-number.js";
|
|
15
19
|
import { isPrimitive } from "./is-primitive.js";
|
|
20
|
+
import { isPromise } from "./is-promise.js";
|
|
21
|
+
import { isRegExp } from "./is-reg-exp.js";
|
|
22
|
+
import { isSet } from "./is-set.js";
|
|
16
23
|
import { isString } from "./is-string.js";
|
|
24
|
+
import { isSymbol } from "./is-symbol.js";
|
|
25
|
+
import { isTruthy } from "./is-truthy.js";
|
|
17
26
|
import { isUndefined } from "./is-undefined.js";
|
|
18
|
-
export { isArray, isBoolean, isDate, isDefined, isEmptyObject, isError, isFunction, isNegativeNumber, isNil, isNonEmptyArray, isNumber, isObject, isPlainObject, isPositiveNumber, isPrimitive, isString, isUndefined };
|
|
27
|
+
export { isArray, isBoolean, isDate, isDefined, isEmptyArray, isEmptyObject, isError, isFalsy, isFunction, isMap, isNegativeNumber, isNil, isNonEmptyArray, isNull, isNumber, isObject, isPlainObject, isPositiveNumber, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isTruthy, isUndefined };
|
package/dist/index.js
CHANGED
|
@@ -2,18 +2,27 @@ import { isArray } from "./is-array.js";
|
|
|
2
2
|
import { isBoolean } from "./is-boolean.js";
|
|
3
3
|
import { isDate } from "./is-date.js";
|
|
4
4
|
import { isDefined } from "./is-defined.js";
|
|
5
|
+
import { isEmptyArray } from "./is-empty-array.js";
|
|
5
6
|
import { isPlainObject } from "./is-plain-object.js";
|
|
6
7
|
import { isEmptyObject } from "./is-empty-object.js";
|
|
7
8
|
import { isError } from "./is-error.js";
|
|
9
|
+
import { isFalsy } from "./is-falsy.js";
|
|
8
10
|
import { isFunction } from "./is-function.js";
|
|
11
|
+
import { isMap } from "./is-map.js";
|
|
9
12
|
import { isNegativeNumber } from "./is-negative-number.js";
|
|
10
13
|
import { isNil } from "./is-nil.js";
|
|
11
14
|
import { isNonEmptyArray } from "./is-non-empty-array.js";
|
|
15
|
+
import { isNull } from "./is-null.js";
|
|
12
16
|
import { isNumber } from "./is-number.js";
|
|
13
17
|
import { isObject } from "./is-object.js";
|
|
14
18
|
import { isPositiveNumber } from "./is-positive-number.js";
|
|
15
19
|
import { isPrimitive } from "./is-primitive.js";
|
|
20
|
+
import { isPromise } from "./is-promise.js";
|
|
21
|
+
import { isRegExp } from "./is-reg-exp.js";
|
|
22
|
+
import { isSet } from "./is-set.js";
|
|
16
23
|
import { isString } from "./is-string.js";
|
|
24
|
+
import { isSymbol } from "./is-symbol.js";
|
|
25
|
+
import { isTruthy } from "./is-truthy.js";
|
|
17
26
|
import { isUndefined } from "./is-undefined.js";
|
|
18
27
|
|
|
19
|
-
export { isArray, isBoolean, isDate, isDefined, isEmptyObject, isError, isFunction, isNegativeNumber, isNil, isNonEmptyArray, isNumber, isObject, isPlainObject, isPositiveNumber, isPrimitive, isString, isUndefined };
|
|
28
|
+
export { isArray, isBoolean, isDate, isDefined, isEmptyArray, isEmptyObject, isError, isFalsy, isFunction, isMap, isNegativeNumber, isNil, isNonEmptyArray, isNull, isNumber, isObject, isPlainObject, isPositiveNumber, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isTruthy, isUndefined };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/is-empty-array.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* isEmptyArray checks if the value is an empty array.
|
|
4
|
+
*
|
|
5
|
+
* @param v value to check.
|
|
6
|
+
* @returns {v is unknown[]} returns true if v is an empty array or otherwise false.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* isEmptyArray([]) // true
|
|
11
|
+
* isEmptyArray([1, 2, 3]) // false
|
|
12
|
+
* isEmptyArray('hello') // false
|
|
13
|
+
* isEmptyArray({}) // false
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
declare const isEmptyArray: (v: unknown) => v is unknown[];
|
|
17
|
+
//#endregion
|
|
18
|
+
export { isEmptyArray };
|
|
19
|
+
//# sourceMappingURL=is-empty-array.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-empty-array.d.ts","names":[],"sources":["../src/is-empty-array.ts"],"mappings":";;;;;;;;;;;;;;;cAcM,YAAA,GAAgB,CAAA,cAAa,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/is-empty-array.ts
|
|
2
|
+
/**
|
|
3
|
+
* isEmptyArray checks if the value is an empty array.
|
|
4
|
+
*
|
|
5
|
+
* @param v value to check.
|
|
6
|
+
* @returns {v is unknown[]} returns true if v is an empty array or otherwise false.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* isEmptyArray([]) // true
|
|
11
|
+
* isEmptyArray([1, 2, 3]) // false
|
|
12
|
+
* isEmptyArray('hello') // false
|
|
13
|
+
* isEmptyArray({}) // false
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
const isEmptyArray = (v) => Array.isArray(v) && v.length === 0;
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { isEmptyArray };
|
|
20
|
+
//# sourceMappingURL=is-empty-array.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-empty-array.js","names":[],"sources":["../src/is-empty-array.ts"],"sourcesContent":["/**\n * isEmptyArray checks if the value is an empty array.\n *\n * @param v value to check.\n * @returns {v is unknown[]} returns true if v is an empty array or otherwise false.\n *\n * @example\n * ```ts\n * isEmptyArray([]) // true\n * isEmptyArray([1, 2, 3]) // false\n * isEmptyArray('hello') // false\n * isEmptyArray({}) // false\n * ```\n */\nconst isEmptyArray = (v: unknown): v is unknown[] => Array.isArray(v) && v.length === 0\n\nexport { isEmptyArray }\n"],"mappings":";;;;;;;;;;;;;;;AAcA,MAAM,gBAAgB,MAA+B,MAAM,QAAQ,EAAE,IAAI,EAAE,WAAW"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/is-falsy.d.ts
|
|
2
|
+
type Falsy = false | 0 | 0n | '' | null | undefined;
|
|
3
|
+
/**
|
|
4
|
+
* isFalsy checks if a value is falsy.
|
|
5
|
+
* A value is considered falsy if it is false, 0, 0n, '', null, or undefined.
|
|
6
|
+
* Useful for type narrowing in conditional statements.
|
|
7
|
+
* See isTruthy for the opposite of isFalsy.
|
|
8
|
+
*
|
|
9
|
+
* @param v value to check.
|
|
10
|
+
* @returns {v is Extract<T, Falsy>} returns true if v is falsy or otherwise false.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* isFalsy(false) // true
|
|
15
|
+
* isFalsy(0) // true
|
|
16
|
+
* isFalsy(0n) // true
|
|
17
|
+
* isFalsy('') // true
|
|
18
|
+
* isFalsy(null) // true
|
|
19
|
+
* isFalsy(undefined) // true
|
|
20
|
+
* isFalsy(true) // false
|
|
21
|
+
* isFalsy(1) // false
|
|
22
|
+
* isFalsy('hello') // false
|
|
23
|
+
* isFalsy([]) // false
|
|
24
|
+
* isFalsy({}) // false
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
declare const isFalsy: <T>(v: T) => v is Extract<T, Falsy>;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { type Falsy, isFalsy };
|
|
30
|
+
//# sourceMappingURL=is-falsy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-falsy.d.ts","names":[],"sources":["../src/is-falsy.ts"],"mappings":";KAAK,KAAA;;;;;;AAAK;;;;;;;;;;;;;;;;;;;cA0BJ,OAAA,MAAc,CAAA,EAAG,CAAA,KAAI,CAAA,IAAK,OAAA,CAAQ,CAAA,EAAG,KAAA"}
|
package/dist/is-falsy.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/is-falsy.ts
|
|
2
|
+
/**
|
|
3
|
+
* isFalsy checks if a value is falsy.
|
|
4
|
+
* A value is considered falsy if it is false, 0, 0n, '', null, or undefined.
|
|
5
|
+
* Useful for type narrowing in conditional statements.
|
|
6
|
+
* See isTruthy for the opposite of isFalsy.
|
|
7
|
+
*
|
|
8
|
+
* @param v value to check.
|
|
9
|
+
* @returns {v is Extract<T, Falsy>} returns true if v is falsy or otherwise false.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* isFalsy(false) // true
|
|
14
|
+
* isFalsy(0) // true
|
|
15
|
+
* isFalsy(0n) // true
|
|
16
|
+
* isFalsy('') // true
|
|
17
|
+
* isFalsy(null) // true
|
|
18
|
+
* isFalsy(undefined) // true
|
|
19
|
+
* isFalsy(true) // false
|
|
20
|
+
* isFalsy(1) // false
|
|
21
|
+
* isFalsy('hello') // false
|
|
22
|
+
* isFalsy([]) // false
|
|
23
|
+
* isFalsy({}) // false
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
const isFalsy = (v) => !v;
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { isFalsy };
|
|
30
|
+
//# sourceMappingURL=is-falsy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-falsy.js","names":[],"sources":["../src/is-falsy.ts"],"sourcesContent":["type Falsy = false | 0 | 0n | '' | null | undefined\n\n/**\n * isFalsy checks if a value is falsy.\n * A value is considered falsy if it is false, 0, 0n, '', null, or undefined.\n * Useful for type narrowing in conditional statements.\n * See isTruthy for the opposite of isFalsy.\n *\n * @param v value to check.\n * @returns {v is Extract<T, Falsy>} returns true if v is falsy or otherwise false.\n *\n * @example\n * ```ts\n * isFalsy(false) // true\n * isFalsy(0) // true\n * isFalsy(0n) // true\n * isFalsy('') // true\n * isFalsy(null) // true\n * isFalsy(undefined) // true\n * isFalsy(true) // false\n * isFalsy(1) // false\n * isFalsy('hello') // false\n * isFalsy([]) // false\n * isFalsy({}) // false\n * ```\n */\nconst isFalsy = <T>(v: T): v is Extract<T, Falsy> => !v\n\nexport type { Falsy }\n\nexport { isFalsy }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAM,WAAc,MAAiC,CAAC"}
|
package/dist/is-map.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/is-map.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* isMap checks if a value is a Map.
|
|
4
|
+
*
|
|
5
|
+
* @param v value to check.
|
|
6
|
+
* @returns {v is Map<unknown, unknown>} returns true if v is a Map or otherwise false.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* isMap(new Map()) // true
|
|
11
|
+
* isMap(new Set()) // false
|
|
12
|
+
* isMap([]) // false
|
|
13
|
+
* isMap({}) // false
|
|
14
|
+
* isMap('hello') // false
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare const isMap: (v: unknown) => v is Map<unknown, unknown>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { isMap };
|
|
20
|
+
//# sourceMappingURL=is-map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-map.d.ts","names":[],"sources":["../src/is-map.ts"],"mappings":";;;;;;;;;;;;;;;;cAeM,KAAA,GAAS,CAAA,cAAa,CAAA,IAAK,GAAA"}
|
package/dist/is-map.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/is-map.ts
|
|
2
|
+
/**
|
|
3
|
+
* isMap checks if a value is a Map.
|
|
4
|
+
*
|
|
5
|
+
* @param v value to check.
|
|
6
|
+
* @returns {v is Map<unknown, unknown>} returns true if v is a Map or otherwise false.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* isMap(new Map()) // true
|
|
11
|
+
* isMap(new Set()) // false
|
|
12
|
+
* isMap([]) // false
|
|
13
|
+
* isMap({}) // false
|
|
14
|
+
* isMap('hello') // false
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
const isMap = (v) => v instanceof Map;
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { isMap };
|
|
21
|
+
//# sourceMappingURL=is-map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-map.js","names":[],"sources":["../src/is-map.ts"],"sourcesContent":["/**\n * isMap checks if a value is a Map.\n *\n * @param v value to check.\n * @returns {v is Map<unknown, unknown>} returns true if v is a Map or otherwise false.\n *\n * @example\n * ```ts\n * isMap(new Map()) // true\n * isMap(new Set()) // false\n * isMap([]) // false\n * isMap({}) // false\n * isMap('hello') // false\n * ```\n */\nconst isMap = (v: unknown): v is Map<unknown, unknown> => v instanceof Map\n\nexport { isMap }\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,MAAM,SAAS,MAA2C,aAAa"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/is-null.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* isNull checks if a value is null.
|
|
4
|
+
*
|
|
5
|
+
* @param v value to check.
|
|
6
|
+
* @returns {v is null} returns true if v is null or otherwise false.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* isNull(null) // true
|
|
11
|
+
* isNull('hello') // false
|
|
12
|
+
* isNull(123) // false
|
|
13
|
+
* isNull({}) // false
|
|
14
|
+
* isNull([]) // false
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare const isNull: (v: unknown) => v is null;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { isNull };
|
|
20
|
+
//# sourceMappingURL=is-null.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-null.d.ts","names":[],"sources":["../src/is-null.ts"],"mappings":";;;;;;;;;;;;;;;;cAeM,MAAA,GAAU,CAAA,cAAa,CAAA"}
|
package/dist/is-null.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/is-null.ts
|
|
2
|
+
/**
|
|
3
|
+
* isNull checks if a value is null.
|
|
4
|
+
*
|
|
5
|
+
* @param v value to check.
|
|
6
|
+
* @returns {v is null} returns true if v is null or otherwise false.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* isNull(null) // true
|
|
11
|
+
* isNull('hello') // false
|
|
12
|
+
* isNull(123) // false
|
|
13
|
+
* isNull({}) // false
|
|
14
|
+
* isNull([]) // false
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
const isNull = (v) => v === null;
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { isNull };
|
|
21
|
+
//# sourceMappingURL=is-null.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-null.js","names":[],"sources":["../src/is-null.ts"],"sourcesContent":["/**\n * isNull checks if a value is null.\n *\n * @param v value to check.\n * @returns {v is null} returns true if v is null or otherwise false.\n *\n * @example\n * ```ts\n * isNull(null) // true\n * isNull('hello') // false\n * isNull(123) // false\n * isNull({}) // false\n * isNull([]) // false\n * ```\n */\nconst isNull = (v: unknown): v is null => v === null\n\nexport { isNull }\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,MAAM,UAAU,MAA0B,MAAM"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/is-promise.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* isPromise checks if a value is a Promise.
|
|
4
|
+
*
|
|
5
|
+
* @param v value to check.
|
|
6
|
+
* @returns {v is Promise<unknown>} returns true if v is a Promise or otherwise false.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* isPromise(Promise.resolve()) // true
|
|
11
|
+
* isPromise(new Set()) // false
|
|
12
|
+
* isPromise([]) // false
|
|
13
|
+
* isPromise({}) // false
|
|
14
|
+
* isPromise('hello') // false
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare const isPromise: (v: unknown) => v is Promise<unknown>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { isPromise };
|
|
20
|
+
//# sourceMappingURL=is-promise.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-promise.d.ts","names":[],"sources":["../src/is-promise.ts"],"mappings":";;;;;;;;;;;;;;;;cAeM,SAAA,GAAa,CAAA,cAAa,CAAA,IAAK,OAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/is-promise.ts
|
|
2
|
+
/**
|
|
3
|
+
* isPromise checks if a value is a Promise.
|
|
4
|
+
*
|
|
5
|
+
* @param v value to check.
|
|
6
|
+
* @returns {v is Promise<unknown>} returns true if v is a Promise or otherwise false.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* isPromise(Promise.resolve()) // true
|
|
11
|
+
* isPromise(new Set()) // false
|
|
12
|
+
* isPromise([]) // false
|
|
13
|
+
* isPromise({}) // false
|
|
14
|
+
* isPromise('hello') // false
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
const isPromise = (v) => typeof v === "object" && v !== null && typeof v.then === "function" && typeof v.catch === "function";
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { isPromise };
|
|
21
|
+
//# sourceMappingURL=is-promise.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-promise.js","names":[],"sources":["../src/is-promise.ts"],"sourcesContent":["/**\n * isPromise checks if a value is a Promise.\n *\n * @param v value to check.\n * @returns {v is Promise<unknown>} returns true if v is a Promise or otherwise false.\n *\n * @example\n * ```ts\n * isPromise(Promise.resolve()) // true\n * isPromise(new Set()) // false\n * isPromise([]) // false\n * isPromise({}) // false\n * isPromise('hello') // false\n * ```\n */\nconst isPromise = (v: unknown): v is Promise<unknown> =>\n typeof v === 'object' &&\n v !== null &&\n typeof (v as Promise<unknown>).then === 'function' &&\n typeof (v as Promise<unknown>).catch === 'function'\n\nexport { isPromise }\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,MAAM,aAAa,MACjB,OAAO,MAAM,YACb,MAAM,QACN,OAAQ,EAAuB,SAAS,cACxC,OAAQ,EAAuB,UAAU"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/is-reg-exp.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* isRegExp checks if a value is a regular expression.
|
|
4
|
+
*
|
|
5
|
+
* @param v value to check.
|
|
6
|
+
* @returns {v is RegExp} returns true if v is a RegExp or otherwise false.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* isRegExp(/abc/) // true
|
|
11
|
+
* isRegExp(new RegExp('abc')) // true
|
|
12
|
+
* isRegExp('abc') // false
|
|
13
|
+
* isRegExp(123) // false
|
|
14
|
+
* isRegExp({}) // false
|
|
15
|
+
* isRegExp([]) // false
|
|
16
|
+
* isRegExp(null) // false
|
|
17
|
+
* isRegExp(undefined) // false
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
declare const isRegExp: (v: unknown) => v is RegExp;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { isRegExp };
|
|
23
|
+
//# sourceMappingURL=is-reg-exp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-reg-exp.d.ts","names":[],"sources":["../src/is-reg-exp.ts"],"mappings":";;;;;;;;;;;;;;;;;;;cAkBM,QAAA,GAAY,CAAA,cAAa,CAAA,IAAK,MAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/is-reg-exp.ts
|
|
2
|
+
/**
|
|
3
|
+
* isRegExp checks if a value is a regular expression.
|
|
4
|
+
*
|
|
5
|
+
* @param v value to check.
|
|
6
|
+
* @returns {v is RegExp} returns true if v is a RegExp or otherwise false.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* isRegExp(/abc/) // true
|
|
11
|
+
* isRegExp(new RegExp('abc')) // true
|
|
12
|
+
* isRegExp('abc') // false
|
|
13
|
+
* isRegExp(123) // false
|
|
14
|
+
* isRegExp({}) // false
|
|
15
|
+
* isRegExp([]) // false
|
|
16
|
+
* isRegExp(null) // false
|
|
17
|
+
* isRegExp(undefined) // false
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
const isRegExp = (v) => v instanceof RegExp;
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { isRegExp };
|
|
24
|
+
//# sourceMappingURL=is-reg-exp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-reg-exp.js","names":[],"sources":["../src/is-reg-exp.ts"],"sourcesContent":["/**\n * isRegExp checks if a value is a regular expression.\n *\n * @param v value to check.\n * @returns {v is RegExp} returns true if v is a RegExp or otherwise false.\n *\n * @example\n * ```ts\n * isRegExp(/abc/) // true\n * isRegExp(new RegExp('abc')) // true\n * isRegExp('abc') // false\n * isRegExp(123) // false\n * isRegExp({}) // false\n * isRegExp([]) // false\n * isRegExp(null) // false\n * isRegExp(undefined) // false\n * ```\n */\nconst isRegExp = (v: unknown): v is RegExp => v instanceof RegExp\n\nexport { isRegExp }\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,MAAM,YAAY,MAA4B,aAAa"}
|
package/dist/is-set.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/is-set.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* isSet checks if a value is a Set.
|
|
4
|
+
*
|
|
5
|
+
* @param v value to check.
|
|
6
|
+
* @returns {v is Set<unknown>} returns true if v is a Set or otherwise false.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* isSet(new Set()) // true
|
|
11
|
+
* isSet(new Map()) // false
|
|
12
|
+
* isSet([]) // false
|
|
13
|
+
* isSet({}) // false
|
|
14
|
+
* isSet('hello') // false
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare const isSet: (v: unknown) => v is Set<unknown>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { isSet };
|
|
20
|
+
//# sourceMappingURL=is-set.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-set.d.ts","names":[],"sources":["../src/is-set.ts"],"mappings":";;;;;;;;;;;;;;;;cAeM,KAAA,GAAS,CAAA,cAAa,CAAA,IAAK,GAAA"}
|
package/dist/is-set.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/is-set.ts
|
|
2
|
+
/**
|
|
3
|
+
* isSet checks if a value is a Set.
|
|
4
|
+
*
|
|
5
|
+
* @param v value to check.
|
|
6
|
+
* @returns {v is Set<unknown>} returns true if v is a Set or otherwise false.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* isSet(new Set()) // true
|
|
11
|
+
* isSet(new Map()) // false
|
|
12
|
+
* isSet([]) // false
|
|
13
|
+
* isSet({}) // false
|
|
14
|
+
* isSet('hello') // false
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
const isSet = (v) => v instanceof Set;
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { isSet };
|
|
21
|
+
//# sourceMappingURL=is-set.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-set.js","names":[],"sources":["../src/is-set.ts"],"sourcesContent":["/**\n * isSet checks if a value is a Set.\n *\n * @param v value to check.\n * @returns {v is Set<unknown>} returns true if v is a Set or otherwise false.\n *\n * @example\n * ```ts\n * isSet(new Set()) // true\n * isSet(new Map()) // false\n * isSet([]) // false\n * isSet({}) // false\n * isSet('hello') // false\n * ```\n */\nconst isSet = (v: unknown): v is Set<unknown> => v instanceof Set\n\nexport { isSet }\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,MAAM,SAAS,MAAkC,aAAa"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/is-symbol.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* isSymbol checks if a value is a symbol.
|
|
4
|
+
*
|
|
5
|
+
* @param v value to check.
|
|
6
|
+
* @returns {v is symbol} returns true if v is a symbol or otherwise false.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* isSymbol(Symbol('foo')) // true
|
|
11
|
+
* isSymbol('hello') // false
|
|
12
|
+
* isSymbol(123) // false
|
|
13
|
+
* isSymbol({}) // false
|
|
14
|
+
* isSymbol([]) // false
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare const isSymbol: (v: unknown) => v is symbol;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { isSymbol };
|
|
20
|
+
//# sourceMappingURL=is-symbol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-symbol.d.ts","names":[],"sources":["../src/is-symbol.ts"],"mappings":";;;;;;;;;;;;;;;;cAeM,QAAA,GAAY,CAAA,cAAa,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/is-symbol.ts
|
|
2
|
+
/**
|
|
3
|
+
* isSymbol checks if a value is a symbol.
|
|
4
|
+
*
|
|
5
|
+
* @param v value to check.
|
|
6
|
+
* @returns {v is symbol} returns true if v is a symbol or otherwise false.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* isSymbol(Symbol('foo')) // true
|
|
11
|
+
* isSymbol('hello') // false
|
|
12
|
+
* isSymbol(123) // false
|
|
13
|
+
* isSymbol({}) // false
|
|
14
|
+
* isSymbol([]) // false
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
const isSymbol = (v) => typeof v === "symbol";
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { isSymbol };
|
|
21
|
+
//# sourceMappingURL=is-symbol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-symbol.js","names":[],"sources":["../src/is-symbol.ts"],"sourcesContent":["/**\n * isSymbol checks if a value is a symbol.\n *\n * @param v value to check.\n * @returns {v is symbol} returns true if v is a symbol or otherwise false.\n *\n * @example\n * ```ts\n * isSymbol(Symbol('foo')) // true\n * isSymbol('hello') // false\n * isSymbol(123) // false\n * isSymbol({}) // false\n * isSymbol([]) // false\n * ```\n */\nconst isSymbol = (v: unknown): v is symbol => typeof v === 'symbol'\n\nexport { isSymbol }\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,MAAM,YAAY,MAA4B,OAAO,MAAM"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Falsy } from "./is-falsy.js";
|
|
2
|
+
|
|
3
|
+
//#region src/is-truthy.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* isTruthy checks if a value is truthy. A value is considered truthy if it is not falsy.
|
|
6
|
+
* Falsy values are false, 0, 0n, '', null, and undefined.
|
|
7
|
+
* Useful for type narrowing in conditional statements.
|
|
8
|
+
* See isFalsy for the opposite of isTruthy.
|
|
9
|
+
*
|
|
10
|
+
* @param v value to check.
|
|
11
|
+
* @returns {v is Exclude<T, Falsy>} returns true if v is truthy or otherwise false.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* isTruthy(true) // true
|
|
16
|
+
* isTruthy(1) // true
|
|
17
|
+
* isTruthy('hello') // true
|
|
18
|
+
* isTruthy([]) // true
|
|
19
|
+
* isTruthy({}) // true
|
|
20
|
+
* isTruthy(false) // false
|
|
21
|
+
* isTruthy(0) // false
|
|
22
|
+
* isTruthy(0n) // false
|
|
23
|
+
* isTruthy('') // false
|
|
24
|
+
* isTruthy(null) // false
|
|
25
|
+
* isTruthy(undefined) // false
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
declare const isTruthy: <T>(v: T) => v is Exclude<T, Falsy>;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { isTruthy };
|
|
31
|
+
//# sourceMappingURL=is-truthy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-truthy.d.ts","names":[],"sources":["../src/is-truthy.ts"],"mappings":";;;;;AAA0C;;;;;;;;;;;;;;;;;;;;;;cA0BpC,QAAA,MAAe,CAAA,EAAG,CAAA,KAAI,CAAA,IAAK,OAAA,CAAQ,CAAA,EAAG,KAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/is-truthy.ts
|
|
2
|
+
/**
|
|
3
|
+
* isTruthy checks if a value is truthy. A value is considered truthy if it is not falsy.
|
|
4
|
+
* Falsy values are false, 0, 0n, '', null, and undefined.
|
|
5
|
+
* Useful for type narrowing in conditional statements.
|
|
6
|
+
* See isFalsy for the opposite of isTruthy.
|
|
7
|
+
*
|
|
8
|
+
* @param v value to check.
|
|
9
|
+
* @returns {v is Exclude<T, Falsy>} returns true if v is truthy or otherwise false.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* isTruthy(true) // true
|
|
14
|
+
* isTruthy(1) // true
|
|
15
|
+
* isTruthy('hello') // true
|
|
16
|
+
* isTruthy([]) // true
|
|
17
|
+
* isTruthy({}) // true
|
|
18
|
+
* isTruthy(false) // false
|
|
19
|
+
* isTruthy(0) // false
|
|
20
|
+
* isTruthy(0n) // false
|
|
21
|
+
* isTruthy('') // false
|
|
22
|
+
* isTruthy(null) // false
|
|
23
|
+
* isTruthy(undefined) // false
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
const isTruthy = (v) => !!v;
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { isTruthy };
|
|
30
|
+
//# sourceMappingURL=is-truthy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-truthy.js","names":[],"sources":["../src/is-truthy.ts"],"sourcesContent":["import { type Falsy } from './is-falsy.js'\n\n/**\n * isTruthy checks if a value is truthy. A value is considered truthy if it is not falsy.\n * Falsy values are false, 0, 0n, '', null, and undefined.\n * Useful for type narrowing in conditional statements.\n * See isFalsy for the opposite of isTruthy.\n *\n * @param v value to check.\n * @returns {v is Exclude<T, Falsy>} returns true if v is truthy or otherwise false.\n *\n * @example\n * ```ts\n * isTruthy(true) // true\n * isTruthy(1) // true\n * isTruthy('hello') // true\n * isTruthy([]) // true\n * isTruthy({}) // true\n * isTruthy(false) // false\n * isTruthy(0) // false\n * isTruthy(0n) // false\n * isTruthy('') // false\n * isTruthy(null) // false\n * isTruthy(undefined) // false\n * ```\n */\nconst isTruthy = <T>(v: T): v is Exclude<T, Falsy> => !!v\n\nexport { isTruthy }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAM,YAAe,MAAiC,CAAC,CAAC"}
|
package/dist/is-undefined.js
CHANGED
package/dist/is-undefined.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-undefined.js","names":[],"sources":["../src/is-undefined.ts"],"sourcesContent":["/**\n * isUndefined checks if a value is undefined.\n *\n * @param v value to check.\n * @returns {v is undefined} returns true if v is undefined or otherwise false.\n *\n * @example\n * ```ts\n * isUndefined(undefined) // true\n * isUndefined('hello') // false\n * isUndefined(123) // false\n * isUndefined({}) // false\n * isUndefined([]) // false\n * ```\n */\nconst isUndefined = (v: unknown): v is undefined =>
|
|
1
|
+
{"version":3,"file":"is-undefined.js","names":[],"sources":["../src/is-undefined.ts"],"sourcesContent":["/**\n * isUndefined checks if a value is undefined.\n *\n * @param v value to check.\n * @returns {v is undefined} returns true if v is undefined or otherwise false.\n *\n * @example\n * ```ts\n * isUndefined(undefined) // true\n * isUndefined('hello') // false\n * isUndefined(123) // false\n * isUndefined({}) // false\n * isUndefined([]) // false\n * ```\n */\nconst isUndefined = (v: unknown): v is undefined => v === undefined\n\nexport { isUndefined }\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,MAAM,eAAe,MAA+B,MAAM"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -2,16 +2,25 @@ export { isArray } from './is-array.js'
|
|
|
2
2
|
export { isBoolean } from './is-boolean.js'
|
|
3
3
|
export { isDate } from './is-date.js'
|
|
4
4
|
export { isDefined } from './is-defined.js'
|
|
5
|
+
export { isEmptyArray } from './is-empty-array.js'
|
|
5
6
|
export { isEmptyObject } from './is-empty-object.js'
|
|
6
7
|
export { isError } from './is-error.js'
|
|
8
|
+
export { isFalsy } from './is-falsy.js'
|
|
7
9
|
export { isFunction } from './is-function.js'
|
|
10
|
+
export { isMap } from './is-map.js'
|
|
8
11
|
export { isNegativeNumber } from './is-negative-number.js'
|
|
9
12
|
export { isNil } from './is-nil.js'
|
|
10
13
|
export { isNonEmptyArray } from './is-non-empty-array.js'
|
|
14
|
+
export { isNull } from './is-null.js'
|
|
11
15
|
export { isNumber } from './is-number.js'
|
|
12
16
|
export { isObject } from './is-object.js'
|
|
13
17
|
export { isPlainObject } from './is-plain-object.js'
|
|
14
18
|
export { isPositiveNumber } from './is-positive-number.js'
|
|
15
19
|
export { isPrimitive } from './is-primitive.js'
|
|
20
|
+
export { isPromise } from './is-promise.js'
|
|
21
|
+
export { isRegExp } from './is-reg-exp.js'
|
|
22
|
+
export { isSet } from './is-set.js'
|
|
16
23
|
export { isString } from './is-string.js'
|
|
24
|
+
export { isSymbol } from './is-symbol.js'
|
|
25
|
+
export { isTruthy } from './is-truthy.js'
|
|
17
26
|
export { isUndefined } from './is-undefined.js'
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { isEmptyArray } from './is-empty-array.js'
|
|
4
|
+
|
|
5
|
+
describe('is empty array', () => {
|
|
6
|
+
it('should return true for empty arrays', () => {
|
|
7
|
+
expect(isEmptyArray([])).toBe(true)
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
it('should return false for non-empty arrays', () => {
|
|
11
|
+
expect(isEmptyArray([1, 2, 3])).toBe(false)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('should return false for non-arrays', () => {
|
|
15
|
+
expect(isEmptyArray('hello')).toBe(false)
|
|
16
|
+
expect(isEmptyArray({})).toBe(false)
|
|
17
|
+
expect(isEmptyArray(123)).toBe(false)
|
|
18
|
+
expect(isEmptyArray(null)).toBe(false)
|
|
19
|
+
expect(isEmptyArray(undefined)).toBe(false)
|
|
20
|
+
})
|
|
21
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* isEmptyArray checks if the value is an empty array.
|
|
3
|
+
*
|
|
4
|
+
* @param v value to check.
|
|
5
|
+
* @returns {v is unknown[]} returns true if v is an empty array or otherwise false.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* isEmptyArray([]) // true
|
|
10
|
+
* isEmptyArray([1, 2, 3]) // false
|
|
11
|
+
* isEmptyArray('hello') // false
|
|
12
|
+
* isEmptyArray({}) // false
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
const isEmptyArray = (v: unknown): v is unknown[] => Array.isArray(v) && v.length === 0
|
|
16
|
+
|
|
17
|
+
export { isEmptyArray }
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { isFalsy } from './is-falsy.js'
|
|
4
|
+
|
|
5
|
+
describe('is falsy', () => {
|
|
6
|
+
it('should return true for falsy values', () => {
|
|
7
|
+
expect(isFalsy(false)).toBe(true)
|
|
8
|
+
expect(isFalsy(0)).toBe(true)
|
|
9
|
+
expect(isFalsy(0n)).toBe(true)
|
|
10
|
+
expect(isFalsy('')).toBe(true)
|
|
11
|
+
expect(isFalsy(null)).toBe(true)
|
|
12
|
+
expect(isFalsy(undefined)).toBe(true)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('should return false for non-falsy values', () => {
|
|
16
|
+
expect(isFalsy(true)).toBe(false)
|
|
17
|
+
expect(isFalsy(1)).toBe(false)
|
|
18
|
+
expect(isFalsy('hello')).toBe(false)
|
|
19
|
+
expect(isFalsy([])).toBe(false)
|
|
20
|
+
expect(isFalsy({})).toBe(false)
|
|
21
|
+
})
|
|
22
|
+
})
|
package/src/is-falsy.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
type Falsy = false | 0 | 0n | '' | null | undefined
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* isFalsy checks if a value is falsy.
|
|
5
|
+
* A value is considered falsy if it is false, 0, 0n, '', null, or undefined.
|
|
6
|
+
* Useful for type narrowing in conditional statements.
|
|
7
|
+
* See isTruthy for the opposite of isFalsy.
|
|
8
|
+
*
|
|
9
|
+
* @param v value to check.
|
|
10
|
+
* @returns {v is Extract<T, Falsy>} returns true if v is falsy or otherwise false.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* isFalsy(false) // true
|
|
15
|
+
* isFalsy(0) // true
|
|
16
|
+
* isFalsy(0n) // true
|
|
17
|
+
* isFalsy('') // true
|
|
18
|
+
* isFalsy(null) // true
|
|
19
|
+
* isFalsy(undefined) // true
|
|
20
|
+
* isFalsy(true) // false
|
|
21
|
+
* isFalsy(1) // false
|
|
22
|
+
* isFalsy('hello') // false
|
|
23
|
+
* isFalsy([]) // false
|
|
24
|
+
* isFalsy({}) // false
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
const isFalsy = <T>(v: T): v is Extract<T, Falsy> => !v
|
|
28
|
+
|
|
29
|
+
export type { Falsy }
|
|
30
|
+
|
|
31
|
+
export { isFalsy }
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { isMap } from './is-map.js'
|
|
4
|
+
|
|
5
|
+
describe('is map', () => {
|
|
6
|
+
it('should return true for maps', () => {
|
|
7
|
+
expect(isMap(new Map())).toBe(true)
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
it('should return false for non-maps', () => {
|
|
11
|
+
expect(isMap(123)).toBe(false)
|
|
12
|
+
expect(isMap({})).toBe(false)
|
|
13
|
+
expect(isMap([])).toBe(false)
|
|
14
|
+
expect(isMap(null)).toBe(false)
|
|
15
|
+
expect(isMap(undefined)).toBe(false)
|
|
16
|
+
})
|
|
17
|
+
})
|
package/src/is-map.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* isMap checks if a value is a Map.
|
|
3
|
+
*
|
|
4
|
+
* @param v value to check.
|
|
5
|
+
* @returns {v is Map<unknown, unknown>} returns true if v is a Map or otherwise false.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* isMap(new Map()) // true
|
|
10
|
+
* isMap(new Set()) // false
|
|
11
|
+
* isMap([]) // false
|
|
12
|
+
* isMap({}) // false
|
|
13
|
+
* isMap('hello') // false
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
const isMap = (v: unknown): v is Map<unknown, unknown> => v instanceof Map
|
|
17
|
+
|
|
18
|
+
export { isMap }
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { isNull } from './is-null.js'
|
|
4
|
+
|
|
5
|
+
describe('is null', () => {
|
|
6
|
+
it('should return true for null values', () => {
|
|
7
|
+
expect(isNull(null)).toBe(true)
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
it('should return false for non-null values', () => {
|
|
11
|
+
expect(isNull([])).toBe(false)
|
|
12
|
+
expect(isNull('hello')).toBe(false)
|
|
13
|
+
expect(isNull({})).toBe(false)
|
|
14
|
+
expect(isNull(123)).toBe(false)
|
|
15
|
+
expect(isNull(undefined)).toBe(false)
|
|
16
|
+
})
|
|
17
|
+
})
|
package/src/is-null.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* isNull checks if a value is null.
|
|
3
|
+
*
|
|
4
|
+
* @param v value to check.
|
|
5
|
+
* @returns {v is null} returns true if v is null or otherwise false.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* isNull(null) // true
|
|
10
|
+
* isNull('hello') // false
|
|
11
|
+
* isNull(123) // false
|
|
12
|
+
* isNull({}) // false
|
|
13
|
+
* isNull([]) // false
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
const isNull = (v: unknown): v is null => v === null
|
|
17
|
+
|
|
18
|
+
export { isNull }
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { isPromise } from './is-promise.js'
|
|
4
|
+
|
|
5
|
+
describe('is promise', () => {
|
|
6
|
+
it('should return true for promises', () => {
|
|
7
|
+
expect(
|
|
8
|
+
isPromise({
|
|
9
|
+
then: () => {
|
|
10
|
+
void 0
|
|
11
|
+
},
|
|
12
|
+
catch: () => {
|
|
13
|
+
void 0
|
|
14
|
+
},
|
|
15
|
+
}),
|
|
16
|
+
).toBe(true)
|
|
17
|
+
expect(isPromise(Promise.resolve())).toBe(true)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('should return false for non-promises', () => {
|
|
21
|
+
expect(isPromise(123)).toBe(false)
|
|
22
|
+
expect(isPromise({})).toBe(false)
|
|
23
|
+
expect(isPromise([])).toBe(false)
|
|
24
|
+
expect(isPromise(null)).toBe(false)
|
|
25
|
+
expect(isPromise(undefined)).toBe(false)
|
|
26
|
+
})
|
|
27
|
+
})
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* isPromise checks if a value is a Promise.
|
|
3
|
+
*
|
|
4
|
+
* @param v value to check.
|
|
5
|
+
* @returns {v is Promise<unknown>} returns true if v is a Promise or otherwise false.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* isPromise(Promise.resolve()) // true
|
|
10
|
+
* isPromise(new Set()) // false
|
|
11
|
+
* isPromise([]) // false
|
|
12
|
+
* isPromise({}) // false
|
|
13
|
+
* isPromise('hello') // false
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
const isPromise = (v: unknown): v is Promise<unknown> =>
|
|
17
|
+
typeof v === 'object' &&
|
|
18
|
+
v !== null &&
|
|
19
|
+
typeof (v as Promise<unknown>).then === 'function' &&
|
|
20
|
+
typeof (v as Promise<unknown>).catch === 'function'
|
|
21
|
+
|
|
22
|
+
export { isPromise }
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { isRegExp } from './is-reg-exp.js'
|
|
4
|
+
|
|
5
|
+
describe('is reg exp', () => {
|
|
6
|
+
it('should return true for regexp values', () => {
|
|
7
|
+
expect(isRegExp(/abc/)).toBe(true)
|
|
8
|
+
expect(isRegExp(new RegExp('abc'))).toBe(true)
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
it('should return false for non-regexp values', () => {
|
|
12
|
+
expect(isRegExp('abc')).toBe(false)
|
|
13
|
+
expect(isRegExp(123)).toBe(false)
|
|
14
|
+
expect(isRegExp({})).toBe(false)
|
|
15
|
+
expect(isRegExp([])).toBe(false)
|
|
16
|
+
expect(isRegExp(null)).toBe(false)
|
|
17
|
+
expect(isRegExp(undefined)).toBe(false)
|
|
18
|
+
})
|
|
19
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* isRegExp checks if a value is a regular expression.
|
|
3
|
+
*
|
|
4
|
+
* @param v value to check.
|
|
5
|
+
* @returns {v is RegExp} returns true if v is a RegExp or otherwise false.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* isRegExp(/abc/) // true
|
|
10
|
+
* isRegExp(new RegExp('abc')) // true
|
|
11
|
+
* isRegExp('abc') // false
|
|
12
|
+
* isRegExp(123) // false
|
|
13
|
+
* isRegExp({}) // false
|
|
14
|
+
* isRegExp([]) // false
|
|
15
|
+
* isRegExp(null) // false
|
|
16
|
+
* isRegExp(undefined) // false
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
const isRegExp = (v: unknown): v is RegExp => v instanceof RegExp
|
|
20
|
+
|
|
21
|
+
export { isRegExp }
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { isSet } from './is-set.js'
|
|
4
|
+
|
|
5
|
+
describe('is set', () => {
|
|
6
|
+
it('should return true for sets', () => {
|
|
7
|
+
expect(isSet(new Set())).toBe(true)
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
it('should return false for non-sets', () => {
|
|
11
|
+
expect(isSet(123)).toBe(false)
|
|
12
|
+
expect(isSet({})).toBe(false)
|
|
13
|
+
expect(isSet([])).toBe(false)
|
|
14
|
+
expect(isSet(null)).toBe(false)
|
|
15
|
+
expect(isSet(undefined)).toBe(false)
|
|
16
|
+
})
|
|
17
|
+
})
|
package/src/is-set.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* isSet checks if a value is a Set.
|
|
3
|
+
*
|
|
4
|
+
* @param v value to check.
|
|
5
|
+
* @returns {v is Set<unknown>} returns true if v is a Set or otherwise false.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* isSet(new Set()) // true
|
|
10
|
+
* isSet(new Map()) // false
|
|
11
|
+
* isSet([]) // false
|
|
12
|
+
* isSet({}) // false
|
|
13
|
+
* isSet('hello') // false
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
const isSet = (v: unknown): v is Set<unknown> => v instanceof Set
|
|
17
|
+
|
|
18
|
+
export { isSet }
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { isSymbol } from './is-symbol.js'
|
|
4
|
+
|
|
5
|
+
describe('is symbol', () => {
|
|
6
|
+
it('should return true for symbols', () => {
|
|
7
|
+
expect(isSymbol(Symbol('foo'))).toBe(true)
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
it('should return false for non-symbols', () => {
|
|
11
|
+
expect(isSymbol(123)).toBe(false)
|
|
12
|
+
expect(isSymbol('hello')).toBe(false)
|
|
13
|
+
expect(isSymbol({})).toBe(false)
|
|
14
|
+
expect(isSymbol([])).toBe(false)
|
|
15
|
+
expect(isSymbol(null)).toBe(false)
|
|
16
|
+
expect(isSymbol(undefined)).toBe(false)
|
|
17
|
+
})
|
|
18
|
+
})
|
package/src/is-symbol.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* isSymbol checks if a value is a symbol.
|
|
3
|
+
*
|
|
4
|
+
* @param v value to check.
|
|
5
|
+
* @returns {v is symbol} returns true if v is a symbol or otherwise false.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* isSymbol(Symbol('foo')) // true
|
|
10
|
+
* isSymbol('hello') // false
|
|
11
|
+
* isSymbol(123) // false
|
|
12
|
+
* isSymbol({}) // false
|
|
13
|
+
* isSymbol([]) // false
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
const isSymbol = (v: unknown): v is symbol => typeof v === 'symbol'
|
|
17
|
+
|
|
18
|
+
export { isSymbol }
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { isTruthy } from './is-truthy.js'
|
|
4
|
+
|
|
5
|
+
describe('is truthy', () => {
|
|
6
|
+
it('should return true for truthy values', () => {
|
|
7
|
+
expect(isTruthy(true)).toBe(true)
|
|
8
|
+
expect(isTruthy(1)).toBe(true)
|
|
9
|
+
expect(isTruthy('hello')).toBe(true)
|
|
10
|
+
expect(isTruthy([])).toBe(true)
|
|
11
|
+
expect(isTruthy({})).toBe(true)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('should return false for non-truthy values', () => {
|
|
15
|
+
expect(isTruthy(false)).toBe(false)
|
|
16
|
+
expect(isTruthy(0)).toBe(false)
|
|
17
|
+
expect(isTruthy(0n)).toBe(false)
|
|
18
|
+
expect(isTruthy('')).toBe(false)
|
|
19
|
+
expect(isTruthy(null)).toBe(false)
|
|
20
|
+
expect(isTruthy(undefined)).toBe(false)
|
|
21
|
+
})
|
|
22
|
+
})
|
package/src/is-truthy.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type Falsy } from './is-falsy.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* isTruthy checks if a value is truthy. A value is considered truthy if it is not falsy.
|
|
5
|
+
* Falsy values are false, 0, 0n, '', null, and undefined.
|
|
6
|
+
* Useful for type narrowing in conditional statements.
|
|
7
|
+
* See isFalsy for the opposite of isTruthy.
|
|
8
|
+
*
|
|
9
|
+
* @param v value to check.
|
|
10
|
+
* @returns {v is Exclude<T, Falsy>} returns true if v is truthy or otherwise false.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* isTruthy(true) // true
|
|
15
|
+
* isTruthy(1) // true
|
|
16
|
+
* isTruthy('hello') // true
|
|
17
|
+
* isTruthy([]) // true
|
|
18
|
+
* isTruthy({}) // true
|
|
19
|
+
* isTruthy(false) // false
|
|
20
|
+
* isTruthy(0) // false
|
|
21
|
+
* isTruthy(0n) // false
|
|
22
|
+
* isTruthy('') // false
|
|
23
|
+
* isTruthy(null) // false
|
|
24
|
+
* isTruthy(undefined) // false
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
const isTruthy = <T>(v: T): v is Exclude<T, Falsy> => !!v
|
|
28
|
+
|
|
29
|
+
export { isTruthy }
|