@jblib/is 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/dist/index.d.ts +13 -1
  2. package/dist/index.js +13 -1
  3. package/dist/is-array.d.ts +21 -0
  4. package/dist/is-array.d.ts.map +1 -0
  5. package/dist/is-array.js +22 -0
  6. package/dist/is-array.js.map +1 -0
  7. package/dist/is-boolean.d.ts +21 -0
  8. package/dist/is-boolean.d.ts.map +1 -0
  9. package/dist/is-boolean.js +22 -0
  10. package/dist/is-boolean.js.map +1 -0
  11. package/dist/is-date.d.ts +21 -0
  12. package/dist/is-date.d.ts.map +1 -0
  13. package/dist/is-date.js +22 -0
  14. package/dist/is-date.js.map +1 -0
  15. package/dist/is-defined.d.ts +19 -0
  16. package/dist/is-defined.d.ts.map +1 -0
  17. package/dist/is-defined.js +20 -0
  18. package/dist/is-defined.js.map +1 -0
  19. package/dist/is-empty-object.d.ts +23 -0
  20. package/dist/is-empty-object.d.ts.map +1 -0
  21. package/dist/is-empty-object.js +26 -0
  22. package/dist/is-empty-object.js.map +1 -0
  23. package/dist/is-error.d.ts +20 -0
  24. package/dist/is-error.d.ts.map +1 -0
  25. package/dist/is-error.js +21 -0
  26. package/dist/is-error.js.map +1 -0
  27. package/dist/is-function.d.ts +20 -0
  28. package/dist/is-function.d.ts.map +1 -0
  29. package/dist/is-function.js +21 -0
  30. package/dist/is-function.js.map +1 -0
  31. package/dist/is-nil.d.ts +21 -0
  32. package/dist/is-nil.d.ts.map +1 -0
  33. package/dist/is-nil.js +22 -0
  34. package/dist/is-nil.js.map +1 -0
  35. package/dist/is-non-empty-array.d.ts +19 -0
  36. package/dist/is-non-empty-array.d.ts.map +1 -0
  37. package/dist/is-non-empty-array.js +20 -0
  38. package/dist/is-non-empty-array.js.map +1 -0
  39. package/dist/is-object.d.ts +20 -0
  40. package/dist/is-object.d.ts.map +1 -0
  41. package/dist/is-object.js +21 -0
  42. package/dist/is-object.js.map +1 -0
  43. package/dist/is-plain-object.d.ts +22 -0
  44. package/dist/is-plain-object.d.ts.map +1 -0
  45. package/dist/is-plain-object.js +27 -0
  46. package/dist/is-plain-object.js.map +1 -0
  47. package/dist/is-primitive.d.ts +27 -0
  48. package/dist/is-primitive.d.ts.map +1 -0
  49. package/dist/is-primitive.js +24 -0
  50. package/dist/is-primitive.js.map +1 -0
  51. package/package.json +2 -2
  52. package/src/index.ts +14 -4
  53. package/src/is-boolean.spec.ts +18 -0
  54. package/src/is-boolean.ts +19 -0
  55. package/src/is-date.spec.ts +21 -0
  56. package/src/is-date.ts +19 -0
  57. package/src/is-defined.spec.ts +15 -0
  58. package/src/is-defined.ts +17 -0
  59. package/src/is-empty-object.spec.ts +25 -0
  60. package/src/is-empty-object.ts +24 -0
  61. package/src/is-error.spec.ts +19 -0
  62. package/src/is-error.ts +18 -0
  63. package/src/is-nil.spec.ts +17 -0
  64. package/src/is-nil.ts +19 -0
  65. package/src/is-object.spec.ts +17 -0
  66. package/src/is-object.ts +18 -0
  67. package/src/is-plain-object.spec.ts +18 -0
  68. package/src/is-plain-object.ts +28 -0
  69. package/src/is-primitive.spec.ts +23 -0
  70. package/src/is-primitive.ts +26 -0
package/dist/index.d.ts CHANGED
@@ -1,3 +1,15 @@
1
+ import { isArray } from "./is-array.js";
2
+ import { isBoolean } from "./is-boolean.js";
3
+ import { isDate } from "./is-date.js";
4
+ import { isDefined } from "./is-defined.js";
5
+ import { isEmptyObject } from "./is-empty-object.js";
6
+ import { isError } from "./is-error.js";
7
+ import { isFunction } from "./is-function.js";
8
+ import { isNil } from "./is-nil.js";
9
+ import { isNonEmptyArray } from "./is-non-empty-array.js";
1
10
  import { isNumber } from "./is-number.js";
11
+ import { isObject } from "./is-object.js";
12
+ import { isPlainObject } from "./is-plain-object.js";
13
+ import { isPrimitive } from "./is-primitive.js";
2
14
  import { isString } from "./is-string.js";
3
- export { isNumber, isString };
15
+ export { isArray, isBoolean, isDate, isDefined, isEmptyObject, isError, isFunction, isNil, isNonEmptyArray, isNumber, isObject, isPlainObject, isPrimitive, isString };
package/dist/index.js CHANGED
@@ -1,4 +1,16 @@
1
+ import { isArray } from "./is-array.js";
2
+ import { isBoolean } from "./is-boolean.js";
3
+ import { isDate } from "./is-date.js";
4
+ import { isDefined } from "./is-defined.js";
5
+ import { isPlainObject } from "./is-plain-object.js";
6
+ import { isEmptyObject } from "./is-empty-object.js";
7
+ import { isError } from "./is-error.js";
8
+ import { isFunction } from "./is-function.js";
9
+ import { isNil } from "./is-nil.js";
10
+ import { isNonEmptyArray } from "./is-non-empty-array.js";
1
11
  import { isNumber } from "./is-number.js";
12
+ import { isObject } from "./is-object.js";
13
+ import { isPrimitive } from "./is-primitive.js";
2
14
  import { isString } from "./is-string.js";
3
15
 
