yummies 3.1.10 → 3.2.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/date-time.js CHANGED
@@ -3,7 +3,7 @@ import duration from 'dayjs/plugin/duration.js';
3
3
  import relativeTime from 'dayjs/plugin/relativeTime.js';
4
4
  import { unitsToMs } from './ms.js';
5
5
  import { declension } from './text.js';
6
- import { typeGuard } from './type-guard.js';
6
+ import { typeGuard } from './type-guard/index.js';
7
7
  import 'dayjs/locale/ru';
8
8
  dayjs.extend(relativeTime);
9
9
  dayjs.extend(duration);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yummies",
3
- "version": "3.1.10",
3
+ "version": "3.2.1",
4
4
  "keywords": [],
5
5
  "author": "js2me",
6
6
  "license": "MIT",
@@ -167,10 +167,20 @@
167
167
  "default": "./text.js",
168
168
  "types": "./text.d.ts"
169
169
  },
170
+ "./type-guard/_exports": {
171
+ "import": "./type-guard/_exports.js",
172
+ "default": "./type-guard/_exports.js",
173
+ "types": "./type-guard/_exports.d.ts"
174
+ },
175
+ "./type-guard/index.test": {
176
+ "import": "./type-guard/index.test.js",
177
+ "default": "./type-guard/index.test.js",
178
+ "types": "./type-guard/index.test.d.ts"
179
+ },
170
180
  "./type-guard": {
171
- "import": "./type-guard.js",
172
- "default": "./type-guard.js",
173
- "types": "./type-guard.d.ts"
181
+ "import": "./type-guard/index.js",
182
+ "default": "./type-guard/index.js",
183
+ "types": "./type-guard/index.d.ts"
174
184
  },
