yummies 5.15.1 → 6.0.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/README.md +10 -4
- package/async.cjs +45 -1
- package/async.cjs.map +1 -1
- package/async.d.ts +7 -6
- package/common.cjs +11 -1
- package/common.cjs.map +1 -1
- package/common.d.ts +8 -5
- package/common.js.map +1 -1
- package/complex.cjs +88 -1
- package/complex.cjs.map +1 -1
- package/{complex/modules-factory.d.ts → complex.d.ts} +31 -4
- package/complex.js.map +1 -1
- package/cookie.cjs +9 -1
- package/cookie.cjs.map +1 -1
- package/cookie.d.ts +5 -3
- package/cookie.js.map +1 -1
- package/css.cjs +45 -1
- package/css.cjs.map +1 -1
- package/css.d.ts +11 -8
- package/css.js.map +1 -1
- package/data.cjs +43 -1
- package/data.cjs.map +1 -1
- package/data.d.ts +5 -4
- package/data.js.map +1 -1
- package/date-time.cjs +395 -1
- package/date-time.cjs.map +1 -1
- package/date-time.d.ts +12 -10
- package/date-time.js.map +1 -1
- package/device.cjs +32 -1
- package/device.cjs.map +1 -1
- package/device.d.ts +9 -8
- package/encodings.cjs +270 -1
- package/encodings.cjs.map +1 -1
- package/encodings.d.ts +3 -2
- package/encodings.js.map +1 -1
- package/errors.cjs +23 -1
- package/errors.cjs.map +1 -1
- package/errors.d.ts +5 -4
- package/errors.js.map +1 -1
- package/file.cjs +28 -1
- package/file.cjs.map +1 -1
- package/file.d.ts +4 -3
- package/format.cjs +75 -1
- package/format.cjs.map +1 -1
- package/format.d.ts +74 -0
- package/format.js.map +1 -1
- package/html.cjs +167 -1
- package/html.cjs.map +1 -1
- package/html.d.ts +19 -17
- package/html.js.map +1 -1
- package/id.cjs +25 -1
- package/id.cjs.map +1 -1
- package/id.d.ts +9 -8
- package/imports.cjs +33 -1
- package/imports.cjs.map +1 -1
- package/imports.d.ts +6 -4
- package/math.cjs +14 -1
- package/math.cjs.map +1 -1
- package/math.d.ts +7 -5
- package/math.js.map +1 -1
- package/media.cjs +105 -1
- package/media.cjs.map +1 -1
- package/media.d.ts +11 -11
- package/mobx.cjs +184 -1
- package/mobx.cjs.map +1 -1
- package/mobx.d.ts +66 -0
- package/mobx.js.map +1 -1
- package/ms.cjs +13 -1
- package/ms.cjs.map +1 -1
- package/ms.d.ts +4 -3
- package/number.cjs +10 -1
- package/number.cjs.map +1 -1
- package/number.d.ts +3 -2
- package/package.json +39 -113
- package/parser.cjs +68 -1
- package/parser.cjs.map +1 -1
- package/parser.d.ts +41 -0
- package/parser.js.map +1 -1
- package/price.cjs +20 -1
- package/price.cjs.map +1 -1
- package/price.d.ts +5 -3
- package/random.cjs +24 -1
- package/random.cjs.map +1 -1
- package/random.d.ts +10 -9
- package/react.cjs +216 -1
- package/react.cjs.map +1 -1
- package/react.d.ts +113 -0
- package/react.js.map +1 -1
- package/sound.cjs +11 -1
- package/sound.cjs.map +1 -1
- package/sound.d.ts +3 -2
- package/text.cjs +37 -1
- package/text.cjs.map +1 -1
- package/text.d.ts +4 -3
- package/type-guard.cjs +75 -1
- package/type-guard.cjs.map +1 -1
- package/type-guard.d.ts +121 -0
- package/type-guard.js.map +1 -1
- package/{utils/types.d.ts → types.d.ts} +54 -53
- package/types.global.cjs +2 -0
- package/types.global.cjs.map +1 -0
- package/{utility-types.d.ts → types.global.d.ts} +1 -1
- package/types.global.js +2 -0
- package/types.global.js.map +1 -0
- package/vibrate.cjs +8 -1
- package/vibrate.cjs.map +1 -1
- package/vibrate.d.ts +3 -2
- package/async.d.ts.map +0 -1
- package/common.d.ts.map +0 -1
- package/complex/counter.d.ts +0 -15
- package/complex/counter.d.ts.map +0 -1
- package/complex/global-config.d.ts +0 -11
- package/complex/global-config.d.ts.map +0 -1
- package/complex/index.d.ts +0 -4
- package/complex/index.d.ts.map +0 -1
- package/complex/modules-factory.d.ts.map +0 -1
- package/cookie.d.ts.map +0 -1
- package/css.d.ts.map +0 -1
- package/data.d.ts.map +0 -1
- package/date-time.d.ts.map +0 -1
- package/device.d.ts.map +0 -1
- package/encodings.d.ts.map +0 -1
- package/errors.d.ts.map +0 -1
- package/file.d.ts.map +0 -1
- package/format/_exports.d.ts +0 -5
- package/format/_exports.d.ts.map +0 -1
- package/format/constants.d.ts +0 -4
- package/format/constants.d.ts.map +0 -1
- package/format/index.d.ts +0 -3
- package/format/index.d.ts.map +0 -1
- package/format/number.d.ts +0 -36
- package/format/number.d.ts.map +0 -1
- package/format/percent.d.ts +0 -15
- package/format/percent.d.ts.map +0 -1
- package/format/skip-spaces.d.ts +0 -5
- package/format/skip-spaces.d.ts.map +0 -1
- package/html.d.ts.map +0 -1
- package/id.d.ts.map +0 -1
- package/imports.d.ts.map +0 -1
- package/math.d.ts.map +0 -1
- package/media.d.ts.map +0 -1
- package/mobx/apply-observable.d.ts +0 -4
- package/mobx/apply-observable.d.ts.map +0 -1
- package/mobx/create-enhanced-atom.d.ts +0 -11
- package/mobx/create-enhanced-atom.d.ts.map +0 -1
- package/mobx/create-ref.d.ts +0 -28
- package/mobx/create-ref.d.ts.map +0 -1
- package/mobx/deep-observable-struct.d.ts +0 -7
- package/mobx/deep-observable-struct.d.ts.map +0 -1
- package/mobx/get-mobx-administration.d.ts +0 -6
- package/mobx/get-mobx-administration.d.ts.map +0 -1
- package/mobx/index.d.ts +0 -7
- package/mobx/index.d.ts.map +0 -1
- package/mobx/lazy-observe.d.ts +0 -14
- package/mobx/lazy-observe.d.ts.map +0 -1
- package/ms.d.ts.map +0 -1
- package/number.d.ts.map +0 -1
- package/parser/_exports.d.ts +0 -4
- package/parser/_exports.d.ts.map +0 -1
- package/parser/index.d.ts +0 -3
- package/parser/index.d.ts.map +0 -1
- package/parser/number.d.ts +0 -21
- package/parser/number.d.ts.map +0 -1
- package/parser/percent.d.ts +0 -4
- package/parser/percent.d.ts.map +0 -1
- package/parser/string.d.ts +0 -7
- package/parser/string.d.ts.map +0 -1
- package/price.d.ts.map +0 -1
- package/random.d.ts.map +0 -1
- package/react/hooks/index.d.ts +0 -22
- package/react/hooks/index.d.ts.map +0 -1
- package/react/hooks/use-abort-controller.d.ts +0 -2
- package/react/hooks/use-abort-controller.d.ts.map +0 -1
- package/react/hooks/use-abort-signal.d.ts +0 -2
- package/react/hooks/use-abort-signal.d.ts.map +0 -1
- package/react/hooks/use-click-outside.d.ts +0 -9
- package/react/hooks/use-click-outside.d.ts.map +0 -1
- package/react/hooks/use-constant.d.ts +0 -9
- package/react/hooks/use-constant.d.ts.map +0 -1
- package/react/hooks/use-define-ref.d.ts +0 -10
- package/react/hooks/use-define-ref.d.ts.map +0 -1
- package/react/hooks/use-element-ref.d.ts +0 -2
- package/react/hooks/use-element-ref.d.ts.map +0 -1
- package/react/hooks/use-event-listener.d.ts +0 -8
- package/react/hooks/use-event-listener.d.ts.map +0 -1
- package/react/hooks/use-event.d.ts +0 -3
- package/react/hooks/use-event.d.ts.map +0 -1
- package/react/hooks/use-flag.d.ts +0 -8
- package/react/hooks/use-flag.d.ts.map +0 -1
- package/react/hooks/use-force-update.d.ts +0 -2
- package/react/hooks/use-force-update.d.ts.map +0 -1
- package/react/hooks/use-initial-height.d.ts +0 -5
- package/react/hooks/use-initial-height.d.ts.map +0 -1
- package/react/hooks/use-instance.d.ts +0 -27
- package/react/hooks/use-instance.d.ts.map +0 -1
- package/react/hooks/use-intersection-observer.d.ts +0 -2
- package/react/hooks/use-intersection-observer.d.ts.map +0 -1
- package/react/hooks/use-last-defined-value.d.ts +0 -2
- package/react/hooks/use-last-defined-value.d.ts.map +0 -1
- package/react/hooks/use-last-value-ref.d.ts +0 -2
- package/react/hooks/use-last-value-ref.d.ts.map +0 -1
- package/react/hooks/use-life-cycle.d.ts +0 -5
- package/react/hooks/use-life-cycle.d.ts.map +0 -1
- package/react/hooks/use-resize-observer.d.ts +0 -2
- package/react/hooks/use-resize-observer.d.ts.map +0 -1
- package/react/hooks/use-sync-ref.d.ts +0 -2
- package/react/hooks/use-sync-ref.d.ts.map +0 -1
- package/react/hooks/use-toggle.d.ts +0 -2
- package/react/hooks/use-toggle.d.ts.map +0 -1
- package/react/hooks/use-value.d.ts +0 -5
- package/react/hooks/use-value.d.ts.map +0 -1
- package/react/hooks/use-visibility-state.d.ts +0 -2
- package/react/hooks/use-visibility-state.d.ts.map +0 -1
- package/react/index.d.ts +0 -2
- package/react/index.d.ts.map +0 -1
- package/sound.d.ts.map +0 -1
- package/storage.d.ts +0 -39
- package/storage.d.ts.map +0 -1
- package/text.d.ts.map +0 -1
- package/type-guard/_exports.d.ts +0 -86
- package/type-guard/_exports.d.ts.map +0 -1
- package/type-guard/index.d.ts +0 -3
- package/type-guard/index.d.ts.map +0 -1
- package/utility-types.cjs +0 -2
- package/utility-types.cjs.map +0 -1
- package/utility-types.d.ts.map +0 -1
- package/utility-types.js +0 -2
- package/utility-types.js.map +0 -1
- package/utils/types.d.ts.map +0 -1
- package/vibrate.d.ts.map +0 -1
- /package/{utils/types.cjs → types.cjs} +0 -0
- /package/{utils/types.cjs.map → types.cjs.map} +0 -0
- /package/{utils/types.js → types.js} +0 -0
- /package/{utils/types.js.map → types.js.map} +0 -0
package/type-guard.cjs
CHANGED
|
@@ -1,2 +1,76 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const TYPE = {
|
|
4
|
+
Null: "null",
|
|
5
|
+
Undefined: "undefined",
|
|
6
|
+
NaN: "nan",
|
|
7
|
+
Object: "[object Object]",
|
|
8
|
+
Array: "[object Array]",
|
|
9
|
+
String: "[object String]",
|
|
10
|
+
Number: "[object Number]",
|
|
11
|
+
Boolean: "[object Boolean]",
|
|
12
|
+
Function: "[object Function]",
|
|
13
|
+
AsyncFunction: "[object AsyncFunction]",
|
|
14
|
+
RegExp: "[object RegExp]",
|
|
15
|
+
Symbol: "[object Symbol]",
|
|
16
|
+
Infinite: "infinite",
|
|
17
|
+
Element: "element"
|
|
18
|
+
};
|
|
19
|
+
function getType(value) {
|
|
20
|
+
if (value === void 0) {
|
|
21
|
+
return TYPE.Undefined;
|
|
22
|
+
}
|
|
23
|
+
if (value === null) {
|
|
24
|
+
return TYPE.Null;
|
|
25
|
+
}
|
|
26
|
+
if (value && (value.nodeType === 1 || value.nodeType === 9)) {
|
|
27
|
+
return TYPE.Element;
|
|
28
|
+
}
|
|
29
|
+
const stringifiedValue = Object.prototype.toString.call(value);
|
|
30
|
+
if (stringifiedValue === TYPE.Number) {
|
|
31
|
+
if (Number.isNaN(value)) {
|
|
32
|
+
return TYPE.NaN;
|
|
33
|
+
}
|
|
34
|
+
if (!Number.isFinite(value)) {
|
|
35
|
+
return TYPE.Infinite;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return stringifiedValue;
|
|
39
|
+
}
|
|
40
|
+
const createTypeGuard = (...types) => (value) => types.includes(getType(value));
|
|
41
|
+
const isDefined = (value) => value != null;
|
|
42
|
+
const isNull = createTypeGuard(TYPE.Null);
|
|
43
|
+
const isUndefined = createTypeGuard(TYPE.Undefined);
|
|
44
|
+
const isObject = createTypeGuard(TYPE.Object);
|
|
45
|
+
const isArray = createTypeGuard(TYPE.Array);
|
|
46
|
+
const isString = createTypeGuard(TYPE.String);
|
|
47
|
+
const isNumber = createTypeGuard(TYPE.Number);
|
|
48
|
+
const isBoolean = createTypeGuard(TYPE.Boolean);
|
|
49
|
+
const isFunction = createTypeGuard(
|
|
50
|
+
TYPE.Function,
|
|
51
|
+
TYPE.AsyncFunction
|
|
52
|
+
);
|
|
53
|
+
const isRegExp = createTypeGuard(TYPE.RegExp);
|
|
54
|
+
const isElement = createTypeGuard(TYPE.Element);
|
|
55
|
+
const isNaN = createTypeGuard(TYPE.NaN);
|
|
56
|
+
const isInfinite = createTypeGuard(TYPE.Infinite);
|
|
57
|
+
const isSymbol = createTypeGuard(TYPE.Symbol);
|
|
58
|
+
const _exports = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
59
|
+
__proto__: null,
|
|
60
|
+
isArray,
|
|
61
|
+
isBoolean,
|
|
62
|
+
isDefined,
|
|
63
|
+
isElement,
|
|
64
|
+
isFunction,
|
|
65
|
+
isInfinite,
|
|
66
|
+
isNaN,
|
|
67
|
+
isNull,
|
|
68
|
+
isNumber,
|
|
69
|
+
isObject,
|
|
70
|
+
isRegExp,
|
|
71
|
+
isString,
|
|
72
|
+
isSymbol,
|
|
73
|
+
isUndefined
|
|
74
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
75
|
+
exports.typeGuard = _exports;
|
|
2
76
|
//# sourceMappingURL=type-guard.cjs.map
|
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/
|
|
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 * Check if a value is not null or undefined\n * @param value the value to check\n * @returns boolean\n */\nexport const isDefined = <T>(value: T | undefined | null): value is T =>\n value != null;\n\n/**\n * Check if a value is null\n * @param value the value to check\n * @returns boolean\n */\nexport const isNull = createTypeGuard<null>(TYPE.Null);\n\n/**\n * Check if a value is undefined\n * @param value the value to check\n * @returns boolean\n */\nexport const isUndefined = createTypeGuard<undefined>(TYPE.Undefined);\n\n/**\n * Check if a value is an object\n * @param value the value to check\n * @returns boolean\n */\nexport const isObject = createTypeGuard<AnyObject>(TYPE.Object);\n\n/**\n * Check if a value is an array\n * @param value the value to check\n * @returns boolean\n */\nexport const isArray = createTypeGuard<unknown[]>(TYPE.Array);\n\n/**\n * Check if a value is a string\n * @param value the value to check\n * @returns boolean\n */\nexport const isString = createTypeGuard<string>(TYPE.String);\n\n/**\n * Check if a value is a number\n * @param value the value to check\n * @returns boolean\n */\nexport const isNumber = createTypeGuard<number>(TYPE.Number);\n\n/**\n * Check if a value is a boolean\n * @param value the value to check\n * @returns boolean\n */\nexport const isBoolean = createTypeGuard<boolean>(TYPE.Boolean);\n\n/**\n * Check if a value is a function\n * @param value the value to check\n * @returns boolean\n */\nexport const isFunction = createTypeGuard<AnyFunction>(\n TYPE.Function,\n TYPE.AsyncFunction,\n);\n\n/**\n * Check if a value is a regular expression\n * @param value the value to check\n * @returns boolean\n */\nexport const isRegExp = createTypeGuard<RegExp>(TYPE.RegExp);\n\n/**\n * Check if a value is a DOM element\n * @param value the value to check\n * @returns boolean\n */\nexport const isElement = createTypeGuard<HTMLElement>(TYPE.Element);\n\n/**\n * Check if a value is NaN\n * @param value the value to check\n * @returns boolean\n */\nexport const isNaN = createTypeGuard<number>(TYPE.NaN) as (\n value: unknown,\n) => boolean;\n\n/**\n * Check if a value is infinity\n * @param value the value to check\n * @returns boolean\n */\nexport const isInfinite = createTypeGuard<number>(TYPE.Infinite) as (\n value: unknown,\n) => boolean;\n\n/**\n * Check if a value is a symbol\n * @param value the value to check\n * @returns boolean\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;AAO1B,MAAM,YAAY,CAAI,UAC3B,SAAS;AAOJ,MAAM,SAAS,gBAAsB,KAAK,IAAI;AAO9C,MAAM,cAAc,gBAA2B,KAAK,SAAS;AAO7D,MAAM,WAAW,gBAA2B,KAAK,MAAM;AAOvD,MAAM,UAAU,gBAA2B,KAAK,KAAK;AAOrD,MAAM,WAAW,gBAAwB,KAAK,MAAM;AAOpD,MAAM,WAAW,gBAAwB,KAAK,MAAM;AAOpD,MAAM,YAAY,gBAAyB,KAAK,OAAO;AAOvD,MAAM,aAAa;AAAA,EACxB,KAAK;AAAA,EACL,KAAK;AACP;AAOO,MAAM,WAAW,gBAAwB,KAAK,MAAM;AAOpD,MAAM,YAAY,gBAA6B,KAAK,OAAO;AAO3D,MAAM,QAAQ,gBAAwB,KAAK,GAAG;AAS9C,MAAM,aAAa,gBAAwB,KAAK,QAAQ;AASxD,MAAM,WAAW,gBAAwB,KAAK,MAAM;;;;;;;;;;;;;;;;;;;"}
|
package/type-guard.d.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { AnyObject, AnyFunction } from 'yummies/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Check if a value is not null or undefined
|
|
5
|
+
* @param value the value to check
|
|
6
|
+
* @returns boolean
|
|
7
|
+
*/
|
|
8
|
+
declare const isDefined: <T>(value: T | undefined | null) => value is T;
|
|
9
|
+
/**
|
|
10
|
+
* Check if a value is null
|
|
11
|
+
* @param value the value to check
|
|
12
|
+
* @returns boolean
|
|
13
|
+
*/
|
|
14
|
+
declare const isNull: (value: unknown) => value is null;
|
|
15
|
+
/**
|
|
16
|
+
* Check if a value is undefined
|
|
17
|
+
* @param value the value to check
|
|
18
|
+
* @returns boolean
|
|
19
|
+
*/
|
|
20
|
+
declare const isUndefined: (value: unknown) => value is undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Check if a value is an object
|
|
23
|
+
* @param value the value to check
|
|
24
|
+
* @returns boolean
|
|
25
|
+
*/
|
|
26
|
+
declare const isObject: (value: unknown) => value is AnyObject;
|
|
27
|
+
/**
|
|
28
|
+
* Check if a value is an array
|
|
29
|
+
* @param value the value to check
|
|
30
|
+
* @returns boolean
|
|
31
|
+
*/
|
|
32
|
+
declare const isArray: (value: unknown) => value is unknown[];
|
|
33
|
+
/**
|
|
34
|
+
* Check if a value is a string
|
|
35
|
+
* @param value the value to check
|
|
36
|
+
* @returns boolean
|
|
37
|
+
*/
|
|
38
|
+
declare const isString: (value: unknown) => value is string;
|
|
39
|
+
/**
|
|
40
|
+
* Check if a value is a number
|
|
41
|
+
* @param value the value to check
|
|
42
|
+
* @returns boolean
|
|
43
|
+
*/
|
|
44
|
+
declare const isNumber: (value: unknown) => value is number;
|
|
45
|
+
/**
|
|
46
|
+
* Check if a value is a boolean
|
|
47
|
+
* @param value the value to check
|
|
48
|
+
* @returns boolean
|
|
49
|
+
*/
|
|
50
|
+
declare const isBoolean: (value: unknown) => value is boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Check if a value is a function
|
|
53
|
+
* @param value the value to check
|
|
54
|
+
* @returns boolean
|
|
55
|
+
*/
|
|
56
|
+
declare const isFunction: (value: unknown) => value is AnyFunction;
|
|
57
|
+
/**
|
|
58
|
+
* Check if a value is a regular expression
|
|
59
|
+
* @param value the value to check
|
|
60
|
+
* @returns boolean
|
|
61
|
+
*/
|
|
62
|
+
declare const isRegExp: (value: unknown) => value is RegExp;
|
|
63
|
+
/**
|
|
64
|
+
* Check if a value is a DOM element
|
|
65
|
+
* @param value the value to check
|
|
66
|
+
* @returns boolean
|
|
67
|
+
*/
|
|
68
|
+
declare const isElement: (value: unknown) => value is HTMLElement;
|
|
69
|
+
/**
|
|
70
|
+
* Check if a value is NaN
|
|
71
|
+
* @param value the value to check
|
|
72
|
+
* @returns boolean
|
|
73
|
+
*/
|
|
74
|
+
declare const isNaN: (value: unknown) => boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Check if a value is infinity
|
|
77
|
+
* @param value the value to check
|
|
78
|
+
* @returns boolean
|
|
79
|
+
*/
|
|
80
|
+
declare const isInfinite: (value: unknown) => boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Check if a value is a symbol
|
|
83
|
+
* @param value the value to check
|
|
84
|
+
* @returns boolean
|
|
85
|
+
*/
|
|
86
|
+
declare const isSymbol: (value: unknown) => value is symbol;
|
|
87
|
+
|
|
88
|
+
declare const _exports_isArray: typeof isArray;
|
|
89
|
+
declare const _exports_isBoolean: typeof isBoolean;
|
|
90
|
+
declare const _exports_isDefined: typeof isDefined;
|
|
91
|
+
declare const _exports_isElement: typeof isElement;
|
|
92
|
+
declare const _exports_isFunction: typeof isFunction;
|
|
93
|
+
declare const _exports_isInfinite: typeof isInfinite;
|
|
94
|
+
declare const _exports_isNaN: typeof isNaN;
|
|
95
|
+
declare const _exports_isNull: typeof isNull;
|
|
96
|
+
declare const _exports_isNumber: typeof isNumber;
|
|
97
|
+
declare const _exports_isObject: typeof isObject;
|
|
98
|
+
declare const _exports_isRegExp: typeof isRegExp;
|
|
99
|
+
declare const _exports_isString: typeof isString;
|
|
100
|
+
declare const _exports_isSymbol: typeof isSymbol;
|
|
101
|
+
declare const _exports_isUndefined: typeof isUndefined;
|
|
102
|
+
declare namespace _exports {
|
|
103
|
+
export {
|
|
104
|
+
_exports_isArray as isArray,
|
|
105
|
+
_exports_isBoolean as isBoolean,
|
|
106
|
+
_exports_isDefined as isDefined,
|
|
107
|
+
_exports_isElement as isElement,
|
|
108
|
+
_exports_isFunction as isFunction,
|
|
109
|
+
_exports_isInfinite as isInfinite,
|
|
110
|
+
_exports_isNaN as isNaN,
|
|
111
|
+
_exports_isNull as isNull,
|
|
112
|
+
_exports_isNumber as isNumber,
|
|
113
|
+
_exports_isObject as isObject,
|
|
114
|
+
_exports_isRegExp as isRegExp,
|
|
115
|
+
_exports_isString as isString,
|
|
116
|
+
_exports_isSymbol as isSymbol,
|
|
117
|
+
_exports_isUndefined as isUndefined,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export { _exports as typeGuard };
|
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/
|
|
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 * Check if a value is not null or undefined\n * @param value the value to check\n * @returns boolean\n */\nexport const isDefined = <T>(value: T | undefined | null): value is T =>\n value != null;\n\n/**\n * Check if a value is null\n * @param value the value to check\n * @returns boolean\n */\nexport const isNull = createTypeGuard<null>(TYPE.Null);\n\n/**\n * Check if a value is undefined\n * @param value the value to check\n * @returns boolean\n */\nexport const isUndefined = createTypeGuard<undefined>(TYPE.Undefined);\n\n/**\n * Check if a value is an object\n * @param value the value to check\n * @returns boolean\n */\nexport const isObject = createTypeGuard<AnyObject>(TYPE.Object);\n\n/**\n * Check if a value is an array\n * @param value the value to check\n * @returns boolean\n */\nexport const isArray = createTypeGuard<unknown[]>(TYPE.Array);\n\n/**\n * Check if a value is a string\n * @param value the value to check\n * @returns boolean\n */\nexport const isString = createTypeGuard<string>(TYPE.String);\n\n/**\n * Check if a value is a number\n * @param value the value to check\n * @returns boolean\n */\nexport const isNumber = createTypeGuard<number>(TYPE.Number);\n\n/**\n * Check if a value is a boolean\n * @param value the value to check\n * @returns boolean\n */\nexport const isBoolean = createTypeGuard<boolean>(TYPE.Boolean);\n\n/**\n * Check if a value is a function\n * @param value the value to check\n * @returns boolean\n */\nexport const isFunction = createTypeGuard<AnyFunction>(\n TYPE.Function,\n TYPE.AsyncFunction,\n);\n\n/**\n * Check if a value is a regular expression\n * @param value the value to check\n * @returns boolean\n */\nexport const isRegExp = createTypeGuard<RegExp>(TYPE.RegExp);\n\n/**\n * Check if a value is a DOM element\n * @param value the value to check\n * @returns boolean\n */\nexport const isElement = createTypeGuard<HTMLElement>(TYPE.Element);\n\n/**\n * Check if a value is NaN\n * @param value the value to check\n * @returns boolean\n */\nexport const isNaN = createTypeGuard<number>(TYPE.NaN) as (\n value: unknown,\n) => boolean;\n\n/**\n * Check if a value is infinity\n * @param value the value to check\n * @returns boolean\n */\nexport const isInfinite = createTypeGuard<number>(TYPE.Infinite) as (\n value: unknown,\n) => boolean;\n\n/**\n * Check if a value is a symbol\n * @param value the value to check\n * @returns boolean\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;AAO1B,MAAM,YAAY,CAAI,UAC3B,SAAS;AAOJ,MAAM,SAAS,gBAAsB,KAAK,IAAI;AAO9C,MAAM,cAAc,gBAA2B,KAAK,SAAS;AAO7D,MAAM,WAAW,gBAA2B,KAAK,MAAM;AAOvD,MAAM,UAAU,gBAA2B,KAAK,KAAK;AAOrD,MAAM,WAAW,gBAAwB,KAAK,MAAM;AAOpD,MAAM,WAAW,gBAAwB,KAAK,MAAM;AAOpD,MAAM,YAAY,gBAAyB,KAAK,OAAO;AAOvD,MAAM,aAAa;AAAA,EACxB,KAAK;AAAA,EACL,KAAK;AACP;AAOO,MAAM,WAAW,gBAAwB,KAAK,MAAM;AAOpD,MAAM,YAAY,gBAA6B,KAAK,OAAO;AAO3D,MAAM,QAAQ,gBAAwB,KAAK,GAAG;AAS9C,MAAM,aAAa,gBAAwB,KAAK,QAAQ;AASxD,MAAM,WAAW,gBAAwB,KAAK,MAAM;;;;;;;;;;;;;;;;;;"}
|