4
- export { isNumber, isString };
16
+ export { isArray, isBoolean, isDate, isDefined, isEmptyObject, isError, isFunction, isNil, isNonEmptyArray, isNumber, isObject, isPlainObject, isPrimitive, isString };
@@ -0,0 +1,21 @@
1
+ //#region src/is-array.d.ts
2
+ /**
3
+ * isArray checks if the provided value is an array.
4
+ *
5
+ * @param v value to check.
6
+ * @returns {v is unknown[]} returns true if the value is an array or otherwise false.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * isArray([]) // true
11
+ * isArray([1, 2, 3]) // true
12
+ * isArray('hello') // false
13
+ * isArray({}) // false
14
+ * isArray(123) // false
15
+ * isArray(undefined) // false
16
+ * ```
17
+ */
18
+ declare const isArray: (v: unknown) => v is unknown[];
19
+ //#endregion
20
+ export { isArray };
21
+ //# sourceMappingURL=is-array.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-array.d.ts","names":[],"sources":["../src/is-array.ts"],"mappings":";;;;;;;;;;;;;;;;;cAgBM,OAAA,GAAW,CAAA,cAAa,CAAA"}
@@ -0,0 +1,22 @@
1
+ //#region src/is-array.ts
2
+ /**
3
+ * isArray checks if the provided value is an array.
4
+ *
5
+ * @param v value to check.
6
+ * @returns {v is unknown[]} returns true if the value is an array or otherwise false.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * isArray([]) // true
11
+ * isArray([1, 2, 3]) // true
12
+ * isArray('hello') // false
13
+ * isArray({}) // false
14
+ * isArray(123) // false
15
+ * isArray(undefined) // false
16
+ * ```
17
+ */
18
+ const isArray = (v) => Array.isArray(v);
19
+
20
+ //#endregion
21
+ export { isArray };
22
+ //# sourceMappingURL=is-array.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-array.js","names":[],"sources":["../src/is-array.ts"],"sourcesContent":["/**\n * isArray checks if the provided value is an array.\n *\n * @param v value to check.\n * @returns {v is unknown[]} returns true if the value is an array or otherwise false.\n *\n * @example\n * ```ts\n * isArray([]) // true\n * isArray([1, 2, 3]) // true\n * isArray('hello') // false\n * isArray({}) // false\n * isArray(123) // false\n * isArray(undefined) // false\n * ```\n */\nconst isArray = (v: unknown): v is unknown[] => Array.isArray(v)\n\nexport { isArray }\n"],"mappings":";;;;;;;;;;;;;;;;;AAgBA,MAAM,WAAW,MAA+B,MAAM,QAAQ,EAAE"}
@@ -0,0 +1,21 @@
1
+ //#region src/is-boolean.d.ts
2
+ /**
3
+ * isBoolean checks if a value is a boolean.
4
+ *
5
+ * @param v value to check.
6
+ * @returns {v is boolean} returns true if the value is a boolean or otherwise false.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * isBoolean(true) // true
11
+ * isBoolean(false) // true
12
+ * isBoolean('hello') // false
13
+ * isBoolean(42) // false
14
+ * isBoolean(null) // false
15
+ * isBoolean(undefined) // false
16
+ * ```
17
+ */
18
+ declare const isBoolean: (v: unknown) => v is boolean;
19
+ //#endregion
20
+ export { isBoolean };
21
+ //# sourceMappingURL=is-boolean.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-boolean.d.ts","names":[],"sources":["../src/is-boolean.ts"],"mappings":";;;;;;;;;;;;;;;;;cAgBM,SAAA,GAAa,CAAA,cAAa,CAAA"}
@@ -0,0 +1,22 @@
1
+ //#region src/is-boolean.ts
2
+ /**
3
+ * isBoolean checks if a value is a boolean.
4
+ *
5
+ * @param v value to check.
6
+ * @returns {v is boolean} returns true if the value is a boolean or otherwise false.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * isBoolean(true) // true
11
+ * isBoolean(false) // true
12
+ * isBoolean('hello') // false
13
+ * isBoolean(42) // false
14
+ * isBoolean(null) // false
15
+ * isBoolean(undefined) // false
16
+ * ```
17
+ */
18
+ const isBoolean = (v) => typeof v === "boolean";
19
+
20
+ //#endregion
21
+ export { isBoolean };
22
+ //# sourceMappingURL=is-boolean.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-boolean.js","names":[],"sources":["../src/is-boolean.ts"],"sourcesContent":["/**\n * isBoolean checks if a value is a boolean.\n *\n * @param v value to check.\n * @returns {v is boolean} returns true if the value is a boolean or otherwise false.\n *\n * @example\n * ```ts\n * isBoolean(true) // true\n * isBoolean(false) // true\n * isBoolean('hello') // false\n * isBoolean(42) // false\n * isBoolean(null) // false\n * isBoolean(undefined) // false\n * ```\n */\nconst isBoolean = (v: unknown): v is boolean => typeof v === 'boolean'\n\nexport { isBoolean }\n"],"mappings":";;;;;;;;;;;;;;;;;AAgBA,MAAM,aAAa,MAA6B,OAAO,MAAM"}
@@ -0,0 +1,21 @@
1
+ //#region src/is-date.d.ts
2
+ /**
3
+ * isDate checks if the value is an instance of Date and is a valid date.
4
+ *
5
+ * @param v value to check.
6
+ * @returns {v instanceof Date} returns true if the value is an instance of Date and is a valid date or otherwise false.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * isDate(new Date()) // true
11
+ * isDate(new Date('invalid date')) // false
12
+ * isDate('2022-01-01') // false
13
+ * isDate(1640995200000) // false
14
+ * isDate(null) // false
15
+ * isDate(undefined) // false
16
+ * ```
17
+ */
18
+ declare const isDate: (v: unknown) => v is Date;
19
+ //#endregion
20
+ export { isDate };
21
+ //# sourceMappingURL=is-date.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-date.d.ts","names":[],"sources":["../src/is-date.ts"],"mappings":";;;;;;;;;;;;;;;;;cAgBM,MAAA,GAAU,CAAA,cAAa,CAAA,IAAK,IAAA"}
@@ -0,0 +1,22 @@
1
+ //#region src/is-date.ts
2
+ /**
3
+ * isDate checks if the value is an instance of Date and is a valid date.
4
+ *
5
+ * @param v value to check.
6
+ * @returns {v instanceof Date} returns true if the value is an instance of Date and is a valid date or otherwise false.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * isDate(new Date()) // true
11
+ * isDate(new Date('invalid date')) // false
12
+ * isDate('2022-01-01') // false
13
+ * isDate(1640995200000) // false
14
+ * isDate(null) // false
15
+ * isDate(undefined) // false
16
+ * ```
17
+ */
18
+ const isDate = (v) => v instanceof Date && !isNaN(v.getTime());
19
+
20
+ //#endregion
21
+ export { isDate };
22
+ //# sourceMappingURL=is-date.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-date.js","names":[],"sources":["../src/is-date.ts"],"sourcesContent":["/**\n * isDate checks if the value is an instance of Date and is a valid date.\n *\n * @param v value to check.\n * @returns {v instanceof Date} returns true if the value is an instance of Date and is a valid date or otherwise false.\n *\n * @example\n * ```ts\n * isDate(new Date()) // true\n * isDate(new Date('invalid date')) // false\n * isDate('2022-01-01') // false\n * isDate(1640995200000) // false\n * isDate(null) // false\n * isDate(undefined) // false\n * ```\n */\nconst isDate = (v: unknown): v is Date => v instanceof Date && !isNaN(v.getTime())\n\nexport { isDate }\n"],"mappings":";;;;;;;;;;;;;;;;;AAgBA,MAAM,UAAU,MAA0B,aAAa,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC"}
@@ -0,0 +1,19 @@
1
+ //#region src/is-defined.d.ts
2
+ /**
3
+ * isDefined checks if a value is not null or undefined.
4
+ *
5
+ * @param v value to check.
6
+ * @returns {v is T} returns true if the value is defined (not null or undefined) or otherwise false.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * isDefined(42) // true
11
+ * isDefined('hello') // true
12
+ * isDefined(null) // false
13
+ * isDefined(undefined) // false
14
+ * ```
15
+ */
16
+ declare const isDefined: <T>(v: T | null | undefined) => v is T;
17
+ //#endregion
18
+ export { isDefined };
19
+ //# sourceMappingURL=is-defined.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-defined.d.ts","names":[],"sources":["../src/is-defined.ts"],"mappings":";;;;;;;;;;;;;;;cAcM,SAAA,MAAgB,CAAA,EAAG,CAAA,wBAAuB,CAAA,IAAK,CAAA"}
@@ -0,0 +1,20 @@
1
+ //#region src/is-defined.ts
2
+ /**
3
+ * isDefined checks if a value is not null or undefined.
4
+ *
5
+ * @param v value to check.
6
+ * @returns {v is T} returns true if the value is defined (not null or undefined) or otherwise false.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * isDefined(42) // true
11
+ * isDefined('hello') // true
12
+ * isDefined(null) // false
13
+ * isDefined(undefined) // false
14
+ * ```
15
+ */
16
+ const isDefined = (v) => v !== null && v !== void 0;
17
+
18
+ //#endregion
19
+ export { isDefined };
20
+ //# sourceMappingURL=is-defined.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-defined.js","names":[],"sources":["../src/is-defined.ts"],"sourcesContent":["/**\n * isDefined checks if a value is not null or undefined.\n *\n * @param v value to check.\n * @returns {v is T} returns true if the value is defined (not null or undefined) or otherwise false.\n *\n * @example\n * ```ts\n * isDefined(42) // true\n * isDefined('hello') // true\n * isDefined(null) // false\n * isDefined(undefined) // false\n * ```\n */\nconst isDefined = <T>(v: T | null | undefined): v is T => v !== null && v !== undefined\n\nexport { isDefined }\n"],"mappings":";;;;;;;;;;;;;;;AAcA,MAAM,aAAgB,MAAoC,MAAM,QAAQ,MAAM"}
@@ -0,0 +1,23 @@
1
+ //#region src/is-empty-object.d.ts
2
+ /**
3
+ * isEmptyObject checks if a value is an empty object, that is,
4
+ * a plain object with no own properties.
5
+ *
6
+ * @param v value to check.
7
+ * @returns {v is Record<PropertyKey, never>} returns true if the value is an empty object or otherwise false.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * isEmptyObject({}) // true
12
+ * isEmptyObject(Object.create(null)) // true
13
+ * isEmptyObject({ a: 1 }) // false
14
+ * isEmptyObject([]) // false
15
+ * isEmptyObject(null) // false
16
+ * isEmptyObject('hello') // false
17
+ * isEmptyObject(42) // false
18
+ * ```
19
+ */
20
+ declare const isEmptyObject: (v: unknown) => v is Record<PropertyKey, never>;
21
+ //#endregion
22
+ export { isEmptyObject };
23
+ //# sourceMappingURL=is-empty-object.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-empty-object.d.ts","names":[],"sources":["../src/is-empty-object.ts"],"mappings":";;;;;;;;;;;;;;;;;;;cAoBM,aAAA,GAAiB,CAAA,cAAa,CAAA,IAAK,MAAA,CAAO,WAAA"}
@@ -0,0 +1,26 @@
1
+ import { isPlainObject } from "./is-plain-object.js";
2
+
3
+ //#region src/is-empty-object.ts
4
+ /**
5
+ * isEmptyObject checks if a value is an empty object, that is,
6
+ * a plain object with no own properties.
7
+ *
8
+ * @param v value to check.
9
+ * @returns {v is Record<PropertyKey, never>} returns true if the value is an empty object or otherwise false.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * isEmptyObject({}) // true
14
+ * isEmptyObject(Object.create(null)) // true
15
+ * isEmptyObject({ a: 1 }) // false
16
+ * isEmptyObject([]) // false
17
+ * isEmptyObject(null) // false
18
+ * isEmptyObject('hello') // false
19
+ * isEmptyObject(42) // false
20
+ * ```
21
+ */
22
+ const isEmptyObject = (v) => isPlainObject(v) && Reflect.ownKeys(v).length === 0;
23
+
24
+ //#endregion
25
+ export { isEmptyObject };
26
+ //# sourceMappingURL=is-empty-object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-empty-object.js","names":[],"sources":["../src/is-empty-object.ts"],"sourcesContent":["import { isPlainObject } from './is-plain-object.js'\n\n/**\n * isEmptyObject checks if a value is an empty object, that is,\n * a plain object with no own properties.\n *\n * @param v value to check.\n * @returns {v is Record<PropertyKey, never>} returns true if the value is an empty object or otherwise false.\n *\n * @example\n * ```ts\n * isEmptyObject({}) // true\n * isEmptyObject(Object.create(null)) // true\n * isEmptyObject({ a: 1 }) // false\n * isEmptyObject([]) // false\n * isEmptyObject(null) // false\n * isEmptyObject('hello') // false\n * isEmptyObject(42) // false\n * ```\n */\nconst isEmptyObject = (v: unknown): v is Record<PropertyKey, never> =>\n isPlainObject(v) && Reflect.ownKeys(v).length === 0\n\nexport { isEmptyObject }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAoBA,MAAM,iBAAiB,MACrB,cAAc,EAAE,IAAI,QAAQ,QAAQ,EAAE,CAAC,WAAW"}
@@ -0,0 +1,20 @@
1
+ //#region src/is-error.d.ts
2
+ /**
3
+ * isError checks if the value is an instance of Error.
4
+ *
5
+ * @param v value to check.
6
+ * @returns {v is Error} returns true if the value is an instance of Error or otherwise false.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * isError(new Error()) // true
11
+ * isError('hello') // false
12
+ * isError({}) // false
13
+ * isError(123) // false
14
+ * isError(null) // false
15
+ * ```
16
+ */
17
+ declare const isError: (v: unknown) => v is Error;
18
+ //#endregion
19
+ export { isError };
20
+ //# sourceMappingURL=is-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-error.d.ts","names":[],"sources":["../src/is-error.ts"],"mappings":";;;;;;;;;;;;;;;;cAeM,OAAA,GAAW,CAAA,cAAa,CAAA,IAAK,KAAA"}
@@ -0,0 +1,21 @@
1
+ //#region src/is-error.ts
2
+ /**
3
+ * isError checks if the value is an instance of Error.
4
+ *
5
+ * @param v value to check.
6
+ * @returns {v is Error} returns true if the value is an instance of Error or otherwise false.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * isError(new Error()) // true
11
+ * isError('hello') // false
12
+ * isError({}) // false
13
+ * isError(123) // false
14
+ * isError(null) // false
15
+ * ```
16
+ */
17
+ const isError = (v) => v instanceof Error;
18
+
19
+ //#endregion
20
+ export { isError };
21
+ //# sourceMappingURL=is-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-error.js","names":[],"sources":["../src/is-error.ts"],"sourcesContent":["/**\n * isError checks if the value is an instance of Error.\n *\n * @param v value to check.\n * @returns {v is Error} returns true if the value is an instance of Error or otherwise false.\n *\n * @example\n * ```ts\n * isError(new Error()) // true\n * isError('hello') // false\n * isError({}) // false\n * isError(123) // false\n * isError(null) // false\n * ```\n */\nconst isError = (v: unknown): v is Error => v instanceof Error\n\nexport { isError }\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,MAAM,WAAW,MAA2B,aAAa"}
@@ -0,0 +1,20 @@
1
+ //#region src/is-function.d.ts
2
+ /**
3
+ * isFunction checks if the provided value is a function.
4
+ *
5
+ * @param v value to check.
6
+ * @returns {v is (...args: unknown[]) => unknown} returns true if v is a function or otherwise false.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * isFunction(() => {}) // true
11
+ * isFunction(function() {}) // true
12
+ * isFunction(async function() {}) // true
13
+ * isFunction('hello') // false
14
+ * isFunction({}) // false
15
+ * ```
16
+ */
17
+ declare const isFunction: (v: unknown) => v is (...args: unknown[]) => unknown;
18
+ //#endregion
19
+ export { isFunction };
20
+ //# sourceMappingURL=is-function.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-function.d.ts","names":[],"sources":["../src/is-function.ts"],"mappings":";;;;;;;;;;;;;;;;cAeM,UAAA,GAAc,CAAA,cAAa,CAAA,QAAS,IAAA"}
@@ -0,0 +1,21 @@
1
+ //#region src/is-function.ts
2
+ /**
3
+ * isFunction checks if the provided value is a function.
4
+ *
5
+ * @param v value to check.
6
+ * @returns {v is (...args: unknown[]) => unknown} returns true if v is a function or otherwise false.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * isFunction(() => {}) // true
11
+ * isFunction(function() {}) // true
12
+ * isFunction(async function() {}) // true
13
+ * isFunction('hello') // false
14
+ * isFunction({}) // false
15
+ * ```
16
+ */
17
+ const isFunction = (v) => typeof v === "function";
18
+
19
+ //#endregion
20
+ export { isFunction };
21
+ //# sourceMappingURL=is-function.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-function.js","names":[],"sources":["../src/is-function.ts"],"sourcesContent":["/**\n * isFunction checks if the provided value is a function.\n *\n * @param v value to check.\n * @returns {v is (...args: unknown[]) => unknown} returns true if v is a function or otherwise false.\n *\n * @example\n * ```ts\n * isFunction(() => {}) // true\n * isFunction(function() {}) // true\n * isFunction(async function() {}) // true\n * isFunction('hello') // false\n * isFunction({}) // false\n * ```\n */\nconst isFunction = (v: unknown): v is (...args: unknown[]) => unknown => typeof v === 'function'\n\nexport { isFunction }\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,MAAM,cAAc,MAAqD,OAAO,MAAM"}
@@ -0,0 +1,21 @@
1
+ //#region src/is-nil.d.ts
2
+ /**
3
+ * isNil checks if a value is null or undefined.
4
+ *
5
+ * @param v value to check.
6
+ * @returns {v is null | undefined} returns true if the value is null or undefined or otherwise false.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * isNil(null) // true
11
+ * isNil(undefined) // true
12
+ * isNil(42) // false
13
+ * isNil('hello') // false
14
+ * isNil({}) // false
15
+ * isNil([]) // false
16
+ * ```
17
+ */
18
+ declare const isNil: (v: unknown) => v is null | undefined;
19
+ //#endregion
20
+ export { isNil };
21
+ //# sourceMappingURL=is-nil.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-nil.d.ts","names":[],"sources":["../src/is-nil.ts"],"mappings":";;;;;;;;;;;;;;;;;cAgBM,KAAA,GAAS,CAAA,cAAa,CAAA"}
package/dist/is-nil.js ADDED
@@ -0,0 +1,22 @@
1
+ //#region src/is-nil.ts
2
+ /**
3
+ * isNil checks if a value is null or undefined.
4
+ *
5
+ * @param v value to check.
6
+ * @returns {v is null | undefined} returns true if the value is null or undefined or otherwise false.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * isNil(null) // true
11
+ * isNil(undefined) // true
12
+ * isNil(42) // false
13
+ * isNil('hello') // false
14
+ * isNil({}) // false
15
+ * isNil([]) // false
16
+ * ```
17
+ */
18
+ const isNil = (v) => v === null || v === void 0;
19
+
20
+ //#endregion
21
+ export { isNil };
22
+ //# sourceMappingURL=is-nil.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-nil.js","names":[],"sources":["../src/is-nil.ts"],"sourcesContent":["/**\n * isNil checks if a value is null or undefined.\n *\n * @param v value to check.\n * @returns {v is null | undefined} returns true if the value is null or undefined or otherwise false.\n *\n * @example\n * ```ts\n * isNil(null) // true\n * isNil(undefined) // true\n * isNil(42) // false\n * isNil('hello') // false\n * isNil({}) // false\n * isNil([]) // false\n * ```\n */\nconst isNil = (v: unknown): v is null | undefined => v === null || v === undefined\n\nexport { isNil }\n"],"mappings":";;;;;;;;;;;;;;;;;AAgBA,MAAM,SAAS,MAAsC,MAAM,QAAQ,MAAM"}
@@ -0,0 +1,19 @@
1
+ //#region src/is-non-empty-array.d.ts
2
+ /**
3
+ * isNonEmptyArray checks if the provided value is an array and contains at least one element.
4
+ *
5
+ * @param v value to check.
6
+ * @returns {v is unknown[]} returns true if v is a non-empty array or otherwise false.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * isNonEmptyArray([1, 2, 3]) // true
11
+ * isNonEmptyArray([]) // false
12
+ * isNonEmptyArray('hello') // false
13
+ * isNonEmptyArray({}) // false
14
+ * ```
15
+ */
16
+ declare const isNonEmptyArray: (v: unknown) => v is unknown[];
17
+ //#endregion
18
+ export { isNonEmptyArray };
19
+ //# sourceMappingURL=is-non-empty-array.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-non-empty-array.d.ts","names":[],"sources":["../src/is-non-empty-array.ts"],"mappings":";;;;;;;;;;;;;;;cAcM,eAAA,GAAmB,CAAA,cAAa,CAAA"}
@@ -0,0 +1,20 @@
1
+ //#region src/is-non-empty-array.ts
2
+ /**
3
+ * isNonEmptyArray checks if the provided value is an array and contains at least one element.
4
+ *
5
+ * @param v value to check.
6
+ * @returns {v is unknown[]} returns true if v is a non-empty array or otherwise false.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * isNonEmptyArray([1, 2, 3]) // true
11
+ * isNonEmptyArray([]) // false
12
+ * isNonEmptyArray('hello') // false
13
+ * isNonEmptyArray({}) // false
14
+ * ```
15
+ */
16
+ const isNonEmptyArray = (v) => Array.isArray(v) && v.length > 0;
17
+
18
+ //#endregion
19
+ export { isNonEmptyArray };
20
+ //# sourceMappingURL=is-non-empty-array.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-non-empty-array.js","names":[],"sources":["../src/is-non-empty-array.ts"],"sourcesContent":["/**\n * isNonEmptyArray checks if the provided value is an array and contains at least one element.\n *\n * @param v value to check.\n * @returns {v is unknown[]} returns true if v is a non-empty array or otherwise false.\n *\n * @example\n * ```ts\n * isNonEmptyArray([1, 2, 3]) // true\n * isNonEmptyArray([]) // false\n * isNonEmptyArray('hello') // false\n * isNonEmptyArray({}) // false\n * ```\n */\nconst isNonEmptyArray = (v: unknown): v is unknown[] => Array.isArray(v) && v.length > 0\n\nexport { isNonEmptyArray }\n"],"mappings":";;;;;;;;;;;;;;;AAcA,MAAM,mBAAmB,MAA+B,MAAM,QAAQ,EAAE,IAAI,EAAE,SAAS"}
@@ -0,0 +1,20 @@
1
+ //#region src/is-object.d.ts
2
+ /**
3
+ * isObject checks if the value is an object.
4
+ *
5
+ * @param v value to check.
6
+ * @returns {v is object} returns true if the value is an object or otherwise false.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * isObject({}) // true
11
+ * isObject([]) // true
12
+ * isObject(null) // false
13
+ * isObject('hello') // false
14
+ * isObject(42) // false
15
+ * ```
16
+ */
17
+ declare const isObject: (v: unknown) => v is object;
18
+ //#endregion
19
+ export { isObject };
20
+ //# sourceMappingURL=is-object.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-object.d.ts","names":[],"sources":["../src/is-object.ts"],"mappings":";;;;;;;;;;;;;;;;cAeM,QAAA,GAAY,CAAA,cAAa,CAAA"}
@@ -0,0 +1,21 @@
1
+ //#region src/is-object.ts
2
+ /**
3
+ * isObject checks if the value is an object.
4
+ *
5
+ * @param v value to check.
6
+ * @returns {v is object} returns true if the value is an object or otherwise false.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * isObject({}) // true
11
+ * isObject([]) // true
12
+ * isObject(null) // false
13
+ * isObject('hello') // false
14
+ * isObject(42) // false
15
+ * ```
16
+ */
17
+ const isObject = (v) => typeof v === "object" && v !== null;
18
+
19
+ //#endregion
20
+ export { isObject };
21
+ //# sourceMappingURL=is-object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-object.js","names":[],"sources":["../src/is-object.ts"],"sourcesContent":["/**\n * isObject checks if the value is an object.\n *\n * @param v value to check.\n * @returns {v is object} returns true if the value is an object or otherwise false.\n *\n * @example\n * ```ts\n * isObject({}) // true\n * isObject([]) // true\n * isObject(null) // false\n * isObject('hello') // false\n * isObject(42) // false\n * ```\n */\nconst isObject = (v: unknown): v is object => typeof v === 'object' && v !== null\n\nexport { isObject }\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,MAAM,YAAY,MAA4B,OAAO,MAAM,YAAY,MAAM"}
@@ -0,0 +1,22 @@
1
+ //#region src/is-plain-object.d.ts
2
+ /**
3
+ * isPlainObject checks if a value is a plain object, that is,
4
+ * an object created by the Object constructor or with a null prototype.
5
+ *
6
+ * @param v value to check.
7
+ * @returns {v is Record<PropertyKey, unknown>} returns true if the value is a plain object or otherwise false.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * isPlainObject({}) // true
12
+ * isPlainObject(Object.create(null)) // true
13
+ * isPlainObject([]) // false
14
+ * isPlainObject(null) // false
15
+ * isPlainObject('hello') // false
16
+ * isPlainObject(42) // false
17
+ * ```
18
+ */
19
+ declare const isPlainObject: (v: unknown) => v is Record<PropertyKey, unknown>;
20
+ //#endregion
21
+ export { isPlainObject };
22
+ //# sourceMappingURL=is-plain-object.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-plain-object.d.ts","names":[],"sources":["../src/is-plain-object.ts"],"mappings":";;;;;;;;;;;;;;;;;;cAiBM,aAAA,GAAiB,CAAA,cAAa,CAAA,IAAK,MAAA,CAAO,WAAA"}
@@ -0,0 +1,27 @@
1
+ //#region src/is-plain-object.ts
2
+ /**
3
+ * isPlainObject checks if a value is a plain object, that is,
4
+ * an object created by the Object constructor or with a null prototype.
5
+ *
6
+ * @param v value to check.
7
+ * @returns {v is Record<PropertyKey, unknown>} returns true if the value is a plain object or otherwise false.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * isPlainObject({}) // true
12
+ * isPlainObject(Object.create(null)) // true
13
+ * isPlainObject([]) // false
14
+ * isPlainObject(null) // false
15
+ * isPlainObject('hello') // false
16
+ * isPlainObject(42) // false
17
+ * ```
18
+ */
19
+ const isPlainObject = (v) => {
20
+ if (typeof v !== "object" || v === null) return false;
21
+ const proto = Object.getPrototypeOf(v);
22
+ return proto === Object.prototype || proto === null;
23
+ };
24
+
25
+ //#endregion
26
+ export { isPlainObject };
27
+ //# sourceMappingURL=is-plain-object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-plain-object.js","names":[],"sources":["../src/is-plain-object.ts"],"sourcesContent":["/**\n * isPlainObject checks if a value is a plain object, that is,\n * an object created by the Object constructor or with a null prototype.\n *\n * @param v value to check.\n * @returns {v is Record<PropertyKey, unknown>} returns true if the value is a plain object or otherwise false.\n *\n * @example\n * ```ts\n * isPlainObject({}) // true\n * isPlainObject(Object.create(null)) // true\n * isPlainObject([]) // false\n * isPlainObject(null) // false\n * isPlainObject('hello') // false\n * isPlainObject(42) // false\n * ```\n */\nconst isPlainObject = (v: unknown): v is Record<PropertyKey, unknown> => {\n if (typeof v !== 'object' || v === null) {\n return false\n }\n\n const proto = Object.getPrototypeOf(v) as unknown\n\n return proto === Object.prototype || proto === null\n}\n\nexport { isPlainObject }\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,MAAM,iBAAiB,MAAkD;AACvE,KAAI,OAAO,MAAM,YAAY,MAAM,KACjC,QAAO;CAGT,MAAM,QAAQ,OAAO,eAAe,EAAE;AAEtC,QAAO,UAAU,OAAO,aAAa,UAAU"}
@@ -0,0 +1,27 @@
1
+ //#region src/is-primitive.d.ts
2
+ /**
3
+ * Primitive type represents the primitive values.
4
+ */
5
+ type Primitive = string | number | boolean | bigint | symbol | null | undefined;
6
+ /**
7
+ * isPrimitive checks if a value is a primitive.
8
+ *
9
+ * @param v value to check.
10
+ * @returns {v is Primitive} returns true if the value is a primitive or otherwise false.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * isPrimitive(42) // true
15
+ * isPrimitive('hello') // true
16
+ * isPrimitive(true) // true
17
+ * isPrimitive(null) // true
18
+ * isPrimitive(undefined) // true
19
+ * isPrimitive({}) // false
20
+ * isPrimitive([]) // false
21
+ * isPrimitive(() => {}) // false
22
+ * ```
23
+ */
24
+ declare const isPrimitive: (v: unknown) => v is Primitive;
25
+ //#endregion
26
+ export { isPrimitive };
27
+ //# sourceMappingURL=is-primitive.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-primitive.d.ts","names":[],"sources":["../src/is-primitive.ts"],"mappings":";;;;KAGK,SAAA;;;AAAS;;;;;;;;;;;;;;;;cAoBR,WAAA,GAAe,CAAA,cAAa,CAAA,IAAK,SAAA"}
@@ -0,0 +1,24 @@
1
+ //#region src/is-primitive.ts
2
+ /**
3
+ * isPrimitive checks if a value is a primitive.
4
+ *
5
+ * @param v value to check.
6
+ * @returns {v is Primitive} returns true if the value is a primitive or otherwise false.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * isPrimitive(42) // true
11
+ * isPrimitive('hello') // true
12
+ * isPrimitive(true) // true
13
+ * isPrimitive(null) // true
14
+ * isPrimitive(undefined) // true
15
+ * isPrimitive({}) // false
16
+ * isPrimitive([]) // false
17
+ * isPrimitive(() => {}) // false
18
+ * ```
19
+ */
20
+ const isPrimitive = (v) => v === null || typeof v !== "object" && typeof v !== "function";
21
+
22
+ //#endregion
23
+ export { isPrimitive };
24
+ //# sourceMappingURL=is-primitive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-primitive.js","names":[],"sources":["../src/is-primitive.ts"],"sourcesContent":["/**\n * Primitive type represents the primitive values.\n */\ntype Primitive = string | number | boolean | bigint | symbol | null | undefined\n\n/**\n * isPrimitive checks if a value is a primitive.\n *\n * @param v value to check.\n * @returns {v is Primitive} returns true if the value is a primitive or otherwise false.\n *\n * @example\n * ```ts\n * isPrimitive(42) // true\n * isPrimitive('hello') // true\n * isPrimitive(true) // true\n * isPrimitive(null) // true\n * isPrimitive(undefined) // true\n * isPrimitive({}) // false\n * isPrimitive([]) // false\n * isPrimitive(() => {}) // false\n * ```\n */\nconst isPrimitive = (v: unknown): v is Primitive => v === null || (typeof v !== 'object' && typeof v !== 'function')\n\nexport { isPrimitive }\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAuBA,MAAM,eAAe,MAA+B,MAAM,QAAS,OAAO,MAAM,YAAY,OAAO,MAAM"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jblib/is",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "is, condition checks",
5
5
  "type": "module",
