yummies 7.10.0 → 7.11.0
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/async.cjs +11 -11
- package/async.cjs.map +1 -1
- package/async.d.ts +9 -11
- package/async.js +11 -11
- package/async.js.map +1 -1
- package/complex.cjs +32 -8
- package/complex.cjs.map +1 -1
- package/complex.d.ts +133 -13
- package/complex.js +32 -8
- package/complex.js.map +1 -1
- package/css.cjs.map +1 -1
- package/css.d.ts +3 -3
- package/css.js.map +1 -1
- package/date-time.cjs.map +1 -1
- package/date-time.js.map +1 -1
- package/format.cjs.map +1 -1
- package/format.d.ts +89 -4
- package/format.js.map +1 -1
- package/html.cjs.map +1 -1
- package/html.d.ts +3 -3
- package/html.js.map +1 -1
- package/id.cjs.map +1 -1
- package/id.d.ts +10 -10
- package/id.js.map +1 -1
- package/imports.cjs.map +1 -1
- package/imports.d.ts +5 -4
- package/imports.js.map +1 -1
- package/math.cjs.map +1 -1
- package/math.d.ts +1 -1
- package/math.js.map +1 -1
- package/media.cjs.map +1 -1
- package/media.d.ts +1 -1
- package/media.js.map +1 -1
- package/mobx.cjs.map +1 -1
- package/mobx.d.ts +165 -6
- package/mobx.js.map +1 -1
- package/ms.cjs.map +1 -1
- package/ms.d.ts +1 -1
- package/ms.js.map +1 -1
- package/package.json +5 -5
- package/parser.cjs.map +1 -1
- package/parser.d.ts +63 -0
- package/parser.js.map +1 -1
- package/react.cjs.map +1 -1
- package/react.d.ts +407 -9
- package/react.js.map +1 -1
- package/sound.cjs.map +1 -1
- package/sound.d.ts +1 -1
- package/sound.js.map +1 -1
- package/storage.cjs.map +1 -1
- package/storage.d.ts +7 -6
- package/storage.js.map +1 -1
- package/text.cjs.map +1 -1
- package/text.d.ts +5 -5
- package/text.js.map +1 -1
- package/type-guard.cjs.map +1 -1
- package/type-guard.d.ts +199 -42
- package/type-guard.js.map +1 -1
- package/vibrate.cjs.map +1 -1
- package/vibrate.d.ts +1 -1
- package/vibrate.js.map +1 -1
package/storage.d.ts
CHANGED
|
@@ -7,23 +7,24 @@ interface UnsetFromStorageConfig extends Omit<GetFromStorageConfig<any>, 'fallba
|
|
|
7
7
|
}
|
|
8
8
|
interface GetFromStorageConfig<V> {
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Storage key used to retrieve the value.
|
|
11
|
+
* The full key is extended with the project namespace.
|
|
11
12
|
*/
|
|
12
13
|
key: string;
|
|
13
14
|
/**
|
|
14
|
-
*
|
|
15
|
+
* Storage type.
|
|
15
16
|
*/
|
|
16
17
|
type: StorageType;
|
|
17
18
|
/**
|
|
18
|
-
*
|
|
19
|
+
* Default value used when there is no value in storage.
|
|
19
20
|
*/
|
|
20
21
|
fallback?: V;
|
|
21
22
|
/**
|
|
22
|
-
*
|
|
23
|
+
* Optional namespace segment used in the generated key.
|
|
23
24
|
*/
|
|
24
25
|
namespace?: string;
|
|
25
26
|
/**
|
|
26
|
-
*
|
|
27
|
+
* Optional key prefix.
|
|
27
28
|
*/
|
|
28
29
|
prefix?: string;
|
|
29
30
|
}
|
|
@@ -37,7 +38,7 @@ interface StorageApi<BaseConfig extends StorageConfigBase> {
|
|
|
37
38
|
get<Value>(config: GetFromStorageWrappedConfig<Value, BaseConfig>): Value | null;
|
|
38
39
|
}
|
|
39
40
|
/**
|
|
40
|
-
*
|
|
41
|
+
* Creates an interface for working with storage (`localStorage`, `sessionStorage`).
|
|
41
42
|
*/
|
|
42
43
|
declare function createStorage<BaseConfig extends StorageConfigBase>(storageConfig: BaseConfig): StorageApi<BaseConfig>;
|
|
43
44
|
|
package/storage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","sources":["../src/storage.ts"],"sourcesContent":["export type StorageType = 'session' | 'local';\n\nconst storages: Record<StorageType, Storage> = {\n session: sessionStorage,\n local: localStorage,\n};\n\nexport const createKey = (prefix: string, key: string, namespace?: string) =>\n `${prefix}${namespace ? `/${namespace}` : ''}/${key}`;\n\nconst parseStorageValue = <V>(value: unknown): V | null => {\n if (typeof value !== 'string') {\n return value as V;\n }\n\n try {\n const parsed = JSON.parse(value);\n return parsed;\n } catch {\n return null;\n }\n};\n\nconst formatValueToStorage = (value: unknown): string => {\n return JSON.stringify(value);\n};\n\nexport interface SetToStorageConfig<V>\n extends Omit<GetFromStorageConfig<V>, 'fallback'> {\n value: V;\n}\n\nexport interface UnsetFromStorageConfig\n extends Omit<GetFromStorageConfig<any>, 'fallback'> {}\n\nexport interface GetFromStorageConfig<V> {\n /**\n *
|
|
1
|
+
{"version":3,"file":"storage.js","sources":["../src/storage.ts"],"sourcesContent":["export type StorageType = 'session' | 'local';\n\nconst storages: Record<StorageType, Storage> = {\n session: sessionStorage,\n local: localStorage,\n};\n\nexport const createKey = (prefix: string, key: string, namespace?: string) =>\n `${prefix}${namespace ? `/${namespace}` : ''}/${key}`;\n\nconst parseStorageValue = <V>(value: unknown): V | null => {\n if (typeof value !== 'string') {\n return value as V;\n }\n\n try {\n const parsed = JSON.parse(value);\n return parsed;\n } catch {\n return null;\n }\n};\n\nconst formatValueToStorage = (value: unknown): string => {\n return JSON.stringify(value);\n};\n\nexport interface SetToStorageConfig<V>\n extends Omit<GetFromStorageConfig<V>, 'fallback'> {\n value: V;\n}\n\nexport interface UnsetFromStorageConfig\n extends Omit<GetFromStorageConfig<any>, 'fallback'> {}\n\nexport interface GetFromStorageConfig<V> {\n /**\n * Storage key used to retrieve the value.\n * The full key is extended with the project namespace.\n */\n key: string;\n /**\n * Storage type.\n */\n type: StorageType;\n /**\n * Default value used when there is no value in storage.\n */\n fallback?: V;\n /**\n * Optional namespace segment used in the generated key.\n */\n namespace?: string;\n /**\n * Optional key prefix.\n */\n prefix?: string;\n}\n\nexport type SetToStorageWrappedConfig<\n V,\n BaseConfig extends StorageConfigBase,\n> = Omit<\n SetToStorageConfig<V>,\n Extract<keyof SetToStorageConfig<V>, keyof BaseConfig>\n> &\n Partial<\n Pick<\n SetToStorageConfig<V>,\n Extract<keyof SetToStorageConfig<V>, keyof BaseConfig>\n >\n > &\n Pick<BaseConfig, Exclude<keyof BaseConfig, keyof SetToStorageConfig<V>>>;\n\nexport type UnsetFromStorageWrappedConfig<\n BaseConfig extends StorageConfigBase,\n> = Omit<\n UnsetFromStorageConfig,\n Extract<keyof UnsetFromStorageConfig, keyof BaseConfig>\n> &\n Partial<\n Pick<\n UnsetFromStorageConfig,\n Extract<keyof UnsetFromStorageConfig, keyof BaseConfig>\n >\n > &\n Pick<BaseConfig, Exclude<keyof BaseConfig, keyof UnsetFromStorageConfig>>;\n\nexport type GetFromStorageWrappedConfig<\n V,\n BaseConfig extends StorageConfigBase,\n> = Omit<\n GetFromStorageConfig<V>,\n Extract<keyof GetFromStorageConfig<V>, keyof BaseConfig>\n> &\n Partial<\n Pick<\n GetFromStorageConfig<V>,\n Extract<keyof GetFromStorageConfig<V>, keyof BaseConfig>\n >\n > &\n Pick<BaseConfig, Exclude<keyof BaseConfig, keyof GetFromStorageConfig<V>>>;\n\nexport type StorageConfigBase = Partial<\n Pick<GetFromStorageConfig<any>, 'prefix' | 'type'>\n>;\n\nexport interface StorageApi<BaseConfig extends StorageConfigBase> {\n set<Value>(config: SetToStorageWrappedConfig<Value, BaseConfig>): void;\n unset(config: UnsetFromStorageWrappedConfig<BaseConfig>): void;\n get<Value>(\n config: GetFromStorageWrappedConfig<Value, BaseConfig>,\n ): Value | null;\n}\n\n/**\n * Creates an interface for working with storage (`localStorage`, `sessionStorage`).\n */\nexport function createStorage<BaseConfig extends StorageConfigBase>(\n storageConfig: BaseConfig,\n): StorageApi<BaseConfig> {\n return {\n set: <Value>(cfg: SetToStorageWrappedConfig<Value, BaseConfig>) => {\n const config = cfg as unknown as SetToStorageConfig<Value>;\n const storageType = (config.type ?? storageConfig.type!) as StorageType;\n const storagePrefix = (config.prefix ?? storageConfig.prefix!) as string;\n\n const storage = storages[storageType];\n\n storage.setItem(\n createKey(storagePrefix, config.key, config.namespace),\n formatValueToStorage(config.value),\n );\n },\n unset: <Value>(cfg: UnsetFromStorageWrappedConfig<BaseConfig>) => {\n const config = cfg as unknown as SetToStorageConfig<Value>;\n const storageType = (config.type ?? storageConfig.type!) as StorageType;\n const storagePrefix = (config.prefix ?? storageConfig.prefix!) as string;\n const storage = storages[storageType];\n\n storage.removeItem(\n createKey(storagePrefix, config.key, config.namespace),\n );\n },\n get: <Value>(cfg: GetFromStorageWrappedConfig<Value, BaseConfig>) => {\n const config = cfg as unknown as GetFromStorageConfig<Value>;\n const storageType = (config.type ?? storageConfig.type!) as StorageType;\n const storagePrefix = (config.prefix ?? storageConfig.prefix!) as string;\n\n const storage = storages[storageType];\n\n return (\n parseStorageValue<Value>(\n storage.getItem(\n createKey(storagePrefix, config.key, config.namespace),\n ),\n ) ??\n config.fallback ??\n null\n );\n },\n } as const;\n}\n"],"names":[],"mappings":"AAEA,MAAM,WAAyC;AAAA,EAC7C,SAAS;AAAA,EACT,OAAO;AACT;AAEO,MAAM,YAAY,CAAC,QAAgB,KAAa,cACrD,GAAG,MAAM,GAAG,YAAY,IAAI,SAAS,KAAK,EAAE,IAAI,GAAG;AAErD,MAAM,oBAAoB,CAAI,UAA6B;AACzD,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO;AAAA,EACT;AAEA,MAAI;AACF,UAAM,SAAS,KAAK,MAAM,KAAK;AAC/B,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,MAAM,uBAAuB,CAAC,UAA2B;AACvD,SAAO,KAAK,UAAU,KAAK;AAC7B;AA6FO,SAAS,cACd,eACwB;AACxB,SAAO;AAAA,IACL,KAAK,CAAQ,QAAsD;AACjE,YAAM,SAAS;AACf,YAAM,cAAe,OAAO,QAAQ,cAAc;AAClD,YAAM,gBAAiB,OAAO,UAAU,cAAc;AAEtD,YAAM,UAAU,SAAS,WAAW;AAEpC,cAAQ;AAAA,QACN,UAAU,eAAe,OAAO,KAAK,OAAO,SAAS;AAAA,QACrD,qBAAqB,OAAO,KAAK;AAAA,MAAA;AAAA,IAErC;AAAA,IACA,OAAO,CAAQ,QAAmD;AAChE,YAAM,SAAS;AACf,YAAM,cAAe,OAAO,QAAQ,cAAc;AAClD,YAAM,gBAAiB,OAAO,UAAU,cAAc;AACtD,YAAM,UAAU,SAAS,WAAW;AAEpC,cAAQ;AAAA,QACN,UAAU,eAAe,OAAO,KAAK,OAAO,SAAS;AAAA,MAAA;AAAA,IAEzD;AAAA,IACA,KAAK,CAAQ,QAAwD;AACnE,YAAM,SAAS;AACf,YAAM,cAAe,OAAO,QAAQ,cAAc;AAClD,YAAM,gBAAiB,OAAO,UAAU,cAAc;AAEtD,YAAM,UAAU,SAAS,WAAW;AAEpC,aACE;AAAA,QACE,QAAQ;AAAA,UACN,UAAU,eAAe,OAAO,KAAK,OAAO,SAAS;AAAA,QAAA;AAAA,MACvD,KAEF,OAAO,YACP;AAAA,IAEJ;AAAA,EAAA;AAEJ;"}
|
package/text.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.cjs","sources":["../src/text.ts"],"sourcesContent":["/**\n *
|
|
1
|
+
{"version":3,"file":"text.cjs","sources":["../src/text.ts"],"sourcesContent":["/**\n * Returns the correct word form based on the provided count.\n * @example\n * declension(1, ['slovo', 'slova', 'slov']) // 'slovo'\n * @example\n * declension(2, ['slovo', 'slova', 'slov']) // 'slova'\n * @example\n * declension(5, ['slovo', 'slova', 'slov']) // 'slov'\n */\nexport const declension = (\n count: number,\n txt: readonly [one: string, two: string, five: string],\n cases = [2, 0, 1, 1, 1, 2],\n) =>\n txt[count % 100 > 4 && count % 100 < 20 ? 2 : cases[Math.min(count % 10, 5)]];\n\n/**\n * Splits text into lines with a maximum line length.\n */\nexport const splitTextByLines = (\n text: string,\n lineLingth: number = 60,\n): string[] => {\n const words = text.split(/\\s+/).filter((word) => word !== '');\n const lines = [];\n let currentLine = '';\n\n for (const word of words) {\n if (word.length > lineLingth) {\n if (currentLine !== '') {\n lines.push(currentLine);\n currentLine = '';\n }\n\n let start = 0;\n while (start < word.length) {\n const chunk = word.slice(start, start + lineLingth);\n lines.push(chunk);\n start += lineLingth;\n }\n continue;\n }\n\n // Проверка возможности добавления слова в текущую строку\n if (currentLine === '') {\n currentLine = word;\n } else if (currentLine.length + 1 + word.length <= lineLingth) {\n currentLine += ` ${word}`;\n } else {\n lines.push(currentLine);\n currentLine = word;\n }\n }\n\n if (currentLine !== '' || lines.length === 0) {\n lines.push(currentLine);\n }\n\n return lines;\n};\n"],"names":[],"mappings":";;AASO,MAAM,aAAa,CACxB,OACA,KACA,QAAQ,CAAC,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC,MAEzB,IAAI,QAAQ,MAAM,KAAK,QAAQ,MAAM,KAAK,IAAI,MAAM,KAAK,IAAI,QAAQ,IAAI,CAAC,CAAC,CAAC;AAKvE,MAAM,mBAAmB,CAC9B,MACA,aAAqB,OACR;AACb,QAAM,QAAQ,KAAK,MAAM,KAAK,EAAE,OAAO,CAAC,SAAS,SAAS,EAAE;AAC5D,QAAM,QAAQ,CAAA;AACd,MAAI,cAAc;AAElB,aAAW,QAAQ,OAAO;AACxB,QAAI,KAAK,SAAS,YAAY;AAC5B,UAAI,gBAAgB,IAAI;AACtB,cAAM,KAAK,WAAW;AACtB,sBAAc;AAAA,MAChB;AAEA,UAAI,QAAQ;AACZ,aAAO,QAAQ,KAAK,QAAQ;AAC1B,cAAM,QAAQ,KAAK,MAAM,OAAO,QAAQ,UAAU;AAClD,cAAM,KAAK,KAAK;AAChB,iBAAS;AAAA,MACX;AACA;AAAA,IACF;AAGA,QAAI,gBAAgB,IAAI;AACtB,oBAAc;AAAA,IAChB,WAAW,YAAY,SAAS,IAAI,KAAK,UAAU,YAAY;AAC7D,qBAAe,IAAI,IAAI;AAAA,IACzB,OAAO;AACL,YAAM,KAAK,WAAW;AACtB,oBAAc;AAAA,IAChB;AAAA,EACF;AAEA,MAAI,gBAAgB,MAAM,MAAM,WAAW,GAAG;AAC5C,UAAM,KAAK,WAAW;AAAA,EACxB;AAEA,SAAO;AACT;;;"}
|
package/text.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Returns the correct word form based on the provided count.
|
|
3
3
|
* @example
|
|
4
|
-
* declension(1, ['
|
|
4
|
+
* declension(1, ['slovo', 'slova', 'slov']) // 'slovo'
|
|
5
5
|
* @example
|
|
6
|
-
* declension(2, ['
|
|
6
|
+
* declension(2, ['slovo', 'slova', 'slov']) // 'slova'
|
|
7
7
|
* @example
|
|
8
|
-
* declension(5, ['
|
|
8
|
+
* declension(5, ['slovo', 'slova', 'slov']) // 'slov'
|
|
9
9
|
*/
|
|
10
10
|
declare const declension: (count: number, txt: readonly [one: string, two: string, five: string], cases?: number[]) => string;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Splits text into lines with a maximum line length.
|
|
13
13
|
*/
|
|
14
14
|
declare const splitTextByLines: (text: string, lineLingth?: number) => string[];
|
|
15
15
|
|
package/text.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","sources":["../src/text.ts"],"sourcesContent":["/**\n *
|
|
1
|
+
{"version":3,"file":"text.js","sources":["../src/text.ts"],"sourcesContent":["/**\n * Returns the correct word form based on the provided count.\n * @example\n * declension(1, ['slovo', 'slova', 'slov']) // 'slovo'\n * @example\n * declension(2, ['slovo', 'slova', 'slov']) // 'slova'\n * @example\n * declension(5, ['slovo', 'slova', 'slov']) // 'slov'\n */\nexport const declension = (\n count: number,\n txt: readonly [one: string, two: string, five: string],\n cases = [2, 0, 1, 1, 1, 2],\n) =>\n txt[count % 100 > 4 && count % 100 < 20 ? 2 : cases[Math.min(count % 10, 5)]];\n\n/**\n * Splits text into lines with a maximum line length.\n */\nexport const splitTextByLines = (\n text: string,\n lineLingth: number = 60,\n): string[] => {\n const words = text.split(/\\s+/).filter((word) => word !== '');\n const lines = [];\n let currentLine = '';\n\n for (const word of words) {\n if (word.length > lineLingth) {\n if (currentLine !== '') {\n lines.push(currentLine);\n currentLine = '';\n }\n\n let start = 0;\n while (start < word.length) {\n const chunk = word.slice(start, start + lineLingth);\n lines.push(chunk);\n start += lineLingth;\n }\n continue;\n }\n\n // Проверка возможности добавления слова в текущую строку\n if (currentLine === '') {\n currentLine = word;\n } else if (currentLine.length + 1 + word.length <= lineLingth) {\n currentLine += ` ${word}`;\n } else {\n lines.push(currentLine);\n currentLine = word;\n }\n }\n\n if (currentLine !== '' || lines.length === 0) {\n lines.push(currentLine);\n }\n\n return lines;\n};\n"],"names":[],"mappings":"AASO,MAAM,aAAa,CACxB,OACA,KACA,QAAQ,CAAC,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC,MAEzB,IAAI,QAAQ,MAAM,KAAK,QAAQ,MAAM,KAAK,IAAI,MAAM,KAAK,IAAI,QAAQ,IAAI,CAAC,CAAC,CAAC;AAKvE,MAAM,mBAAmB,CAC9B,MACA,aAAqB,OACR;AACb,QAAM,QAAQ,KAAK,MAAM,KAAK,EAAE,OAAO,CAAC,SAAS,SAAS,EAAE;AAC5D,QAAM,QAAQ,CAAA;AACd,MAAI,cAAc;AAElB,aAAW,QAAQ,OAAO;AACxB,QAAI,KAAK,SAAS,YAAY;AAC5B,UAAI,gBAAgB,IAAI;AACtB,cAAM,KAAK,WAAW;AACtB,sBAAc;AAAA,MAChB;AAEA,UAAI,QAAQ;AACZ,aAAO,QAAQ,KAAK,QAAQ;AAC1B,cAAM,QAAQ,KAAK,MAAM,OAAO,QAAQ,UAAU;AAClD,cAAM,KAAK,KAAK;AAChB,iBAAS;AAAA,MACX;AACA;AAAA,IACF;AAGA,QAAI,gBAAgB,IAAI;AACtB,oBAAc;AAAA,IAChB,WAAW,YAAY,SAAS,IAAI,KAAK,UAAU,YAAY;AAC7D,qBAAe,IAAI,IAAI;AAAA,IACzB,OAAO;AACL,YAAM,KAAK,WAAW;AACtB,oBAAc;AAAA,IAChB;AAAA,EACF;AAEA,MAAI,gBAAgB,MAAM,MAAM,WAAW,GAAG;AAC5C,UAAM,KAAK,WAAW;AAAA,EACxB;AAEA,SAAO;AACT;"}
|
package/type-guard.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-guard.cjs","sources":["../src/type-guard/_exports.ts"],"sourcesContent":["import type { AnyFunction, AnyObject, ValueOf } 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 *
|
|
1
|
+
{"version":3,"file":"type-guard.cjs","sources":["../src/type-guard/_exports.ts"],"sourcesContent":["import type { AnyFunction, AnyObject, ValueOf } 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 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"],"names":[],"mappings":";;AAEA,MAAM,OAAO;AAAA,EACX,MAAM;AAAA,EACN,WAAW;AAAA,EACX,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,UAAU;AAAA,EACV,eAAe;AAAA,EACf,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,SAAS;AACX;AAIA,SAAS,QAAQ,OAAsB;AACrC,MAAI,UAAU,QAAW;AACvB,WAAO,KAAK;AAAA,EACd;AACA,MAAI,UAAU,MAAM;AAClB,WAAO,KAAK;AAAA,EACd;AAIA,MAAI,UAAU,MAAM,aAAa,KAAK,MAAM,aAAa,IAAI;AAC3D,WAAO,KAAK;AAAA,EACd;AAEA,QAAM,mBAAmB,OAAO,UAAU,SAAS,KAAK,KAAK;AAG7D,MAAI,qBAAqB,KAAK,QAAQ;AACpC,QAAI,OAAO,MAAM,KAAe,GAAG;AACjC,aAAO,KAAK;AAAA,IACd;AACA,QAAI,CAAC,OAAO,SAAS,KAAe,GAAG;AACrC,aAAO,KAAK;AAAA,IACd;AAAA,EACF;AAEA,SAAO;AACT;AAEA,MAAM,kBACJ,IAAO,UACP,CAAC,UACC,MAAM,SAAS,QAAQ,KAAK,CAAC;AAmB1B,MAAM,YAAY,CAAI,UAC3B,SAAS;AAkBJ,MAAM,SAAS,gBAAsB,KAAK,IAAI;AAkB9C,MAAM,cAAc,gBAA2B,KAAK,SAAS;AAkB7D,MAAM,WAAW,gBAA2B,KAAK,MAAM;AAkBvD,MAAM,UAAU,gBAA2B,KAAK,KAAK;AAkBrD,MAAM,WAAW,gBAAwB,KAAK,MAAM;AAoBpD,MAAM,WAAW,gBAAwB,KAAK,MAAM;AAkBpD,MAAM,YAAY,gBAAyB,KAAK,OAAO;AAkBvD,MAAM,aAAa;AAAA,EACxB,KAAK;AAAA,EACL,KAAK;AACP;AAkBO,MAAM,WAAW,gBAAwB,KAAK,MAAM;AAkBpD,MAAM,YAAY,gBAA6B,KAAK,OAAO;AAkB3D,MAAM,QAAQ,gBAAwB,KAAK,GAAG;AAoB9C,MAAM,aAAa,gBAAwB,KAAK,QAAQ;AAoBxD,MAAM,WAAW,gBAAwB,KAAK,MAAM;;;;;;;;;;;;;;;;;;;"}
|
package/type-guard.d.ts
CHANGED
|
@@ -1,87 +1,244 @@
|
|
|
1
1
|
import { AnyFunction, AnyObject } from 'yummies/types';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* @
|
|
4
|
+
* Checks that a value is neither `null` nor `undefined`.
|
|
5
|
+
*
|
|
6
|
+
* @template T Value type without nullish branches.
|
|
7
|
+
* @param value Value to test.
|
|
8
|
+
* @returns `true` when the value is defined.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* isDefined(0); // true
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* isDefined(null); // false
|
|
18
|
+
* ```
|
|
7
19
|
*/
|
|
8
20
|
declare const isDefined: <T>(value: T | undefined | null) => value is T;
|
|
9
21
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* @
|
|
22
|
+
* Checks whether a value is exactly `null`.
|
|
23
|
+
*
|
|
24
|
+
* @param value Value to test.
|
|
25
|
+
* @returns `true` when the value is `null`.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* isNull(null); // true
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* isNull(undefined); // false
|
|
35
|
+
* ```
|
|
13
36
|
*/
|
|
14
37
|
declare const isNull: (value: unknown) => value is null;
|
|
15
38
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* @
|
|
39
|
+
* Checks whether a value is exactly `undefined`.
|
|
40
|
+
*
|
|
41
|
+
* @param value Value to test.
|
|
42
|
+
* @returns `true` when the value is `undefined`.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* isUndefined(undefined); // true
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* isUndefined('value'); // false
|
|
52
|
+
* ```
|
|
19
53
|
*/
|
|
20
54
|
declare const isUndefined: (value: unknown) => value is undefined;
|
|
21
55
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* @
|
|
56
|
+
* Checks whether a value is a plain object.
|
|
57
|
+
*
|
|
58
|
+
* @param value Value to test.
|
|
59
|
+
* @returns `true` when the value matches `[object Object]`.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* isObject({ id: 1 }); // true
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* isObject([]); // false
|
|
69
|
+
* ```
|
|
25
70
|
*/
|
|
26
71
|
declare const isObject: (value: unknown) => value is AnyObject;
|
|
27
72
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* @
|
|
73
|
+
* Checks whether a value is an array.
|
|
74
|
+
*
|
|
75
|
+
* @param value Value to test.
|
|
76
|
+
* @returns `true` when the value is an array.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* isArray([1, 2, 3]); // true
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* isArray({ length: 1 }); // false
|
|
86
|
+
* ```
|
|
31
87
|
*/
|
|
32
88
|
declare const isArray: (value: unknown) => value is unknown[];
|
|
33
89
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* @
|
|
90
|
+
* Checks whether a value is a string object or primitive string.
|
|
91
|
+
*
|
|
92
|
+
* @param value Value to test.
|
|
93
|
+
* @returns `true` when the value is a string.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* isString('hello'); // true
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* isString(123); // false
|
|
103
|
+
* ```
|
|
37
104
|
*/
|
|
38
105
|
declare const isString: (value: unknown) => value is string;
|
|
39
106
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
107
|
+
* Checks whether a value is a finite number.
|
|
108
|
+
*
|
|
109
|
+
* Unlike `isNaN` and `isInfinite`, this guard only matches regular numeric values.
|
|
110
|
+
*
|
|
111
|
+
* @param value Value to test.
|
|
112
|
+
* @returns `true` when the value is a non-NaN finite number.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* isNumber(123); // true
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* isNumber(Number.NaN); // false
|
|
122
|
+
* ```
|
|
43
123
|
*/
|
|
44
124
|
declare const isNumber: (value: unknown) => value is number;
|
|
45
125
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* @
|
|
126
|
+
* Checks whether a value is a boolean.
|
|
127
|
+
*
|
|
128
|
+
* @param value Value to test.
|
|
129
|
+
* @returns `true` when the value is a boolean.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* isBoolean(true); // true
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* isBoolean('true'); // false
|
|
139
|
+
* ```
|
|
49
140
|
*/
|
|
50
141
|
declare const isBoolean: (value: unknown) => value is boolean;
|
|
51
142
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* @
|
|
143
|
+
* Checks whether a value is a synchronous or asynchronous function.
|
|
144
|
+
*
|
|
145
|
+
* @param value Value to test.
|
|
146
|
+
* @returns `true` when the value is a function.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts
|
|
150
|
+
* isFunction(() => {}); // true
|
|
151
|
+
* ```
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```ts
|
|
155
|
+
* isFunction(async () => {}); // true
|
|
156
|
+
* ```
|
|
55
157
|
*/
|
|
56
158
|
declare const isFunction: (value: unknown) => value is AnyFunction;
|
|
57
159
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* @
|
|
160
|
+
* Checks whether a value is a regular expression.
|
|
161
|
+
*
|
|
162
|
+
* @param value Value to test.
|
|
163
|
+
* @returns `true` when the value is a `RegExp`.
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```ts
|
|
167
|
+
* isRegExp(/foo/); // true
|
|
168
|
+
* ```
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```ts
|
|
172
|
+
* isRegExp('foo'); // false
|
|
173
|
+
* ```
|
|
61
174
|
*/
|
|
62
175
|
declare const isRegExp: (value: unknown) => value is RegExp;
|
|
63
176
|
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* @
|
|
177
|
+
* Checks whether a value looks like a DOM element or document node.
|
|
178
|
+
*
|
|
179
|
+
* @param value Value to test.
|
|
180
|
+
* @returns `true` when the value has an element-like node type.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```ts
|
|
184
|
+
* isElement(document.body); // true
|
|
185
|
+
* ```
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```ts
|
|
189
|
+
* isElement({ nodeType: 3 }); // false
|
|
190
|
+
* ```
|
|
67
191
|
*/
|
|
68
192
|
declare const isElement: (value: unknown) => value is HTMLElement;
|
|
69
193
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* @
|
|
194
|
+
* Checks whether a value is `NaN`.
|
|
195
|
+
*
|
|
196
|
+
* @param value Value to test.
|
|
197
|
+
* @returns `true` when the value is `NaN`.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```ts
|
|
201
|
+
* isNaN(Number.NaN); // true
|
|
202
|
+
* ```
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ```ts
|
|
206
|
+
* isNaN(5); // false
|
|
207
|
+
* ```
|
|
73
208
|
*/
|
|
74
209
|
declare const isNaN: (value: unknown) => boolean;
|
|
75
210
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* @
|
|
211
|
+
* Checks whether a value is positive or negative infinity.
|
|
212
|
+
*
|
|
213
|
+
* @param value Value to test.
|
|
214
|
+
* @returns `true` when the value is not finite.
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```ts
|
|
218
|
+
* isInfinite(Infinity); // true
|
|
219
|
+
* ```
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```ts
|
|
223
|
+
* isInfinite(10); // false
|
|
224
|
+
* ```
|
|
79
225
|
*/
|
|
80
226
|
declare const isInfinite: (value: unknown) => boolean;
|
|
81
227
|
/**
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* @
|
|
228
|
+
* Checks whether a value is a symbol.
|
|
229
|
+
*
|
|
230
|
+
* @param value Value to test.
|
|
231
|
+
* @returns `true` when the value is a symbol.
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```ts
|
|
235
|
+
* isSymbol(Symbol('id')); // true
|
|
236
|
+
* ```
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* ```ts
|
|
240
|
+
* isSymbol('id'); // false
|
|
241
|
+
* ```
|
|
85
242
|
*/
|
|
86
243
|
declare const isSymbol: (value: unknown) => value is symbol;
|
|
87
244
|
|
package/type-guard.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-guard.js","sources":["../src/type-guard/_exports.ts"],"sourcesContent":["import type { AnyFunction, AnyObject, ValueOf } 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 *
|
|
1
|
+
{"version":3,"file":"type-guard.js","sources":["../src/type-guard/_exports.ts"],"sourcesContent":["import type { AnyFunction, AnyObject, ValueOf } 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 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"],"names":[],"mappings":"AAEA,MAAM,OAAO;AAAA,EACX,MAAM;AAAA,EACN,WAAW;AAAA,EACX,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,UAAU;AAAA,EACV,eAAe;AAAA,EACf,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,SAAS;AACX;AAIA,SAAS,QAAQ,OAAsB;AACrC,MAAI,UAAU,QAAW;AACvB,WAAO,KAAK;AAAA,EACd;AACA,MAAI,UAAU,MAAM;AAClB,WAAO,KAAK;AAAA,EACd;AAIA,MAAI,UAAU,MAAM,aAAa,KAAK,MAAM,aAAa,IAAI;AAC3D,WAAO,KAAK;AAAA,EACd;AAEA,QAAM,mBAAmB,OAAO,UAAU,SAAS,KAAK,KAAK;AAG7D,MAAI,qBAAqB,KAAK,QAAQ;AACpC,QAAI,OAAO,MAAM,KAAe,GAAG;AACjC,aAAO,KAAK;AAAA,IACd;AACA,QAAI,CAAC,OAAO,SAAS,KAAe,GAAG;AACrC,aAAO,KAAK;AAAA,IACd;AAAA,EACF;AAEA,SAAO;AACT;AAEA,MAAM,kBACJ,IAAO,UACP,CAAC,UACC,MAAM,SAAS,QAAQ,KAAK,CAAC;AAmB1B,MAAM,YAAY,CAAI,UAC3B,SAAS;AAkBJ,MAAM,SAAS,gBAAsB,KAAK,IAAI;AAkB9C,MAAM,cAAc,gBAA2B,KAAK,SAAS;AAkB7D,MAAM,WAAW,gBAA2B,KAAK,MAAM;AAkBvD,MAAM,UAAU,gBAA2B,KAAK,KAAK;AAkBrD,MAAM,WAAW,gBAAwB,KAAK,MAAM;AAoBpD,MAAM,WAAW,gBAAwB,KAAK,MAAM;AAkBpD,MAAM,YAAY,gBAAyB,KAAK,OAAO;AAkBvD,MAAM,aAAa;AAAA,EACxB,KAAK;AAAA,EACL,KAAK;AACP;AAkBO,MAAM,WAAW,gBAAwB,KAAK,MAAM;AAkBpD,MAAM,YAAY,gBAA6B,KAAK,OAAO;AAkB3D,MAAM,QAAQ,gBAAwB,KAAK,GAAG;AAoB9C,MAAM,aAAa,gBAAwB,KAAK,QAAQ;AAoBxD,MAAM,WAAW,gBAAwB,KAAK,MAAM;;;;;;;;;;;;;;;;;;"}
|
package/vibrate.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vibrate.cjs","sources":["../src/vibrate.ts"],"sourcesContent":["/**\n *
|
|
1
|
+
{"version":3,"file":"vibrate.cjs","sources":["../src/vibrate.ts"],"sourcesContent":["/**\n * Triggers vibration using the provided pattern.\n */\nexport const vibrate = (pattern: number | number[]) => {\n if ('vibrate' in navigator) {\n navigator.vibrate(pattern);\n }\n};\n"],"names":[],"mappings":";;AAGO,MAAM,UAAU,CAAC,YAA+B;AACrD,MAAI,aAAa,WAAW;AAC1B,cAAU,QAAQ,OAAO;AAAA,EAC3B;AACF;;"}
|
package/vibrate.d.ts
CHANGED
package/vibrate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vibrate.js","sources":["../src/vibrate.ts"],"sourcesContent":["/**\n *
|
|
1
|
+
{"version":3,"file":"vibrate.js","sources":["../src/vibrate.ts"],"sourcesContent":["/**\n * Triggers vibration using the provided pattern.\n */\nexport const vibrate = (pattern: number | number[]) => {\n if ('vibrate' in navigator) {\n navigator.vibrate(pattern);\n }\n};\n"],"names":[],"mappings":"AAGO,MAAM,UAAU,CAAC,YAA+B;AACrD,MAAI,aAAa,WAAW;AAC1B,cAAU,QAAQ,OAAO;AAAA,EAC3B;AACF;"}
|