175
185
  "./utils/types": {
176
186
  "import": "./utils/types.js",
@@ -0,0 +1,86 @@
1
+ import { AnyFunction, AnyObject } from '../utils/types.js';
2
+ /**
3
+ * Check if a value is not null or undefined
4
+ * @param value the value to check
5
+ * @returns boolean
6
+ */
7
+ export declare const isDefined: <T>(value: T | undefined | null) => value is T;
8
+ /**
9
+ * Check if a value is null
10
+ * @param value the value to check
11
+ * @returns boolean
12
+ */
13
+ export declare const isNull: (value: unknown) => value is null;
14
+ /**
15
+ * Check if a value is undefined
16
+ * @param value the value to check
17
+ * @returns boolean
18
+ */
19
+ export declare const isUndefined: (value: unknown) => value is undefined;
20
+ /**
21
+ * Check if a value is an object
22
+ * @param value the value to check
23
+ * @returns boolean
24
+ */
25
+ export declare const isObject: (value: unknown) => value is AnyObject;
26
+ /**
27
+ * Check if a value is an array
28
+ * @param value the value to check
29
+ * @returns boolean
30
+ */
31
+ export declare const isArray: (value: unknown) => value is unknown[];
32
+ /**
33
+ * Check if a value is a string
34
+ * @param value the value to check
35
+ * @returns boolean
36
+ */
37
+ export declare const isString: (value: unknown) => value is string;
38
+ /**
39
+ * Check if a value is a number
40
+ * @param value the value to check
41
+ * @returns boolean
42
+ */
43
+ export declare const isNumber: (value: unknown) => value is number;
44
+ /**
45
+ * Check if a value is a boolean
46
+ * @param value the value to check
47
+ * @returns boolean
48
+ */
49
+ export declare const isBoolean: (value: unknown) => value is boolean;
50
+ /**
51
+ * Check if a value is a function
52
+ * @param value the value to check
53
+ * @returns boolean
54
+ */
55
+ export declare const isFunction: (value: unknown) => value is AnyFunction;
56
+ /**
57
+ * Check if a value is a regular expression
58
+ * @param value the value to check
59
+ * @returns boolean
60
+ */
61
+ export declare const isRegExp: (value: unknown) => value is boolean;
62
+ /**
63
+ * Check if a value is a DOM element
64
+ * @param value the value to check
65
+ * @returns boolean
66
+ */
67
+ export declare const isElement: (value: unknown) => value is HTMLElement;
68
+ /**
69
+ * Check if a value is NaN
70
+ * @param value the value to check
71
+ * @returns boolean
72
+ */
73
+ export declare const isNaN: (value: unknown) => value is number;
74
+ /**
75
+ * Check if a value is infinity
76
+ * @param value the value to check
77
+ * @returns boolean
78
+ */
79
+ export declare const isInfinite: (value: unknown) => value is number;
80
+ /**
81
+ * Check if a value is a symbol
82
+ * @param value the value to check
83
+ * @returns boolean
84
+ */
85
+ export declare const isSymbol: (value: unknown) => value is symbol;
86
+ //# sourceMappingURL=_exports.d.ts.map
@@ -0,0 +1 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E;;;;GAIG;AACH,eAAO,MAAM,QAAQ,UApGX,OAAO,KAAG,KAAK,UAoGmC,CAAC"}
@@ -0,0 +1,126 @@
1
+ var Type;
2
+ (function (Type) {
3
+ Type["Null"] = "null";
4
+ Type["Undefined"] = "undefined";
5
+ Type["NaN"] = "nan";
6
+ Type["Object"] = "[object Object]";
7
+ Type["Array"] = "[object Array]";
8
+ Type["String"] = "[object String]";
9
+ Type["Number"] = "[object Number]";
10
+ Type["Boolean"] = "[object Boolean]";
11
+ Type["Function"] = "[object Function]";
12
+ Type["RegExp"] = "[object RegExp]";
13
+ Type["Symbol"] = "[object Symbol]";
14
+ Type["Infinite"] = "infinite";
15
+ Type["Element"] = "element";
16
+ })(Type || (Type = {}));
17
+ function getType(value) {
18
+ if (value === undefined) {
19
+ return Type.Undefined;
20
+ }
21
+ if (value === null) {
22
+ return Type.Null;
23
+ }
24
+ // handle DOM elements
25
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
26
+ // @ts-ignore
27
+ if (value && (value.nodeType === 1 || value.nodeType === 9)) {
28
+ return Type.Element;
29
+ }
30
+ const stringifiedValue = Object.prototype.toString.call(value);
31
+ // handle NaN and Infinity
32
+ if (stringifiedValue === Type.Number) {
33
+ if (Number.isNaN(value)) {
34
+ return Type.NaN;
35
+ }
36
+ if (!Number.isFinite(value)) {
37
+ return Type.Infinite;
38
+ }
39
+ }
40
+ return stringifiedValue;
41
+ }
42
+ const createTypeGuard = (type) => (value) => getType(value) === type;
43
+ /**
44
+ * Check if a value is not null or undefined
45
+ * @param value the value to check
46
+ * @returns boolean
47
+ */
48
+ export const isDefined = (value) => value != null;
49
+ /**
50
+ * Check if a value is null
51
+ * @param value the value to check
52
+ * @returns boolean
53
+ */
54
+ export const isNull = createTypeGuard(Type.Null);
55
+ /**
56
+ * Check if a value is undefined
57
+ * @param value the value to check
58
+ * @returns boolean
59
+ */
60
+ export const isUndefined = createTypeGuard(Type.Undefined);
61
+ /**
62
+ * Check if a value is an object
63
+ * @param value the value to check
64
+ * @returns boolean
65
+ */
66
+ export const isObject = createTypeGuard(Type.Object);
67
+ /**
68
+ * Check if a value is an array
69
+ * @param value the value to check
70
+ * @returns boolean
71
+ */
72
+ export const isArray = createTypeGuard(Type.Array);
73
+ /**
74
+ * Check if a value is a string
75
+ * @param value the value to check
76
+ * @returns boolean
77
+ */
78
+ export const isString = createTypeGuard(Type.String);
79
+ /**
80
+ * Check if a value is a number
81
+ * @param value the value to check
82
+ * @returns boolean
83
+ */
84
+ export const isNumber = createTypeGuard(Type.Number);
85
+ /**
86
+ * Check if a value is a boolean
87
+ * @param value the value to check
88
+ * @returns boolean
89
+ */
90
+ export const isBoolean = createTypeGuard(Type.Boolean);
91
+ /**
92
+ * Check if a value is a function
93
+ * @param value the value to check
94
+ * @returns boolean
95
+ */
96
+ export const isFunction = createTypeGuard(Type.Function);
97
+ /**
98
+ * Check if a value is a regular expression
99
+ * @param value the value to check
100
+ * @returns boolean
101
+ */
102
+ export const isRegExp = createTypeGuard(Type.RegExp);
103
+ /**
104
+ * Check if a value is a DOM element
105
+ * @param value the value to check
106
+ * @returns boolean
107
+ */
108
+ export const isElement = createTypeGuard(Type.Element);
109
+ /**
110
+ * Check if a value is NaN
111
+ * @param value the value to check
112
+ * @returns boolean
113
+ */
114
+ export const isNaN = createTypeGuard(Type.NaN);
115
+ /**
116
+ * Check if a value is infinity
117
+ * @param value the value to check
118
+ * @returns boolean
119
+ */
120
+ export const isInfinite = createTypeGuard(Type.Infinite);
121
+ /**
122
+ * Check if a value is a symbol
123
+ * @param value the value to check
124
+ * @returns boolean
125
+ */
126
+ export const isSymbol = createTypeGuard(Type.Symbol);
@@ -0,0 +1,3 @@
1
+ import * as typeGuard from './_exports.js';
2
+ export { typeGuard };
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/type-guard/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,SAAS,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -0,0 +1,4 @@
1
+ // This way is more treeshakable than collecting
2
+ // it into one exportable object export const typeGuard
3
+ import * as typeGuard from './_exports.js';
4
+ export { typeGuard };
package/type-guard.d.ts DELETED
@@ -1,18 +0,0 @@
1
- import { AnyFunction, AnyObject } from './utils/types.js';
2
- export declare const typeGuard: {
3
- isNull: (value: unknown) => value is null;
4
- isUndefined: (value: unknown) => value is undefined;
5
- isObject: (value: unknown) => value is AnyObject;
6
- isArray: (value: unknown) => value is unknown[];
7
- isString: (value: unknown) => value is string;
8
- isNumber: (value: unknown) => value is number;
9
- isBoolean: (value: unknown) => value is boolean;
10
- isFunction: (value: unknown) => value is AnyFunction;
11
- isRegExp: (value: unknown) => value is boolean;
12
- isElement: (value: unknown) => value is HTMLElement;
13
- isNaN: (value: unknown) => value is number;
14
- isInfinite: (value: unknown) => value is number;
15
- isSymbol: (value: unknown) => value is symbol;
16
- isDefined: <T>(value: T | undefined | null) => value is T;
17
- };
18
- //# sourceMappingURL=type-guard.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"type-guard.d.ts","sourceRoot":"","sources":["../src/type-guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAuD1D,eAAO,MAAM,SAAS;oBALZ,OAAO,KAAG,KAAK,QAAK;yBAApB,OAAO,KAAG,KAAK,aAAK;sBAApB,OAAO,KAAG,KAAK,aAAK;qBAApB,OAAO,KAAG,KAAK,aAAK;sBAApB,OAAO,KAAG,KAAK,UAAK;sBAApB,OAAO,KAAG,KAAK,UAAK;uBAApB,OAAO,KAAG,KAAK,WAAK;wBAApB,OAAO,KAAG,KAAK,eAAK;sBAApB,OAAO,KAAG,KAAK,WAAK;uBAApB,OAAO,KAAG,KAAK,eAAK;mBAApB,OAAO,KAAG,KAAK,UAAK;wBAApB,OAAO,KAAG,KAAK,UAAK;sBAApB,OAAO,KAAG,KAAK,UAAK;gBAGX,CAAC,SAAS,CAAC,GAAG,SAAS,GAAG,IAAI,KAAG,KAAK,IAAI,CAAC;CAiB7D,CAAC"}
package/type-guard.js DELETED
@@ -1,59 +0,0 @@
1
- var Type;
2
- (function (Type) {
3
- Type["Null"] = "null";
4
- Type["Undefined"] = "undefined";
5
- Type["NaN"] = "nan";
6
- Type["Object"] = "[object Object]";
7
- Type["Array"] = "[object Array]";
8
- Type["String"] = "[object String]";
9
- Type["Number"] = "[object Number]";
10
- Type["Boolean"] = "[object Boolean]";
11
- Type["Function"] = "[object Function]";
12
- Type["RegExp"] = "[object RegExp]";
13
- Type["Symbol"] = "[object Symbol]";
14
- Type["Infinite"] = "infinite";
15
- Type["Element"] = "element";
16
- })(Type || (Type = {}));
17
- function getType(value) {
18
- if (value === undefined) {
19
- return Type.Undefined;
20
- }
21
- if (value === null) {
22
- return Type.Null;
23
- }
24
- // handle DOM elements
25
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
26
- // @ts-ignore
27
- if (value && (value.nodeType === 1 || value.nodeType === 9)) {
28
- return Type.Element;
29
- }
30
- const stringifiedValue = Object.prototype.toString.call(value);
31
- // handle NaN and Infinity
32
- if (stringifiedValue === Type.Number) {
33
- if (Number.isNaN(value)) {
34
- return Type.NaN;
35
- }
36
- if (!Number.isFinite(value)) {
37
- return Type.Infinite;
38
- }
39
- }
40
- return stringifiedValue;
41
- }
42
- const createTypeGuard = (type) => (value) => getType(value) === type;
43
- const isDefined = (value) => value != null;
44
- export const typeGuard = {
45
- isNull: createTypeGuard(Type.Null),
46
- isUndefined: createTypeGuard(Type.Undefined),
47
- isObject: createTypeGuard(Type.Object),
48
- isArray: createTypeGuard(Type.Array),
49
- isString: createTypeGuard(Type.String),
50
- isNumber: createTypeGuard(Type.Number),
51
- isBoolean: createTypeGuard(Type.Boolean),
52
- isFunction: createTypeGuard(Type.Function),
53
- isRegExp: createTypeGuard(Type.RegExp),
54
- isElement: createTypeGuard(Type.Element),
55
- isNaN: createTypeGuard(Type.NaN),
56
- isInfinite: createTypeGuard(Type.Infinite),
57
- isSymbol: createTypeGuard(Type.Symbol),
58
- isDefined,
59
- };