6
6
  "devDependencies": {
@@ -8,7 +8,7 @@
8
8
  "tsdown": "^0.21.10",
9
9
  "typescript": "^6.0.3",
10
10
  "vitest": "^4.1.5",
11
- "@jblib/eslint": "0.0.4"
11
+ "@jblib/eslint": "0.0.7"
12
12
  },
13
13
  "keywords": [
14
14
  "is"
package/src/index.ts CHANGED
@@ -1,4 +1,14 @@
1
- import { isNumber } from './is-number.js'
2
- import { isString } from './is-string.js'
3
-
4
- export { isNumber, isString }
1
+ export { isArray } from './is-array.js'
2
+ export { isBoolean } from './is-boolean.js'
3
+ export { isDate } from './is-date.js'
4
+ export { isDefined } from './is-defined.js'
5
+ export { isEmptyObject } from './is-empty-object.js'
6
+ export { isError } from './is-error.js'
7
+ export { isFunction } from './is-function.js'
8
+ export { isNil } from './is-nil.js'
9
+ export { isNonEmptyArray } from './is-non-empty-array.js'
10
+ export { isNumber } from './is-number.js'
11
+ export { isObject } from './is-object.js'
12
+ export { isPlainObject } from './is-plain-object.js'
13
+ export { isPrimitive } from './is-primitive.js'
14
+ export { isString } from './is-string.js'
@@ -0,0 +1,18 @@
1
+ import { describe, expect, it } from 'vitest'
2
+
3
+ import { isBoolean } from './is-boolean.js'
4
+
5
+ describe('is boolean', () => {
6
+ it('should return true for booleans', () => {
7
+ expect(isBoolean(true)).toBe(true)
8
+ expect(isBoolean(false)).toBe(true)
9
+ })
10
+
11
+ it('should return false for non-booleans', () => {
12
+ expect(isBoolean('hello')).toBe(false)
13
+ expect(isBoolean({})).toBe(false)
14
+ expect(isBoolean(123)).toBe(false)
15
+ expect(isBoolean(null)).toBe(false)
16
+ expect(isBoolean(undefined)).toBe(false)
17
+ })
18
+ })
@@ -0,0 +1,19 @@
1
+ /**
2
+ * isBoolean checks if a value is a boolean.
3
+ *
4
+ * @param v value to check.
5
+ * @returns {v is boolean} returns true if the value is a boolean or otherwise false.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * isBoolean(true) // true
10
+ * isBoolean(false) // true
11
+ * isBoolean('hello') // false
12
+ * isBoolean(42) // false
13
+ * isBoolean(null) // false
14
+ * isBoolean(undefined) // false
15
+ * ```
16
+ */
17
+ const isBoolean = (v: unknown): v is boolean => typeof v === 'boolean'
18
+
19
+ export { isBoolean }
@@ -0,0 +1,21 @@
1
+ import { describe, expect, it } from 'vitest'
2
+
3
+ import { isDate } from './is-date.js'
4
+
5
+ describe('is date', () => {
6
+ it('should return true for valid dates', () => {
7
+ expect(isDate(new Date())).toBe(true)
8
+ })
9
+
10
+ it('should return false for invalid dates', () => {
11
+ expect(isDate(new Date('invalid date'))).toBe(false)
12
+ })
13
+
14
+ it('should return false for non-date values', () => {
15
+ expect(isDate('2022-01-01')).toBe(false)
16
+ expect(isDate(1640995200000)).toBe(false)
17
+ expect(isDate({})).toBe(false)
18
+ expect(isDate(null)).toBe(false)
19
+ expect(isDate(undefined)).toBe(false)
20
+ })
21
+ })
package/src/is-date.ts ADDED
@@ -0,0 +1,19 @@
1
+ /**
2
+ * isDate checks if the value is an instance of Date and is a valid date.
3
+ *
4
+ * @param v value to check.
5
+ * @returns {v instanceof Date} returns true if the value is an instance of Date and is a valid date or otherwise false.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * isDate(new Date()) // true
10
+ * isDate(new Date('invalid date')) // false
11
+ * isDate('2022-01-01') // false
12
+ * isDate(1640995200000) // false
13
+ * isDate(null) // false
14
+ * isDate(undefined) // false
15
+ * ```
16
+ */
17
+ const isDate = (v: unknown): v is Date => v instanceof Date && !isNaN(v.getTime())
18
+
19
+ export { isDate }
@@ -0,0 +1,15 @@
1
+ import { describe, expect, it } from 'vitest'
2
+
3
+ import { isDefined } from './is-defined.js'
4
+
5
+ describe('is defined', () => {
6
+ it('should return true for defined values', () => {
7
+ expect(isDefined(42)).toBe(true)
8
+ expect(isDefined('hello')).toBe(true)
9
+ })
10
+
11
+ it('should return false for null or undefined', () => {
12
+ expect(isDefined(null)).toBe(false)
13
+ expect(isDefined(undefined)).toBe(false)
14
+ })
15
+ })
@@ -0,0 +1,17 @@
1
+ /**
2
+ * isDefined checks if a value is not null or undefined.
3
+ *
4
+ * @param v value to check.
5
+ * @returns {v is T} returns true if the value is defined (not null or undefined) or otherwise false.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * isDefined(42) // true
10
+ * isDefined('hello') // true
11
+ * isDefined(null) // false
12
+ * isDefined(undefined) // false
13
+ * ```
14
+ */
15
+ const isDefined = <T>(v: T | null | undefined): v is T => v !== null && v !== undefined
16
+
17
+ export { isDefined }
@@ -0,0 +1,25 @@
1
+ import { describe, expect, it } from 'vitest'
2
+
3
+ import { isEmptyObject } from './is-empty-object.js'
4
+
5
+ describe('is empty object', () => {
6
+ it('should return true for empty objects', () => {
7
+ expect(isEmptyObject({})).toBe(true)
8
+ expect(isEmptyObject(Object.create(null))).toBe(true)
9
+ })
10
+
11
+ it('should return false for non-empty objects', () => {
12
+ expect(
13
+ isEmptyObject({
14
+ a: 1,
15
+ }),
16
+ ).toBe(false)
17
+ })
18
+
19
+ it('should return false for non-object values', () => {
20
+ expect(isEmptyObject([])).toBe(false)
21
+ expect(isEmptyObject(null)).toBe(false)
22
+ expect(isEmptyObject('hello')).toBe(false)
23
+ expect(isEmptyObject(42)).toBe(false)
24
+ })
25
+ })
@@ -0,0 +1,24 @@
1
+ import { isPlainObject } from './is-plain-object.js'
2
+
3
+ /**
4
+ * isEmptyObject checks if a value is an empty object, that is,
5
+ * a plain object with no own properties.
6
+ *
7
+ * @param v value to check.
8
+ * @returns {v is Record<PropertyKey, never>} returns true if the value is an empty object or otherwise false.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * isEmptyObject({}) // true
13
+ * isEmptyObject(Object.create(null)) // true
14
+ * isEmptyObject({ a: 1 }) // false
15
+ * isEmptyObject([]) // false
16
+ * isEmptyObject(null) // false
17
+ * isEmptyObject('hello') // false
18
+ * isEmptyObject(42) // false
19
+ * ```
20
+ */
21
+ const isEmptyObject = (v: unknown): v is Record<PropertyKey, never> =>
22
+ isPlainObject(v) && Reflect.ownKeys(v).length === 0
23
+
24
+ export { isEmptyObject }
@@ -0,0 +1,19 @@
1
+ import { describe, expect, it } from 'vitest'
2
+
3
+ import { isError } from './is-error.js'
4
+
5
+ describe('is error', () => {
6
+ it('should return true for errors', () => {
7
+ expect(isError(new Error())).toBe(true)
8
+ expect(isError(new Error('error message'))).toBe(true)
9
+ })
10
+
11
+ it('should return false for non-errors', () => {
12
+ expect(isError('hello')).toBe(false)
13
+ expect(isError({})).toBe(false)
14
+ expect(isError(123)).toBe(false)
15
+ expect(isError(null)).toBe(false)
16
+ expect(isError(undefined)).toBe(false)
17
+ expect(isError([])).toBe(false)
18
+ })
19
+ })
@@ -0,0 +1,18 @@
1
+ /**
2
+ * isError checks if the value is an instance of Error.
3
+ *
4
+ * @param v value to check.
5
+ * @returns {v is Error} returns true if the value is an instance of Error or otherwise false.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * isError(new Error()) // true
10
+ * isError('hello') // false
11
+ * isError({}) // false
12
+ * isError(123) // false
13
+ * isError(null) // false
14
+ * ```
15
+ */
16
+ const isError = (v: unknown): v is Error => v instanceof Error
17
+
18
+ export { isError }
@@ -0,0 +1,17 @@
1
+ import { describe, expect, it } from 'vitest'
2
+
3
+ import { isNil } from './is-nil.js'
4
+
5
+ describe('is nil', () => {
6
+ it('should return true for null and undefined', () => {
7
+ expect(isNil(null)).toBe(true)
8
+ expect(isNil(undefined)).toBe(true)
9
+ })
10
+
11
+ it('should return false for non-nil values', () => {
12
+ expect(isNil(42)).toBe(false)
13
+ expect(isNil('hello')).toBe(false)
14
+ expect(isNil({})).toBe(false)
15
+ expect(isNil([])).toBe(false)
16
+ })
17
+ })
package/src/is-nil.ts ADDED
@@ -0,0 +1,19 @@
1
+ /**
2
+ * isNil checks if a value is null or undefined.
3
+ *
4
+ * @param v value to check.
5
+ * @returns {v is null | undefined} returns true if the value is null or undefined or otherwise false.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * isNil(null) // true
10
+ * isNil(undefined) // true
11
+ * isNil(42) // false
12
+ * isNil('hello') // false
13
+ * isNil({}) // false
14
+ * isNil([]) // false
15
+ * ```
16
+ */
17
+ const isNil = (v: unknown): v is null | undefined => v === null || v === undefined
18
+
19
+ export { isNil }
@@ -0,0 +1,17 @@
1
+ import { describe, expect, it } from 'vitest'
2
+
3
+ import { isObject } from './is-object.js'
4
+
5
+ describe('is object', () => {
6
+ it('should return true for objects', () => {
7
+ expect(isObject({})).toBe(true)
8
+ expect(isObject([])).toBe(true)
9
+ })
10
+
11
+ it('should return false for non-objects', () => {
12
+ expect(isObject('hello')).toBe(false)
13
+ expect(isObject(123)).toBe(false)
14
+ expect(isObject(null)).toBe(false)
15
+ expect(isObject(undefined)).toBe(false)
16
+ })
17
+ })
@@ -0,0 +1,18 @@
1
+ /**
2
+ * isObject checks if the value is an object.
3
+ *
4
+ * @param v value to check.
5
+ * @returns {v is object} returns true if the value is an object or otherwise false.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * isObject({}) // true
10
+ * isObject([]) // true
11
+ * isObject(null) // false
12
+ * isObject('hello') // false
13
+ * isObject(42) // false
14
+ * ```
15
+ */
16
+ const isObject = (v: unknown): v is object => typeof v === 'object' && v !== null
17
+
18
+ export { isObject }
@@ -0,0 +1,18 @@
1
+ import { describe, expect, it } from 'vitest'
2
+
3
+ import { isPlainObject } from './is-plain-object.js'
4
+
5
+ describe('is plain object', () => {
6
+ it('should return true for plain objects', () => {
7
+ expect(isPlainObject({})).toBe(true)
8
+ expect(isPlainObject(Object.create(null))).toBe(true)
9
+ })
10
+
11
+ it('should return false for non-plain objects', () => {
12
+ expect(isPlainObject([])).toBe(false)
13
+ expect(isPlainObject(null)).toBe(false)
14
+ expect(isPlainObject(undefined)).toBe(false)
15
+ expect(isPlainObject('hello')).toBe(false)
16
+ expect(isPlainObject(42)).toBe(false)
17
+ })
18
+ })
@@ -0,0 +1,28 @@
1
+ /**
2
+ * isPlainObject checks if a value is a plain object, that is,
3
+ * an object created by the Object constructor or with a null prototype.
4
+ *
5
+ * @param v value to check.
6
+ * @returns {v is Record<PropertyKey, unknown>} returns true if the value is a plain object or otherwise false.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * isPlainObject({}) // true
11
+ * isPlainObject(Object.create(null)) // true
12
+ * isPlainObject([]) // false
13
+ * isPlainObject(null) // false
14
+ * isPlainObject('hello') // false
15
+ * isPlainObject(42) // false
16
+ * ```
17
+ */
18
+ const isPlainObject = (v: unknown): v is Record<PropertyKey, unknown> => {
19
+ if (typeof v !== 'object' || v === null) {
20
+ return false
21
+ }
22
+
23
+ const proto = Object.getPrototypeOf(v) as unknown
24
+
25
+ return proto === Object.prototype || proto === null
26
+ }
27
+
28
+ export { isPlainObject }
@@ -0,0 +1,23 @@
1
+ import { describe, expect, it } from 'vitest'
2
+
3
+ import { isPrimitive } from './is-primitive.js'
4
+
5
+ describe('is primitive', () => {
6
+ it('should return true for primitives', () => {
7
+ expect(isPrimitive(42)).toBe(true)
8
+ expect(isPrimitive('hello')).toBe(true)
9
+ expect(isPrimitive(true)).toBe(true)
10
+ expect(isPrimitive(null)).toBe(true)
11
+ expect(isPrimitive(undefined)).toBe(true)
12
+ })
13
+
14
+ it('should return false for non-primitives', () => {
15
+ expect(isPrimitive({})).toBe(false)
16
+ expect(isPrimitive([])).toBe(false)
17
+ expect(
18
+ isPrimitive(() => {
19
+ void 0
20
+ }),
21
+ ).toBe(false)
22
+ })
23
+ })
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Primitive type represents the primitive values.
3
+ */
4
+ type Primitive = string | number | boolean | bigint | symbol | null | undefined
5
+
6
+ /**
7
+ * isPrimitive checks if a value is a primitive.
8
+ *
9
+ * @param v value to check.
10
+ * @returns {v is Primitive} returns true if the value is a primitive or otherwise false.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * isPrimitive(42) // true
15
+ * isPrimitive('hello') // true
16
+ * isPrimitive(true) // true
17
+ * isPrimitive(null) // true
18
+ * isPrimitive(undefined) // true
19
+ * isPrimitive({}) // false
20
+ * isPrimitive([]) // false
21
+ * isPrimitive(() => {}) // false
22
+ * ```
23
+ */
24
+ const isPrimitive = (v: unknown): v is Primitive => v === null || (typeof v !== 'object' && typeof v !== 'function')
25
+
26
+ export { isPrimitive }