yummies 7.19.4 → 7.20.1
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/assert.cjs +1 -1
- package/assert.cjs.map +1 -1
- package/assert.js +1 -1
- package/assert.js.map +1 -1
- package/async.cjs +147 -137
- package/async.cjs.map +1 -1
- package/async.d.ts +98 -131
- package/async.js +147 -137
- package/async.js.map +1 -1
- package/common.cjs +3 -1
- package/common.cjs.map +1 -1
- package/common.d.ts +18 -24
- package/common.js +3 -1
- package/common.js.map +1 -1
- package/complex.cjs +1 -0
- package/complex.cjs.map +1 -1
- package/complex.js +1 -0
- package/complex.js.map +1 -1
- package/cookie.cjs +1 -1
- package/cookie.cjs.map +1 -1
- package/cookie.d.ts +0 -18
- package/cookie.js +1 -1
- package/cookie.js.map +1 -1
- package/css-cx.cjs +78 -0
- package/css-cx.cjs.map +1 -0
- package/css-cx.d.ts +69 -0
- package/css-cx.js +74 -0
- package/css-cx.js.map +1 -0
- package/css.cjs +32 -111
- package/css.cjs.map +1 -1
- package/css.d.ts +32 -42
- package/css.js +30 -107
- package/css.js.map +1 -1
- package/data.cjs +60 -50
- package/data.cjs.map +1 -1
- package/data.d.ts +21 -34
- package/data.js +60 -50
- package/data.js.map +1 -1
- package/date-time.cjs +104 -98
- package/date-time.cjs.map +1 -1
- package/date-time.d.ts +51 -57
- package/date-time.js +104 -97
- package/date-time.js.map +1 -1
- package/device.cjs +14 -19
- package/device.cjs.map +1 -1
- package/device.d.ts +15 -26
- package/device.js +14 -19
- package/device.js.map +1 -1
- package/encodings.cjs +1 -1
- package/encodings.cjs.map +1 -1
- package/encodings.d.ts +0 -17
- package/encodings.js +1 -1
- package/encodings.js.map +1 -1
- package/errors.cjs +1 -18
- package/errors.cjs.map +1 -1
- package/errors.d.ts +0 -17
- package/errors.js +1 -17
- package/errors.js.map +1 -1
- package/file.cjs +3 -17
- package/file.cjs.map +1 -1
- package/file.d.ts +1 -16
- package/file.js +3 -17
- package/file.js.map +1 -1
- package/format.cjs +1 -1
- package/format.cjs.map +1 -1
- package/format.js +1 -1
- package/format.js.map +1 -1
- package/html.cjs +112 -175
- package/html.cjs.map +1 -1
- package/html.d.ts +58 -57
- package/html.js +111 -172
- package/html.js.map +1 -1
- package/id-nanoid.cjs +36 -0
- package/id-nanoid.cjs.map +1 -0
- package/id-nanoid.d.ts +26 -0
- package/id-nanoid.js +32 -0
- package/id-nanoid.js.map +1 -0
- package/id.cjs +10 -45
- package/id.cjs.map +1 -1
- package/id.d.ts +27 -36
- package/id.js +6 -40
- package/id.js.map +1 -1
- package/imports.cjs +3 -18
- package/imports.cjs.map +1 -1
- package/imports.d.ts +1 -16
- package/imports.js +3 -17
- package/imports.js.map +1 -1
- package/math.cjs +16 -12
- package/math.cjs.map +1 -1
- package/math.d.ts +9 -24
- package/math.js +16 -12
- package/math.js.map +1 -1
- package/media.cjs +88 -89
- package/media.cjs.map +1 -1
- package/media.d.ts +72 -80
- package/media.js +88 -88
- package/media.js.map +1 -1
- package/mobx.cjs +0 -1
- package/mobx.cjs.map +1 -1
- package/mobx.js.map +1 -1
- package/ms.cjs +3 -17
- package/ms.cjs.map +1 -1
- package/ms.d.ts +1 -16
- package/ms.js +3 -17
- package/ms.js.map +1 -1
- package/number.cjs +1 -17
- package/number.cjs.map +1 -1
- package/number.d.ts +0 -16
- package/number.js +1 -17
- package/number.js.map +1 -1
- package/package.json +6 -6
- package/parser.cjs +1 -1
- package/parser.cjs.map +1 -1
- package/parser.js +1 -1
- package/parser.js.map +1 -1
- package/price.cjs +1 -1
- package/price.cjs.map +1 -1
- package/price.d.ts +0 -16
- package/price.js +1 -1
- package/price.js.map +1 -1
- package/random.cjs +37 -39
- package/random.cjs.map +1 -1
- package/random.d.ts +31 -40
- package/random.js +37 -39
- package/random.js.map +1 -1
- package/react.cjs +0 -1
- package/react.cjs.map +1 -1
- package/react.js.map +1 -1
- package/sanitize-html.cjs +82 -0
- package/sanitize-html.cjs.map +1 -0
- package/sanitize-html.d.ts +28 -0
- package/sanitize-html.js +79 -0
- package/sanitize-html.js.map +1 -0
- package/sound.cjs +1 -17
- package/sound.cjs.map +1 -1
- package/sound.d.ts +0 -16
- package/sound.js +1 -17
- package/sound.js.map +1 -1
- package/storage.cjs +7 -5
- package/storage.cjs.map +1 -1
- package/storage.d.ts +3 -17
- package/storage.js +7 -5
- package/storage.js.map +1 -1
- package/text.cjs +3 -17
- package/text.cjs.map +1 -1
- package/text.d.ts +1 -16
- package/text.js +3 -17
- package/text.js.map +1 -1
- package/type-guard.cjs +38 -1
- package/type-guard.cjs.map +1 -1
- package/type-guard.d.ts +38 -0
- package/type-guard.js +38 -1
- package/type-guard.js.map +1 -1
- package/types.d.ts +20 -1
- package/types.global.d.ts +19 -0
- package/vibrate.cjs +1 -17
- package/vibrate.cjs.map +1 -1
- package/vibrate.d.ts +0 -16
- package/vibrate.js +1 -17
- package/vibrate.js.map +1 -1
- /package/{chunk-pbuEa-1d.js → chunk-D7D4PA-g.js} +0 -0
- /package/{chunk-CZWwpsFl.cjs → chunk-DakpK96I.cjs} +0 -0
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 {\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,MAAM;AAG9D,KAAI,qBAAqB,KAAK,QAAQ;AACpC,MAAI,OAAO,MAAM,MAAgB,CAC/B,QAAO,KAAK;AAEd,MAAI,CAAC,OAAO,SAAS,MAAgB,CACnC,QAAO,KAAK;;AAIhB,QAAO;;AAGT,IAAM,mBACA,GAAG,WACN,UACC,MAAM,SAAS,QAAQ,MAAM,CAAC;;;;;;;;;;;;;;;;;;AAmBlC,IAAa,aAAgB,UAC3B,SAAS;;;;;;;;;;;;;;;;;AAkBX,IAAa,YAAe,UAC1B,CAAC,CAAC;;;;;;;;;;;;;;;;;AAkBJ,IAAa,WAAc,UACzB,CAAC;;;;;;;;;;;;;;;;;AAkBH,IAAa,SAAS,gBAAsB,KAAK,KAAK;;;;;;;;;;;;;;;;;AAkBtD,IAAa,cAAc,gBAA2B,KAAK,UAAU;;;;;;;;;;;;;;;;;AAkBrE,IAAa,WAAW,gBAA2B,KAAK,OAAO;;;;;;;;;;;;;;;;;AAkB/D,IAAa,UAAU,gBAA2B,KAAK,MAAM;;;;;;;;;;;;;;;;;AAkB7D,IAAa,WAAW,gBAAwB,KAAK,OAAO;;;;;;;;;;;;;;;;;;;AAoB5D,IAAa,WAAW,gBAAwB,KAAK,OAAO;;;;;;;;;;;;;;;;;AAkB5D,IAAa,YAAY,gBAAyB,KAAK,QAAQ;;;;;;;;;;;;;;;;;AAkB/D,IAAa,aAAa,gBACxB,KAAK,UACL,KAAK,cACN;;;;;;;;;;;;;;;;;AAkBD,IAAa,WAAW,gBAAwB,KAAK,OAAO;;;;;;;;;;;;;;;;;AAkB5D,IAAa,YAAY,gBAA6B,KAAK,QAAQ;;;;;;;;;;;;;;;;;AAkBnE,IAAa,QAAQ,gBAAwB,KAAK,IAAI;;;;;;;;;;;;;;;;;AAoBtD,IAAa,aAAa,gBAAwB,KAAK,SAAS;;;;;;;;;;;;;;;;;AAoBhE,IAAa,WAAW,gBAAwB,KAAK,OAAO"}
|
|
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 object-like: non-null and `typeof value === 'object'`.\n *\n * This includes plain objects, arrays, `Date`, `RegExp`, boxed primitives, and other built-ins\n * whose `typeof` is `\"object\"`. It is broader than `isObject`, which only matches plain objects.\n *\n * @template T Input value type.\n * @param value Value to test.\n * @returns `true` when the value is a non-null object.\n *\n * @example\n * ```ts\n * isObjectLike({ a: 1 }); // true\n * ```\n *\n * @example\n * ```ts\n * isObjectLike([]); // true\n * ```\n *\n * @example\n * ```ts\n * isObjectLike(new Date()); // true\n * ```\n *\n * @example\n * ```ts\n * isObjectLike(null); // false\n * ```\n *\n * @example\n * ```ts\n * isObjectLike(() => {}); // false\n * ```\n */\nexport const isObjectLike = <T = never>(\n value: unknown,\n): value is T extends never ? Extract<typeof value, object> : T =>\n typeof value === 'object' && !!value;\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;AACX;AAIA,SAAS,QAAQ,OAAsB;CACrC,IAAI,UAAU,KAAA,GACZ,OAAO,KAAK;CAEd,IAAI,UAAU,MACZ,OAAO,KAAK;CAKd,IAAI,UAAU,MAAM,aAAa,KAAK,MAAM,aAAa,IACvD,OAAO,KAAK;CAGd,MAAM,mBAAmB,OAAO,UAAU,SAAS,KAAK,KAAK;CAG7D,IAAI,qBAAqB,KAAK,QAAQ;EACpC,IAAI,OAAO,MAAM,KAAe,GAC9B,OAAO,KAAK;EAEd,IAAI,CAAC,OAAO,SAAS,KAAe,GAClC,OAAO,KAAK;CAEhB;CAEA,OAAO;AACT;AAEA,IAAM,mBACA,GAAG,WACN,UACC,MAAM,SAAS,QAAQ,KAAK,CAAC;;;;;;;;;;;;;;;;;;AAmBjC,IAAa,aAAgB,UAC3B,SAAS;;;;;;;;;;;;;;;;;AAkBX,IAAa,YAAe,UAC1B,CAAC,CAAC;;;;;;;;;;;;;;;;;AAkBJ,IAAa,WAAc,UACzB,CAAC;;;;;;;;;;;;;;;;;AAkBH,IAAa,SAAS,gBAAsB,KAAK,IAAI;;;;;;;;;;;;;;;;;AAkBrD,IAAa,cAAc,gBAA2B,KAAK,SAAS;;;;;;;;;;;;;;;;;AAkBpE,IAAa,WAAW,gBAA2B,KAAK,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqC9D,IAAa,gBACX,UAEA,OAAO,UAAU,YAAY,CAAC,CAAC;;;;;;;;;;;;;;;;;AAkBjC,IAAa,UAAU,gBAA2B,KAAK,KAAK;;;;;;;;;;;;;;;;;AAkB5D,IAAa,WAAW,gBAAwB,KAAK,MAAM;;;;;;;;;;;;;;;;;;;AAoB3D,IAAa,WAAW,gBAAwB,KAAK,MAAM;;;;;;;;;;;;;;;;;AAkB3D,IAAa,YAAY,gBAAyB,KAAK,OAAO;;;;;;;;;;;;;;;;;AAkB9D,IAAa,aAAa,gBACxB,KAAK,UACL,KAAK,aACP;;;;;;;;;;;;;;;;;AAkBA,IAAa,WAAW,gBAAwB,KAAK,MAAM;;;;;;;;;;;;;;;;;AAkB3D,IAAa,YAAY,gBAA6B,KAAK,OAAO;;;;;;;;;;;;;;;;;AAkBlE,IAAa,QAAQ,gBAAwB,KAAK,GAAG;;;;;;;;;;;;;;;;;AAoBrD,IAAa,aAAa,gBAAwB,KAAK,QAAQ;;;;;;;;;;;;;;;;;AAoB/D,IAAa,WAAW,gBAAwB,KAAK,MAAM"}
|
package/types.d.ts
CHANGED
|
@@ -199,6 +199,16 @@ type MaybeKeys<T, TMaybeKeys extends keyof T> = {
|
|
|
199
199
|
* @returns A type with specified keys required and others optional
|
|
200
200
|
*/
|
|
201
201
|
type RequiredKeys<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
202
|
+
/**
|
|
203
|
+
* Applies {@link Defined} to the value types of specified keys while keeping the rest unchanged.
|
|
204
|
+
*
|
|
205
|
+
* @template T - The original type
|
|
206
|
+
* @template K - The keys whose value types should exclude `undefined`
|
|
207
|
+
* @returns A type with specified keys excluding `undefined` from their values and others unchanged
|
|
208
|
+
*/
|
|
209
|
+
type DefinedKeys<T, K extends keyof T> = Omit<T, K> & {
|
|
210
|
+
[Key in K]: Defined<T[K]>;
|
|
211
|
+
};
|
|
202
212
|
/**
|
|
203
213
|
* Extracts the inner type from a Promise type.
|
|
204
214
|
*
|
|
@@ -495,5 +505,14 @@ type AnyBoolean = boolean & {};
|
|
|
495
505
|
* and leave the rest of the string unchanged.
|
|
496
506
|
*/
|
|
497
507
|
type UpperFirst<S extends string> = S extends `${infer F}${infer R}` ? `${Uppercase<F>}${R}` : S;
|
|
508
|
+
type RequiredPropertyIfNeeded<TPropertyName extends string, TPropertyValue> = TPropertyValue extends undefined ? {
|
|
509
|
+
[P in TPropertyName]?: TPropertyValue;
|
|
510
|
+
} : TPropertyValue extends AnyObject ? IsPartial<TPropertyValue> extends true ? {
|
|
511
|
+
[P in TPropertyName]?: TPropertyValue;
|
|
512
|
+
} : {
|
|
513
|
+
[P in TPropertyName]: TPropertyValue;
|
|
514
|
+
} : {
|
|
515
|
+
[P in TPropertyName]: TPropertyValue;
|
|
516
|
+
};
|
|
498
517
|
|
|
499
|
-
export type { AllPropertiesOptional, AnyBoolean, AnyFunction, AnyNumber, AnyObject, AnyPrimitive, AnyString, BrowserNativeObject, Class, CopyObject, DeepPartial, Defined, Dict, EmptyObject, ExtractEnumKeys, ExtractEnumValues, ExtractObjects, FalsyValues, Fn, HasKey, HasSpecificKey, IfEquals, IndexKeys, IsAny, IsArray, IsEmptyArray, IsFunction, IsObject, IsObjectEmpty, IsPartial, IsUnknown, KeyOfByValue, LiteralUnion, Maybe, MaybeArray, MaybeFalsy, MaybeFn, MaybeKeys, MaybePromise, MaybeValues, NonReadonly, NonUndefined, NotMaybe, NotNullable, Nullable, OmitByValue, OverrideKey, Params, PartialIf, PartialKeys, PickByValue, Primitive, ReadonlyKeys, RecordEntries, RenameKey, RequiredKeys, UnionToIntersection, Unpromise, UpperFirst, ValueOf, WithRequired, WritableKeys };
|
|
518
|
+
export type { AllPropertiesOptional, AnyBoolean, AnyFunction, AnyNumber, AnyObject, AnyPrimitive, AnyString, BrowserNativeObject, Class, CopyObject, DeepPartial, Defined, DefinedKeys, Dict, EmptyObject, ExtractEnumKeys, ExtractEnumValues, ExtractObjects, FalsyValues, Fn, HasKey, HasSpecificKey, IfEquals, IndexKeys, IsAny, IsArray, IsEmptyArray, IsFunction, IsObject, IsObjectEmpty, IsPartial, IsUnknown, KeyOfByValue, LiteralUnion, Maybe, MaybeArray, MaybeFalsy, MaybeFn, MaybeKeys, MaybePromise, MaybeValues, NonReadonly, NonUndefined, NotMaybe, NotNullable, Nullable, OmitByValue, OverrideKey, Params, PartialIf, PartialKeys, PickByValue, Primitive, ReadonlyKeys, RecordEntries, RenameKey, RequiredKeys, RequiredPropertyIfNeeded, UnionToIntersection, Unpromise, UpperFirst, ValueOf, WithRequired, WritableKeys };
|
package/types.global.d.ts
CHANGED
|
@@ -200,6 +200,16 @@ type MaybeKeys<T, TMaybeKeys extends keyof T> = {
|
|
|
200
200
|
* @returns A type with specified keys required and others optional
|
|
201
201
|
*/
|
|
202
202
|
type RequiredKeys<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
203
|
+
/**
|
|
204
|
+
* Applies {@link Defined} to the value types of specified keys while keeping the rest unchanged.
|
|
205
|
+
*
|
|
206
|
+
* @template T - The original type
|
|
207
|
+
* @template K - The keys whose value types should exclude `undefined`
|
|
208
|
+
* @returns A type with specified keys excluding `undefined` from their values and others unchanged
|
|
209
|
+
*/
|
|
210
|
+
type DefinedKeys<T, K extends keyof T> = Omit<T, K> & {
|
|
211
|
+
[Key in K]: Defined<T[K]>;
|
|
212
|
+
};
|
|
203
213
|
/**
|
|
204
214
|
* Extracts the inner type from a Promise type.
|
|
205
215
|
*
|
|
@@ -496,4 +506,13 @@ type AnyBoolean = boolean & {};
|
|
|
496
506
|
* and leave the rest of the string unchanged.
|
|
497
507
|
*/
|
|
498
508
|
type UpperFirst<S extends string> = S extends `${infer F}${infer R}` ? `${Uppercase<F>}${R}` : S;
|
|
509
|
+
type RequiredPropertyIfNeeded<TPropertyName extends string, TPropertyValue> = TPropertyValue extends undefined ? {
|
|
510
|
+
[P in TPropertyName]?: TPropertyValue;
|
|
511
|
+
} : TPropertyValue extends AnyObject ? IsPartial<TPropertyValue> extends true ? {
|
|
512
|
+
[P in TPropertyName]?: TPropertyValue;
|
|
513
|
+
} : {
|
|
514
|
+
[P in TPropertyName]: TPropertyValue;
|
|
515
|
+
} : {
|
|
516
|
+
[P in TPropertyName]: TPropertyValue;
|
|
517
|
+
};
|
|
499
518
|
|
package/vibrate.cjs
CHANGED
|
@@ -1,21 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
//#region src/vibrate.ts
|
|
3
|
-
/**
|
|
4
|
-
* ---header-docs-section---
|
|
5
|
-
* # yummies/vibrate
|
|
6
|
-
*
|
|
7
|
-
* ## Description
|
|
8
|
-
*
|
|
9
|
-
* Thin wrapper around **`navigator.vibrate`** for mobile-style haptics: single pulses or patterned
|
|
10
|
-
* on/off sequences. It no-ops when the API is missing or disabled, so UI code stays simple. Do not
|
|
11
|
-
* rely on vibration for critical feedback because iOS and many desktops omit the API entirely.
|
|
12
|
-
*
|
|
13
|
-
* ## Usage
|
|
14
|
-
*
|
|
15
|
-
* ```ts
|
|
16
|
-
* import { vibrate } from "yummies/vibrate";
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
2
|
+
//#region src/vibrate/vibrate.ts
|
|
19
3
|
/**
|
|
20
4
|
* Triggers haptic feedback via the {@link https://developer.mozilla.org/en-US/docs/Web/API/Vibration_API | Vibration API}
|
|
21
5
|
* when `navigator.vibrate` exists (common on Android Chrome; often missing on iOS Safari / desktop).
|
package/vibrate.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vibrate.cjs","names":[],"sources":["../src/vibrate.ts"],"sourcesContent":["/**\n *
|
|
1
|
+
{"version":3,"file":"vibrate.cjs","names":[],"sources":["../src/vibrate/vibrate.ts"],"sourcesContent":["/**\n * Triggers haptic feedback via the {@link https://developer.mozilla.org/en-US/docs/Web/API/Vibration_API | Vibration API}\n * when `navigator.vibrate` exists (common on Android Chrome; often missing on iOS Safari / desktop).\n *\n * - **Single number** — vibrate for that many milliseconds, then stop.\n * - **Array of numbers** — alternating vibration and pause lengths in ms: `[vibrate, pause, vibrate, ...]`.\n * Per the spec, values are clamped; odd-length arrays imply a trailing vibrate segment.\n *\n * If the API is unavailable or the user has disabled vibration, this function **does nothing**\n * (no throw). Call sites should not rely on vibration for critical UX.\n *\n * @param pattern - Duration in ms, or a pattern array as described above.\n *\n * @example\n * Short confirmation buzz (200 ms):\n * ```ts\n * vibrate(200);\n * ```\n *\n * @example\n * Double-pulse pattern: 100 ms on, 50 ms off, 100 ms on:\n * ```ts\n * vibrate([100, 50, 100]);\n * ```\n */\nexport const vibrate = (pattern: number | number[]) => {\n if ('vibrate' in navigator) {\n navigator.vibrate(pattern);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,IAAa,WAAW,YAA+B;CACrD,IAAI,aAAa,WACf,UAAU,QAAQ,OAAO;AAE7B"}
|
package/vibrate.d.ts
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ---header-docs-section---
|
|
3
|
-
* # yummies/vibrate
|
|
4
|
-
*
|
|
5
|
-
* ## Description
|
|
6
|
-
*
|
|
7
|
-
* Thin wrapper around **`navigator.vibrate`** for mobile-style haptics: single pulses or patterned
|
|
8
|
-
* on/off sequences. It no-ops when the API is missing or disabled, so UI code stays simple. Do not
|
|
9
|
-
* rely on vibration for critical feedback because iOS and many desktops omit the API entirely.
|
|
10
|
-
*
|
|
11
|
-
* ## Usage
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* import { vibrate } from "yummies/vibrate";
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
1
|
/**
|
|
18
2
|
* Triggers haptic feedback via the {@link https://developer.mozilla.org/en-US/docs/Web/API/Vibration_API | Vibration API}
|
|
19
3
|
* when `navigator.vibrate` exists (common on Android Chrome; often missing on iOS Safari / desktop).
|
package/vibrate.js
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
//#region src/vibrate.ts
|
|
2
|
-
/**
|
|
3
|
-
* ---header-docs-section---
|
|
4
|
-
* # yummies/vibrate
|
|
5
|
-
*
|
|
6
|
-
* ## Description
|
|
7
|
-
*
|
|
8
|
-
* Thin wrapper around **`navigator.vibrate`** for mobile-style haptics: single pulses or patterned
|
|
9
|
-
* on/off sequences. It no-ops when the API is missing or disabled, so UI code stays simple. Do not
|
|
10
|
-
* rely on vibration for critical feedback because iOS and many desktops omit the API entirely.
|
|
11
|
-
*
|
|
12
|
-
* ## Usage
|
|
13
|
-
*
|
|
14
|
-
* ```ts
|
|
15
|
-
* import { vibrate } from "yummies/vibrate";
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
1
|
+
//#region src/vibrate/vibrate.ts
|
|
18
2
|
/**
|
|
19
3
|
* Triggers haptic feedback via the {@link https://developer.mozilla.org/en-US/docs/Web/API/Vibration_API | Vibration API}
|
|
20
4
|
* when `navigator.vibrate` exists (common on Android Chrome; often missing on iOS Safari / desktop).
|
package/vibrate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vibrate.js","names":[],"sources":["../src/vibrate.ts"],"sourcesContent":["/**\n *
|
|
1
|
+
{"version":3,"file":"vibrate.js","names":[],"sources":["../src/vibrate/vibrate.ts"],"sourcesContent":["/**\n * Triggers haptic feedback via the {@link https://developer.mozilla.org/en-US/docs/Web/API/Vibration_API | Vibration API}\n * when `navigator.vibrate` exists (common on Android Chrome; often missing on iOS Safari / desktop).\n *\n * - **Single number** — vibrate for that many milliseconds, then stop.\n * - **Array of numbers** — alternating vibration and pause lengths in ms: `[vibrate, pause, vibrate, ...]`.\n * Per the spec, values are clamped; odd-length arrays imply a trailing vibrate segment.\n *\n * If the API is unavailable or the user has disabled vibration, this function **does nothing**\n * (no throw). Call sites should not rely on vibration for critical UX.\n *\n * @param pattern - Duration in ms, or a pattern array as described above.\n *\n * @example\n * Short confirmation buzz (200 ms):\n * ```ts\n * vibrate(200);\n * ```\n *\n * @example\n * Double-pulse pattern: 100 ms on, 50 ms off, 100 ms on:\n * ```ts\n * vibrate([100, 50, 100]);\n * ```\n */\nexport const vibrate = (pattern: number | number[]) => {\n if ('vibrate' in navigator) {\n navigator.vibrate(pattern);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,IAAa,WAAW,YAA+B;CACrD,IAAI,aAAa,WACf,UAAU,QAAQ,OAAO;AAE7B"}
|
|
File without changes
|
|
File without changes
|