yummies 7.14.1 → 7.14.2
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/package.json +1 -1
- package/type-guard.cjs +5 -7
- package/type-guard.cjs.map +1 -1
- package/type-guard.d.ts +7 -9
- package/type-guard.js +5 -7
- package/type-guard.js.map +1 -1
- package/types.d.ts +3 -2
- package/types.global.d.ts +3 -2
package/package.json
CHANGED
package/type-guard.cjs
CHANGED
|
@@ -65,10 +65,10 @@ var createTypeGuard = (...types) => (value) => types.includes(getType(value));
|
|
|
65
65
|
*/
|
|
66
66
|
var isDefined = (value) => value != null;
|
|
67
67
|
/**
|
|
68
|
-
* Checks whether a value is truthy (
|
|
68
|
+
* Checks whether a value is truthy (`!!value`).
|
|
69
69
|
*
|
|
70
70
|
* @param value Value to test.
|
|
71
|
-
* @returns `true` when
|
|
71
|
+
* @returns `true` when `!!value` is true.
|
|
72
72
|
*
|
|
73
73
|
* @example
|
|
74
74
|
* ```ts
|
|
@@ -80,14 +80,12 @@ var isDefined = (value) => value != null;
|
|
|
80
80
|
* isTruthy(0); // false
|
|
81
81
|
* ```
|
|
82
82
|
*/
|
|
83
|
-
var isTruthy = (value) =>
|
|
83
|
+
var isTruthy = (value) => !!value;
|
|
84
84
|
/**
|
|
85
|
-
* Checks whether a value is falsy (
|
|
86
|
-
*
|
|
87
|
-
* Includes `false`, `0`, `-0`, `NaN`, `""`, `null`, `undefined`, and `0n`.
|
|
85
|
+
* Checks whether a value is falsy (`!Boolean(value)`).
|
|
88
86
|
*
|
|
89
87
|
* @param value Value to test.
|
|
90
|
-
* @returns `true` when
|
|
88
|
+
* @returns `true` when `Boolean(value)` is false.
|
|
91
89
|
*
|
|
92
90
|
* @example
|
|
93
91
|
* ```ts
|
package/type-guard.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-guard.cjs","names":[],"sources":["../src/type-guard/_exports.ts"],"sourcesContent":["/**\n * ---header-docs-section---\n * # yummies/type-guard\n *\n * ## Description\n *\n * Runtime **type guards** and narrowers for primitives, DOM nodes, `NaN`, and common app values.\n * Each helper is implemented once with consistent `typeof` / `Object.prototype.toString` logic so\n * `unknown` from JSON, events, or third-party scripts becomes safe typed branches without ad-hoc\n * checks scattered through the codebase.\n *\n * ## Usage\n *\n * ```ts\n * import { typeGuard } from \"yummies/type-guard\";\n * ```\n */\n\nimport type {
|
|
1
|
+
{"version":3,"file":"type-guard.cjs","names":[],"sources":["../src/type-guard/_exports.ts"],"sourcesContent":["/**\n * ---header-docs-section---\n * # yummies/type-guard\n *\n * ## Description\n *\n * Runtime **type guards** and narrowers for primitives, DOM nodes, `NaN`, and common app values.\n * Each helper is implemented once with consistent `typeof` / `Object.prototype.toString` logic so\n * `unknown` from JSON, events, or third-party scripts becomes safe typed branches without ad-hoc\n * checks scattered through the codebase.\n *\n * ## Usage\n *\n * ```ts\n * import { typeGuard } from \"yummies/type-guard\";\n * ```\n */\n\nimport type {\n AnyFunction,\n AnyObject,\n FalsyValues,\n ValueOf,\n} from 'yummies/types';\n\nconst TYPE = {\n Null: 'null',\n Undefined: 'undefined',\n NaN: 'nan',\n Object: '[object Object]',\n Array: '[object Array]',\n String: '[object String]',\n Number: '[object Number]',\n Boolean: '[object Boolean]',\n Function: '[object Function]',\n AsyncFunction: '[object AsyncFunction]',\n RegExp: '[object RegExp]',\n Symbol: '[object Symbol]',\n Infinite: 'infinite',\n Element: 'element',\n};\n\ntype Type = ValueOf<typeof TYPE>;\n\nfunction getType(value: unknown): Type {\n if (value === undefined) {\n return TYPE.Undefined;\n }\n if (value === null) {\n return TYPE.Null;\n }\n\n // handle DOM elements\n // @ts-expect-error\n if (value && (value.nodeType === 1 || value.nodeType === 9)) {\n return TYPE.Element;\n }\n\n const stringifiedValue = Object.prototype.toString.call(value);\n\n // handle NaN and Infinity\n if (stringifiedValue === TYPE.Number) {\n if (Number.isNaN(value as number)) {\n return TYPE.NaN;\n }\n if (!Number.isFinite(value as number)) {\n return TYPE.Infinite;\n }\n }\n\n return stringifiedValue as Type;\n}\n\nconst createTypeGuard =\n <T>(...types: Type[]) =>\n (value: unknown): value is T =>\n types.includes(getType(value));\n\n/**\n * Checks that a value is neither `null` nor `undefined`.\n *\n * @template T Value type without nullish branches.\n * @param value Value to test.\n * @returns `true` when the value is defined.\n *\n * @example\n * ```ts\n * isDefined(0); // true\n * ```\n *\n * @example\n * ```ts\n * isDefined(null); // false\n * ```\n */\nexport const isDefined = <T>(value: T | undefined | null): value is T =>\n value != null;\n\n/**\n * Checks whether a value is truthy (`!!value`).\n *\n * @param value Value to test.\n * @returns `true` when `!!value` is true.\n *\n * @example\n * ```ts\n * isTruthy(1); // true\n * ```\n *\n * @example\n * ```ts\n * isTruthy(0); // false\n * ```\n */\nexport const isTruthy = <T>(value: T): value is Exclude<T, FalsyValues> =>\n !!value;\n\n/**\n * Checks whether a value is falsy (`!Boolean(value)`).\n *\n * @param value Value to test.\n * @returns `true` when `Boolean(value)` is false.\n *\n * @example\n * ```ts\n * isFalsy(null); // true\n * ```\n *\n * @example\n * ```ts\n * isFalsy(\"x\"); // false\n * ```\n */\nexport const isFalsy = <T>(value: T): value is Extract<T, FalsyValues> =>\n !value;\n\n/**\n * Checks whether a value is exactly `null`.\n *\n * @param value Value to test.\n * @returns `true` when the value is `null`.\n *\n * @example\n * ```ts\n * isNull(null); // true\n * ```\n *\n * @example\n * ```ts\n * isNull(undefined); // false\n * ```\n */\nexport const isNull = createTypeGuard<null>(TYPE.Null);\n\n/**\n * Checks whether a value is exactly `undefined`.\n *\n * @param value Value to test.\n * @returns `true` when the value is `undefined`.\n *\n * @example\n * ```ts\n * isUndefined(undefined); // true\n * ```\n *\n * @example\n * ```ts\n * isUndefined('value'); // false\n * ```\n */\nexport const isUndefined = createTypeGuard<undefined>(TYPE.Undefined);\n\n/**\n * Checks whether a value is a plain object.\n *\n * @param value Value to test.\n * @returns `true` when the value matches `[object Object]`.\n *\n * @example\n * ```ts\n * isObject({ id: 1 }); // true\n * ```\n *\n * @example\n * ```ts\n * isObject([]); // false\n * ```\n */\nexport const isObject = createTypeGuard<AnyObject>(TYPE.Object);\n\n/**\n * Checks whether a value is an array.\n *\n * @param value Value to test.\n * @returns `true` when the value is an array.\n *\n * @example\n * ```ts\n * isArray([1, 2, 3]); // true\n * ```\n *\n * @example\n * ```ts\n * isArray({ length: 1 }); // false\n * ```\n */\nexport const isArray = createTypeGuard<unknown[]>(TYPE.Array);\n\n/**\n * Checks whether a value is a string object or primitive string.\n *\n * @param value Value to test.\n * @returns `true` when the value is a string.\n *\n * @example\n * ```ts\n * isString('hello'); // true\n * ```\n *\n * @example\n * ```ts\n * isString(123); // false\n * ```\n */\nexport const isString = createTypeGuard<string>(TYPE.String);\n\n/**\n * Checks whether a value is a finite number.\n *\n * Unlike `isNaN` and `isInfinite`, this guard only matches regular numeric values.\n *\n * @param value Value to test.\n * @returns `true` when the value is a non-NaN finite number.\n *\n * @example\n * ```ts\n * isNumber(123); // true\n * ```\n *\n * @example\n * ```ts\n * isNumber(Number.NaN); // false\n * ```\n */\nexport const isNumber = createTypeGuard<number>(TYPE.Number);\n\n/**\n * Checks whether a value is a boolean.\n *\n * @param value Value to test.\n * @returns `true` when the value is a boolean.\n *\n * @example\n * ```ts\n * isBoolean(true); // true\n * ```\n *\n * @example\n * ```ts\n * isBoolean('true'); // false\n * ```\n */\nexport const isBoolean = createTypeGuard<boolean>(TYPE.Boolean);\n\n/**\n * Checks whether a value is a synchronous or asynchronous function.\n *\n * @param value Value to test.\n * @returns `true` when the value is a function.\n *\n * @example\n * ```ts\n * isFunction(() => {}); // true\n * ```\n *\n * @example\n * ```ts\n * isFunction(async () => {}); // true\n * ```\n */\nexport const isFunction = createTypeGuard<AnyFunction>(\n TYPE.Function,\n TYPE.AsyncFunction,\n);\n\n/**\n * Checks whether a value is a regular expression.\n *\n * @param value Value to test.\n * @returns `true` when the value is a `RegExp`.\n *\n * @example\n * ```ts\n * isRegExp(/foo/); // true\n * ```\n *\n * @example\n * ```ts\n * isRegExp('foo'); // false\n * ```\n */\nexport const isRegExp = createTypeGuard<RegExp>(TYPE.RegExp);\n\n/**\n * Checks whether a value looks like a DOM element or document node.\n *\n * @param value Value to test.\n * @returns `true` when the value has an element-like node type.\n *\n * @example\n * ```ts\n * isElement(document.body); // true\n * ```\n *\n * @example\n * ```ts\n * isElement({ nodeType: 3 }); // false\n * ```\n */\nexport const isElement = createTypeGuard<HTMLElement>(TYPE.Element);\n\n/**\n * Checks whether a value is `NaN`.\n *\n * @param value Value to test.\n * @returns `true` when the value is `NaN`.\n *\n * @example\n * ```ts\n * isNaN(Number.NaN); // true\n * ```\n *\n * @example\n * ```ts\n * isNaN(5); // false\n * ```\n */\nexport const isNaN = createTypeGuard<number>(TYPE.NaN) as (\n value: unknown,\n) => boolean;\n\n/**\n * Checks whether a value is positive or negative infinity.\n *\n * @param value Value to test.\n * @returns `true` when the value is not finite.\n *\n * @example\n * ```ts\n * isInfinite(Infinity); // true\n * ```\n *\n * @example\n * ```ts\n * isInfinite(10); // false\n * ```\n */\nexport const isInfinite = createTypeGuard<number>(TYPE.Infinite) as (\n value: unknown,\n) => boolean;\n\n/**\n * Checks whether a value is a symbol.\n *\n * @param value Value to test.\n * @returns `true` when the value is a symbol.\n *\n * @example\n * ```ts\n * isSymbol(Symbol('id')); // true\n * ```\n *\n * @example\n * ```ts\n * isSymbol('id'); // false\n * ```\n */\nexport const isSymbol = createTypeGuard<symbol>(TYPE.Symbol);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAyBA,IAAM,OAAO;CACX,MAAM;CACN,WAAW;CACX,KAAK;CACL,QAAQ;CACR,OAAO;CACP,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,UAAU;CACV,eAAe;CACf,QAAQ;CACR,QAAQ;CACR,UAAU;CACV,SAAS;CACV;AAID,SAAS,QAAQ,OAAsB;AACrC,KAAI,UAAU,KAAA,EACZ,QAAO,KAAK;AAEd,KAAI,UAAU,KACZ,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AwB,KAAK,SAAS;;;;;;;;;;;;;;;;;AAoBhE,IAAa,WAAW,gBAAwB,KAAK,OAAO"}
|
package/type-guard.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyFunction, AnyObject } from 'yummies/types';
|
|
1
|
+
import { FalsyValues, AnyFunction, AnyObject } from 'yummies/types';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* ---header-docs-section---
|
|
@@ -37,10 +37,10 @@ import { AnyFunction, AnyObject } from 'yummies/types';
|
|
|
37
37
|
*/
|
|
38
38
|
declare const isDefined: <T>(value: T | undefined | null) => value is T;
|
|
39
39
|
/**
|
|
40
|
-
* Checks whether a value is truthy (
|
|
40
|
+
* Checks whether a value is truthy (`!!value`).
|
|
41
41
|
*
|
|
42
42
|
* @param value Value to test.
|
|
43
|
-
* @returns `true` when
|
|
43
|
+
* @returns `true` when `!!value` is true.
|
|
44
44
|
*
|
|
45
45
|
* @example
|
|
46
46
|
* ```ts
|
|
@@ -52,14 +52,12 @@ declare const isDefined: <T>(value: T | undefined | null) => value is T;
|
|
|
52
52
|
* isTruthy(0); // false
|
|
53
53
|
* ```
|
|
54
54
|
*/
|
|
55
|
-
declare const isTruthy: (value:
|
|
55
|
+
declare const isTruthy: <T>(value: T) => value is Exclude<T, FalsyValues>;
|
|
56
56
|
/**
|
|
57
|
-
* Checks whether a value is falsy (
|
|
58
|
-
*
|
|
59
|
-
* Includes `false`, `0`, `-0`, `NaN`, `""`, `null`, `undefined`, and `0n`.
|
|
57
|
+
* Checks whether a value is falsy (`!Boolean(value)`).
|
|
60
58
|
*
|
|
61
59
|
* @param value Value to test.
|
|
62
|
-
* @returns `true` when
|
|
60
|
+
* @returns `true` when `Boolean(value)` is false.
|
|
63
61
|
*
|
|
64
62
|
* @example
|
|
65
63
|
* ```ts
|
|
@@ -71,7 +69,7 @@ declare const isTruthy: (value: unknown) => boolean;
|
|
|
71
69
|
* isFalsy("x"); // false
|
|
72
70
|
* ```
|
|
73
71
|
*/
|
|
74
|
-
declare const isFalsy: (value:
|
|
72
|
+
declare const isFalsy: <T>(value: T) => value is Extract<T, FalsyValues>;
|
|
75
73
|
/**
|
|
76
74
|
* Checks whether a value is exactly `null`.
|
|
77
75
|
*
|
package/type-guard.js
CHANGED
|
@@ -65,10 +65,10 @@ var createTypeGuard = (...types) => (value) => types.includes(getType(value));
|
|
|
65
65
|
*/
|
|
66
66
|
var isDefined = (value) => value != null;
|
|
67
67
|
/**
|
|
68
|
-
* Checks whether a value is truthy (
|
|
68
|
+
* Checks whether a value is truthy (`!!value`).
|
|
69
69
|
*
|
|
70
70
|
* @param value Value to test.
|
|
71
|
-
* @returns `true` when
|
|
71
|
+
* @returns `true` when `!!value` is true.
|
|
72
72
|
*
|
|
73
73
|
* @example
|
|
74
74
|
* ```ts
|
|
@@ -80,14 +80,12 @@ var isDefined = (value) => value != null;
|
|
|
80
80
|
* isTruthy(0); // false
|
|
81
81
|
* ```
|
|
82
82
|
*/
|
|
83
|
-
var isTruthy = (value) =>
|
|
83
|
+
var isTruthy = (value) => !!value;
|
|
84
84
|
/**
|
|
85
|
-
* Checks whether a value is falsy (
|
|
86
|
-
*
|
|
87
|
-
* Includes `false`, `0`, `-0`, `NaN`, `""`, `null`, `undefined`, and `0n`.
|
|
85
|
+
* Checks whether a value is falsy (`!Boolean(value)`).
|
|
88
86
|
*
|
|
89
87
|
* @param value Value to test.
|
|
90
|
-
* @returns `true` when
|
|
88
|
+
* @returns `true` when `Boolean(value)` is false.
|
|
91
89
|
*
|
|
92
90
|
* @example
|
|
93
91
|
* ```ts
|
package/type-guard.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-guard.js","names":[],"sources":["../src/type-guard/_exports.ts"],"sourcesContent":["/**\n * ---header-docs-section---\n * # yummies/type-guard\n *\n * ## Description\n *\n * Runtime **type guards** and narrowers for primitives, DOM nodes, `NaN`, and common app values.\n * Each helper is implemented once with consistent `typeof` / `Object.prototype.toString` logic so\n * `unknown` from JSON, events, or third-party scripts becomes safe typed branches without ad-hoc\n * checks scattered through the codebase.\n *\n * ## Usage\n *\n * ```ts\n * import { typeGuard } from \"yummies/type-guard\";\n * ```\n */\n\nimport type {
|
|
1
|
+
{"version":3,"file":"type-guard.js","names":[],"sources":["../src/type-guard/_exports.ts"],"sourcesContent":["/**\n * ---header-docs-section---\n * # yummies/type-guard\n *\n * ## Description\n *\n * Runtime **type guards** and narrowers for primitives, DOM nodes, `NaN`, and common app values.\n * Each helper is implemented once with consistent `typeof` / `Object.prototype.toString` logic so\n * `unknown` from JSON, events, or third-party scripts becomes safe typed branches without ad-hoc\n * checks scattered through the codebase.\n *\n * ## Usage\n *\n * ```ts\n * import { typeGuard } from \"yummies/type-guard\";\n * ```\n */\n\nimport type {\n AnyFunction,\n AnyObject,\n FalsyValues,\n ValueOf,\n} from 'yummies/types';\n\nconst TYPE = {\n Null: 'null',\n Undefined: 'undefined',\n NaN: 'nan',\n Object: '[object Object]',\n Array: '[object Array]',\n String: '[object String]',\n Number: '[object Number]',\n Boolean: '[object Boolean]',\n Function: '[object Function]',\n AsyncFunction: '[object AsyncFunction]',\n RegExp: '[object RegExp]',\n Symbol: '[object Symbol]',\n Infinite: 'infinite',\n Element: 'element',\n};\n\ntype Type = ValueOf<typeof TYPE>;\n\nfunction getType(value: unknown): Type {\n if (value === undefined) {\n return TYPE.Undefined;\n }\n if (value === null) {\n return TYPE.Null;\n }\n\n // handle DOM elements\n // @ts-expect-error\n if (value && (value.nodeType === 1 || value.nodeType === 9)) {\n return TYPE.Element;\n }\n\n const stringifiedValue = Object.prototype.toString.call(value);\n\n // handle NaN and Infinity\n if (stringifiedValue === TYPE.Number) {\n if (Number.isNaN(value as number)) {\n return TYPE.NaN;\n }\n if (!Number.isFinite(value as number)) {\n return TYPE.Infinite;\n }\n }\n\n return stringifiedValue as Type;\n}\n\nconst createTypeGuard =\n <T>(...types: Type[]) =>\n (value: unknown): value is T =>\n types.includes(getType(value));\n\n/**\n * Checks that a value is neither `null` nor `undefined`.\n *\n * @template T Value type without nullish branches.\n * @param value Value to test.\n * @returns `true` when the value is defined.\n *\n * @example\n * ```ts\n * isDefined(0); // true\n * ```\n *\n * @example\n * ```ts\n * isDefined(null); // false\n * ```\n */\nexport const isDefined = <T>(value: T | undefined | null): value is T =>\n value != null;\n\n/**\n * Checks whether a value is truthy (`!!value`).\n *\n * @param value Value to test.\n * @returns `true` when `!!value` is true.\n *\n * @example\n * ```ts\n * isTruthy(1); // true\n * ```\n *\n * @example\n * ```ts\n * isTruthy(0); // false\n * ```\n */\nexport const isTruthy = <T>(value: T): value is Exclude<T, FalsyValues> =>\n !!value;\n\n/**\n * Checks whether a value is falsy (`!Boolean(value)`).\n *\n * @param value Value to test.\n * @returns `true` when `Boolean(value)` is false.\n *\n * @example\n * ```ts\n * isFalsy(null); // true\n * ```\n *\n * @example\n * ```ts\n * isFalsy(\"x\"); // false\n * ```\n */\nexport const isFalsy = <T>(value: T): value is Extract<T, FalsyValues> =>\n !value;\n\n/**\n * Checks whether a value is exactly `null`.\n *\n * @param value Value to test.\n * @returns `true` when the value is `null`.\n *\n * @example\n * ```ts\n * isNull(null); // true\n * ```\n *\n * @example\n * ```ts\n * isNull(undefined); // false\n * ```\n */\nexport const isNull = createTypeGuard<null>(TYPE.Null);\n\n/**\n * Checks whether a value is exactly `undefined`.\n *\n * @param value Value to test.\n * @returns `true` when the value is `undefined`.\n *\n * @example\n * ```ts\n * isUndefined(undefined); // true\n * ```\n *\n * @example\n * ```ts\n * isUndefined('value'); // false\n * ```\n */\nexport const isUndefined = createTypeGuard<undefined>(TYPE.Undefined);\n\n/**\n * Checks whether a value is a plain object.\n *\n * @param value Value to test.\n * @returns `true` when the value matches `[object Object]`.\n *\n * @example\n * ```ts\n * isObject({ id: 1 }); // true\n * ```\n *\n * @example\n * ```ts\n * isObject([]); // false\n * ```\n */\nexport const isObject = createTypeGuard<AnyObject>(TYPE.Object);\n\n/**\n * Checks whether a value is an array.\n *\n * @param value Value to test.\n * @returns `true` when the value is an array.\n *\n * @example\n * ```ts\n * isArray([1, 2, 3]); // true\n * ```\n *\n * @example\n * ```ts\n * isArray({ length: 1 }); // false\n * ```\n */\nexport const isArray = createTypeGuard<unknown[]>(TYPE.Array);\n\n/**\n * Checks whether a value is a string object or primitive string.\n *\n * @param value Value to test.\n * @returns `true` when the value is a string.\n *\n * @example\n * ```ts\n * isString('hello'); // true\n * ```\n *\n * @example\n * ```ts\n * isString(123); // false\n * ```\n */\nexport const isString = createTypeGuard<string>(TYPE.String);\n\n/**\n * Checks whether a value is a finite number.\n *\n * Unlike `isNaN` and `isInfinite`, this guard only matches regular numeric values.\n *\n * @param value Value to test.\n * @returns `true` when the value is a non-NaN finite number.\n *\n * @example\n * ```ts\n * isNumber(123); // true\n * ```\n *\n * @example\n * ```ts\n * isNumber(Number.NaN); // false\n * ```\n */\nexport const isNumber = createTypeGuard<number>(TYPE.Number);\n\n/**\n * Checks whether a value is a boolean.\n *\n * @param value Value to test.\n * @returns `true` when the value is a boolean.\n *\n * @example\n * ```ts\n * isBoolean(true); // true\n * ```\n *\n * @example\n * ```ts\n * isBoolean('true'); // false\n * ```\n */\nexport const isBoolean = createTypeGuard<boolean>(TYPE.Boolean);\n\n/**\n * Checks whether a value is a synchronous or asynchronous function.\n *\n * @param value Value to test.\n * @returns `true` when the value is a function.\n *\n * @example\n * ```ts\n * isFunction(() => {}); // true\n * ```\n *\n * @example\n * ```ts\n * isFunction(async () => {}); // true\n * ```\n */\nexport const isFunction = createTypeGuard<AnyFunction>(\n TYPE.Function,\n TYPE.AsyncFunction,\n);\n\n/**\n * Checks whether a value is a regular expression.\n *\n * @param value Value to test.\n * @returns `true` when the value is a `RegExp`.\n *\n * @example\n * ```ts\n * isRegExp(/foo/); // true\n * ```\n *\n * @example\n * ```ts\n * isRegExp('foo'); // false\n * ```\n */\nexport const isRegExp = createTypeGuard<RegExp>(TYPE.RegExp);\n\n/**\n * Checks whether a value looks like a DOM element or document node.\n *\n * @param value Value to test.\n * @returns `true` when the value has an element-like node type.\n *\n * @example\n * ```ts\n * isElement(document.body); // true\n * ```\n *\n * @example\n * ```ts\n * isElement({ nodeType: 3 }); // false\n * ```\n */\nexport const isElement = createTypeGuard<HTMLElement>(TYPE.Element);\n\n/**\n * Checks whether a value is `NaN`.\n *\n * @param value Value to test.\n * @returns `true` when the value is `NaN`.\n *\n * @example\n * ```ts\n * isNaN(Number.NaN); // true\n * ```\n *\n * @example\n * ```ts\n * isNaN(5); // false\n * ```\n */\nexport const isNaN = createTypeGuard<number>(TYPE.NaN) as (\n value: unknown,\n) => boolean;\n\n/**\n * Checks whether a value is positive or negative infinity.\n *\n * @param value Value to test.\n * @returns `true` when the value is not finite.\n *\n * @example\n * ```ts\n * isInfinite(Infinity); // true\n * ```\n *\n * @example\n * ```ts\n * isInfinite(10); // false\n * ```\n */\nexport const isInfinite = createTypeGuard<number>(TYPE.Infinite) as (\n value: unknown,\n) => boolean;\n\n/**\n * Checks whether a value is a symbol.\n *\n * @param value Value to test.\n * @returns `true` when the value is a symbol.\n *\n * @example\n * ```ts\n * isSymbol(Symbol('id')); // true\n * ```\n *\n * @example\n * ```ts\n * isSymbol('id'); // false\n * ```\n */\nexport const isSymbol = createTypeGuard<symbol>(TYPE.Symbol);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAyBA,IAAM,OAAO;CACX,MAAM;CACN,WAAW;CACX,KAAK;CACL,QAAQ;CACR,OAAO;CACP,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,UAAU;CACV,eAAe;CACf,QAAQ;CACR,QAAQ;CACR,UAAU;CACV,SAAS;CACV;AAID,SAAS,QAAQ,OAAsB;AACrC,KAAI,UAAU,KAAA,EACZ,QAAO,KAAK;AAEd,KAAI,UAAU,KACZ,QAAO,KAAK;AAKd,KAAI,UAAU,MAAM,aAAa,KAAK,MAAM,aAAa,GACvD,QAAO,KAAK;CAGd,MAAM,mBAAmB,OAAO,UAAU,SAAS,KAAK,M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nyFunction = (...args: any) => any;
|
|
|
134
134
|
*/
|
|
135
135
|
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
136
136
|
/**
|
|
137
|
-
* Represents falsy values (undefined, null, empty
|
|
137
|
+
* Represents falsy values aligned with `!Boolean(x)` / `typeGuard.isFalsy` (undefined, null, empty
|
|
138
|
+
* string, false, `0`, and `0n`).
|
|
138
139
|
*
|
|
139
140
|
* @returns Union of all falsy values
|
|
140
141
|
*/
|
|
141
|
-
type FalsyValues = undefined | null | '' | false | 0;
|
|
142
|
+
type FalsyValues = undefined | null | '' | false | 0 | 0n;
|
|
142
143
|
/**
|
|
143
144
|
* Represents a type that can be either the specified type, undefined, or any other falsy value.
|
|
144
145
|
*
|
package/types.global.d.ts
CHANGED
|
@@ -135,11 +135,12 @@ type AnyFunction = (...args: any) => any;
|
|
|
135
135
|
*/
|
|
136
136
|
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
137
137
|
/**
|
|
138
|
-
* Represents falsy values (undefined, null, empty
|
|
138
|
+
* Represents falsy values aligned with `!Boolean(x)` / `typeGuard.isFalsy` (undefined, null, empty
|
|
139
|
+
* string, false, `0`, and `0n`).
|
|
139
140
|
*
|
|
140
141
|
* @returns Union of all falsy values
|
|
141
142
|
*/
|
|
142
|
-
type FalsyValues = undefined | null | '' | false | 0;
|
|
143
|
+
type FalsyValues = undefined | null | '' | false | 0 | 0n;
|
|
143
144
|
/**
|
|
144
145
|
* Represents a type that can be either the specified type, undefined, or any other falsy value.
|
|
145
146
|
*
|