@ntnyq/utils 0.4.3 → 0.4.5

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/dist/index.cjs CHANGED
@@ -41,20 +41,28 @@ __export(index_exports, {
41
41
  interopDefault: () => interopDefault,
42
42
  isArray: () => isArray,
43
43
  isArrayEqual: () => isArrayEqual,
44
+ isBigInt: () => isBigInt,
44
45
  isBoolean: () => isBoolean,
45
46
  isBrowser: () => isBrowser,
46
47
  isDeepEqual: () => isDeepEqual,
47
48
  isEmptyArray: () => isEmptyArray,
49
+ isEmptyMap: () => isEmptyMap,
48
50
  isEmptyObject: () => isEmptyObject,
51
+ isEmptySet: () => isEmptySet,
49
52
  isEmptyString: () => isEmptyString,
50
53
  isEmptyStringOrWhitespace: () => isEmptyStringOrWhitespace,
54
+ isError: () => isError,
51
55
  isFunction: () => isFunction,
52
56
  isInteger: () => isInteger,
57
+ isIterable: () => isIterable,
58
+ isMap: () => isMap,
53
59
  isNaN: () => isNaN,
54
60
  isNativePromise: () => isNativePromise,
55
61
  isNil: () => isNil,
62
+ isNonEmptyArray: () => isNonEmptyArray,
56
63
  isNonEmptyString: () => isNonEmptyString,
57
64
  isNull: () => isNull,
65
+ isNullOrUndefined: () => isNullOrUndefined,
58
66
  isNumber: () => isNumber,
59
67
  isNumbericString: () => isNumbericString,
60
68
  isObject: () => isObject,
@@ -134,18 +142,10 @@ function isNull(value) {
134
142
  function isNil(value) {
135
143
  return isNull(value) || isUndefined(value);
136
144
  }
145
+ var isNullOrUndefined = isNil;
137
146
  function isString(value) {
138
147
  return typeof value === "string";
139
148
  }
140
- function isNumber(value) {
141
- return typeof value === "number";
142
- }
143
- function isZero(value) {
144
- return value === 0;
145
- }
146
- function isNaN(value) {
147
- return Number.isNaN(value);
148
- }
149
149
  function isEmptyString(value) {
150
150
  return isString(value) && value.length === 0;
151
151
  }
@@ -161,9 +161,21 @@ function isEmptyStringOrWhitespace(value) {
161
161
  function isNumbericString(value) {
162
162
  return isString(value) && !isEmptyStringOrWhitespace(value) && !Number.isNaN(Number(value));
163
163
  }
164
+ function isNumber(value) {
165
+ return typeof value === "number";
166
+ }
167
+ function isZero(value) {
168
+ return value === 0;
169
+ }
170
+ function isNaN(value) {
171
+ return Number.isNaN(value);
172
+ }
164
173
  function isInteger(value) {
165
174
  return Number.isInteger(value);
166
175
  }
176
+ function isBigInt(value) {
177
+ return typeof value === "bigint";
178
+ }
167
179
  function isBoolean(value) {
168
180
  return typeof value === "boolean";
169
181
  }
@@ -176,27 +188,45 @@ function isArray(value) {
176
188
  function isEmptyArray(value) {
177
189
  return isArray(value) && value.length === 0;
178
190
  }
191
+ function isNonEmptyArray(value) {
192
+ return isArray(value) && value.length > 0;
193
+ }
179
194
  function isObject(value) {
180
- return getObjectType(value) === "Object";
195
+ return (typeof value === "object" || isFunction(value)) && !isNull(value);
181
196
  }
182
197
  function isEmptyObject(value) {
183
- return isObject(value) && Object.keys(value).length === 0;
198
+ return isObject(value) && !isMap(value) && !isSet(value) && Object.keys(value).length === 0;
184
199
  }
185
- function isRegExp(value) {
186
- return getObjectType(value) === "RegExp";
200
+ function isMap(value) {
201
+ return getObjectType(value) === "Map";
202
+ }
203
+ function isEmptyMap(value) {
204
+ return isMap(value) && value.size === 0;
187
205
  }
188
206
  function isSet(value) {
189
207
  return getObjectType(value) === "Set";
190
208
  }
191
- function isNativePromise(value) {
192
- return getObjectType(value) === "Promise";
209
+ function isEmptySet(value) {
210
+ return isSet(value) && value.size === 0;
211
+ }
212
+ function isRegExp(value) {
213
+ return getObjectType(value) === "RegExp";
214
+ }
215
+ function isError(value) {
216
+ return getObjectType(value) === "Error";
193
217
  }
194
218
  function hasPromiseApi(value) {
195
219
  return isFunction(value?.then) && isFunction(value?.catch);
196
220
  }
221
+ function isNativePromise(value) {
222
+ return getObjectType(value) === "Promise";
223
+ }
197
224
  function isPromise(value) {
198
225
  return isNativePromise(value) || hasPromiseApi(value);
199
226
  }
227
+ function isIterable(value) {
228
+ return isFunction(value?.[Symbol.iterator]);
229
+ }
200
230
 
201
231
  // src/fn/noop.ts
202
232
  var noop = () => {
@@ -650,20 +680,28 @@ function resolveSubOptions(options, key) {
650
680
  interopDefault,
651
681
  isArray,
652
682
  isArrayEqual,
683
+ isBigInt,
653
684
  isBoolean,
654
685
  isBrowser,
655
686
  isDeepEqual,
656
687
  isEmptyArray,
688
+ isEmptyMap,
657
689
  isEmptyObject,
690
+ isEmptySet,
658
691
  isEmptyString,
659
692
  isEmptyStringOrWhitespace,
693
+ isError,
660
694
  isFunction,
661
695
  isInteger,
696
+ isIterable,
697
+ isMap,
662
698
  isNaN,
663
699
  isNativePromise,
664
700
  isNil,
701
+ isNonEmptyArray,
665
702
  isNonEmptyString,
666
703
  isNull,
704
+ isNullOrUndefined,
667
705
  isNumber,
668
706
  isNumbericString,
669
707
  isObject,
package/dist/index.d.cts CHANGED
@@ -19,26 +19,34 @@ declare function getObjectType(value: unknown): string;
19
19
  declare function isUndefined(value: unknown): value is undefined;
20
20
  declare function isNull(value: unknown): value is null;
21
21
  declare function isNil(value: unknown): value is null | undefined;
22
+ declare const isNullOrUndefined: typeof isNil;
22
23
  declare function isString(value: unknown): value is string;
23
- declare function isNumber(value: unknown): value is number;
24
- declare function isZero(value: unknown): value is 0;
25
- declare function isNaN(value: unknown): value is typeof Number.NaN;
26
24
  declare function isEmptyString(value: unknown): value is '';
27
25
  declare function isNonEmptyString(value: unknown): value is NonEmptyString;
28
26
  declare function isWhitespaceString(value: unknown): value is Whitespace;
29
27
  declare function isEmptyStringOrWhitespace(value: unknown): value is '' | Whitespace;
30
28
  declare function isNumbericString(value: unknown): value is `${number}`;
29
+ declare function isNumber(value: unknown): value is number;
30
+ declare function isZero(value: unknown): value is 0;
31
+ declare function isNaN(value: unknown): value is typeof Number.NaN;
31
32
  declare function isInteger(value: unknown): value is number;
33
+ declare function isBigInt(value: unknown): value is bigint;
32
34
  declare function isBoolean(value: unknown): value is boolean;
33
35
  declare function isFunction(value: unknown): value is Function;
34
36
  declare function isArray(value: unknown): value is unknown[];
35
37
  declare function isEmptyArray(value: unknown): value is [];
38
+ declare function isNonEmptyArray<T = unknown, Item = unknown>(value: T | Item[]): value is [Item, ...Item[]];
36
39
  declare function isObject(value: unknown): value is object;
37
40
  declare function isEmptyObject(value: unknown): value is {};
38
- declare function isRegExp(value: unknown): value is RegExp;
41
+ declare function isMap<Key = unknown, Value = unknown>(value: unknown): value is Map<Key, Value>;
42
+ declare function isEmptyMap(value: unknown): value is Map<never, never>;
39
43
  declare function isSet<Value = unknown>(value: unknown): value is Set<Value>;
44
+ declare function isEmptySet(value: unknown): value is Set<never>;
45
+ declare function isRegExp(value: unknown): value is RegExp;
46
+ declare function isError(value: unknown): value is Error;
40
47
  declare function isNativePromise<T = unknown>(value: unknown): value is Promise<T>;
41
48
  declare function isPromise<T = unknown>(value: unknown): value is Promise<T>;
49
+ declare function isIterable<T = unknown>(value: unknown): value is Iterable<T>;
42
50
 
43
51
  /**
44
52
  * A function that does nothing.
@@ -420,4 +428,4 @@ declare function interopDefault<T>(mod: Awaitable<T>): Promise<InteropModuleDefa
420
428
  */
421
429
  declare function resolveSubOptions<T extends Record<string, any>, K extends keyof T>(options: T, key: K): Partial<ResolvedOptions<T[K]>>;
422
430
 
423
- export { type AnyFn, type Arrayable, type Awaitable, type Callable, type CleanObjectOptions, type InteropModuleDefault, type JsonArray, type JsonObject, type JsonPrimitive, type JsonValue, type MayBe, NOOP, type NonEmptyString, type Nullable, type Overwrite, type Prettify, type PrettifyV2, type PrimitiveType, type ResolvedOptions, type SortObjectOptions, type ThrottleDebounceOptions, type Whitespace, at, cAF, capitalize, chunk, clamp, cleanObject, days, debounce, ensurePrefix, ensureSuffix, escapeHtml, flattenArrayable, getObjectType, hasOwn, hours, interopDefault, isArray, isArrayEqual, isBoolean, isBrowser, isDeepEqual, isEmptyArray, isEmptyObject, isEmptyString, isEmptyStringOrWhitespace, isFunction, isInteger, isNaN, isNativePromise, isNil, isNonEmptyString, isNull, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isUndefined, isWhitespaceString, isZero, join, last, mergeArrayable, minutes, noop, omit, once, pick, rAF, resolveSubOptions, seconds, slash, sortObject, throttle, toArray, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
431
+ export { type AnyFn, type Arrayable, type Awaitable, type Callable, type CleanObjectOptions, type InteropModuleDefault, type JsonArray, type JsonObject, type JsonPrimitive, type JsonValue, type MayBe, NOOP, type NonEmptyString, type Nullable, type Overwrite, type Prettify, type PrettifyV2, type PrimitiveType, type ResolvedOptions, type SortObjectOptions, type ThrottleDebounceOptions, type Whitespace, at, cAF, capitalize, chunk, clamp, cleanObject, days, debounce, ensurePrefix, ensureSuffix, escapeHtml, flattenArrayable, getObjectType, hasOwn, hours, interopDefault, isArray, isArrayEqual, isBigInt, isBoolean, isBrowser, isDeepEqual, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isEmptyStringOrWhitespace, isError, isFunction, isInteger, isIterable, isMap, isNaN, isNativePromise, isNil, isNonEmptyArray, isNonEmptyString, isNull, isNullOrUndefined, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isUndefined, isWhitespaceString, isZero, join, last, mergeArrayable, minutes, noop, omit, once, pick, rAF, resolveSubOptions, seconds, slash, sortObject, throttle, toArray, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
package/dist/index.d.ts CHANGED
@@ -19,26 +19,34 @@ declare function getObjectType(value: unknown): string;
19
19
  declare function isUndefined(value: unknown): value is undefined;
20
20
  declare function isNull(value: unknown): value is null;
21
21
  declare function isNil(value: unknown): value is null | undefined;
22
+ declare const isNullOrUndefined: typeof isNil;
22
23
  declare function isString(value: unknown): value is string;
23
- declare function isNumber(value: unknown): value is number;
24
- declare function isZero(value: unknown): value is 0;
25
- declare function isNaN(value: unknown): value is typeof Number.NaN;
26
24
  declare function isEmptyString(value: unknown): value is '';
27
25
  declare function isNonEmptyString(value: unknown): value is NonEmptyString;
28
26
  declare function isWhitespaceString(value: unknown): value is Whitespace;
29
27
  declare function isEmptyStringOrWhitespace(value: unknown): value is '' | Whitespace;
30
28
  declare function isNumbericString(value: unknown): value is `${number}`;
29
+ declare function isNumber(value: unknown): value is number;
30
+ declare function isZero(value: unknown): value is 0;
31
+ declare function isNaN(value: unknown): value is typeof Number.NaN;
31
32
  declare function isInteger(value: unknown): value is number;
33
+ declare function isBigInt(value: unknown): value is bigint;
32
34
  declare function isBoolean(value: unknown): value is boolean;
33
35
  declare function isFunction(value: unknown): value is Function;
34
36
  declare function isArray(value: unknown): value is unknown[];
35
37
  declare function isEmptyArray(value: unknown): value is [];
38
+ declare function isNonEmptyArray<T = unknown, Item = unknown>(value: T | Item[]): value is [Item, ...Item[]];
36
39
  declare function isObject(value: unknown): value is object;
37
40
  declare function isEmptyObject(value: unknown): value is {};
38
- declare function isRegExp(value: unknown): value is RegExp;
41
+ declare function isMap<Key = unknown, Value = unknown>(value: unknown): value is Map<Key, Value>;
42
+ declare function isEmptyMap(value: unknown): value is Map<never, never>;
39
43
  declare function isSet<Value = unknown>(value: unknown): value is Set<Value>;
44
+ declare function isEmptySet(value: unknown): value is Set<never>;
45
+ declare function isRegExp(value: unknown): value is RegExp;
46
+ declare function isError(value: unknown): value is Error;
40
47
  declare function isNativePromise<T = unknown>(value: unknown): value is Promise<T>;
41
48
  declare function isPromise<T = unknown>(value: unknown): value is Promise<T>;
49
+ declare function isIterable<T = unknown>(value: unknown): value is Iterable<T>;
42
50
 
43
51
  /**
44
52
  * A function that does nothing.
@@ -420,4 +428,4 @@ declare function interopDefault<T>(mod: Awaitable<T>): Promise<InteropModuleDefa
420
428
  */
421
429
  declare function resolveSubOptions<T extends Record<string, any>, K extends keyof T>(options: T, key: K): Partial<ResolvedOptions<T[K]>>;
422
430
 
423
- export { type AnyFn, type Arrayable, type Awaitable, type Callable, type CleanObjectOptions, type InteropModuleDefault, type JsonArray, type JsonObject, type JsonPrimitive, type JsonValue, type MayBe, NOOP, type NonEmptyString, type Nullable, type Overwrite, type Prettify, type PrettifyV2, type PrimitiveType, type ResolvedOptions, type SortObjectOptions, type ThrottleDebounceOptions, type Whitespace, at, cAF, capitalize, chunk, clamp, cleanObject, days, debounce, ensurePrefix, ensureSuffix, escapeHtml, flattenArrayable, getObjectType, hasOwn, hours, interopDefault, isArray, isArrayEqual, isBoolean, isBrowser, isDeepEqual, isEmptyArray, isEmptyObject, isEmptyString, isEmptyStringOrWhitespace, isFunction, isInteger, isNaN, isNativePromise, isNil, isNonEmptyString, isNull, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isUndefined, isWhitespaceString, isZero, join, last, mergeArrayable, minutes, noop, omit, once, pick, rAF, resolveSubOptions, seconds, slash, sortObject, throttle, toArray, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
431
+ export { type AnyFn, type Arrayable, type Awaitable, type Callable, type CleanObjectOptions, type InteropModuleDefault, type JsonArray, type JsonObject, type JsonPrimitive, type JsonValue, type MayBe, NOOP, type NonEmptyString, type Nullable, type Overwrite, type Prettify, type PrettifyV2, type PrimitiveType, type ResolvedOptions, type SortObjectOptions, type ThrottleDebounceOptions, type Whitespace, at, cAF, capitalize, chunk, clamp, cleanObject, days, debounce, ensurePrefix, ensureSuffix, escapeHtml, flattenArrayable, getObjectType, hasOwn, hours, interopDefault, isArray, isArrayEqual, isBigInt, isBoolean, isBrowser, isDeepEqual, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isEmptyStringOrWhitespace, isError, isFunction, isInteger, isIterable, isMap, isNaN, isNativePromise, isNil, isNonEmptyArray, isNonEmptyString, isNull, isNullOrUndefined, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isUndefined, isWhitespaceString, isZero, join, last, mergeArrayable, minutes, noop, omit, once, pick, rAF, resolveSubOptions, seconds, slash, sortObject, throttle, toArray, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
package/dist/index.js CHANGED
@@ -34,18 +34,10 @@ function isNull(value) {
34
34
  function isNil(value) {
35
35
  return isNull(value) || isUndefined(value);
36
36
  }
37
+ var isNullOrUndefined = isNil;
37
38
  function isString(value) {
38
39
  return typeof value === "string";
39
40
  }
40
- function isNumber(value) {
41
- return typeof value === "number";
42
- }
43
- function isZero(value) {
44
- return value === 0;
45
- }
46
- function isNaN(value) {
47
- return Number.isNaN(value);
48
- }
49
41
  function isEmptyString(value) {
50
42
  return isString(value) && value.length === 0;
51
43
  }
@@ -61,9 +53,21 @@ function isEmptyStringOrWhitespace(value) {
61
53
  function isNumbericString(value) {
62
54
  return isString(value) && !isEmptyStringOrWhitespace(value) && !Number.isNaN(Number(value));
63
55
  }
56
+ function isNumber(value) {
57
+ return typeof value === "number";
58
+ }
59
+ function isZero(value) {
60
+ return value === 0;
61
+ }
62
+ function isNaN(value) {
63
+ return Number.isNaN(value);
64
+ }
64
65
  function isInteger(value) {
65
66
  return Number.isInteger(value);
66
67
  }
68
+ function isBigInt(value) {
69
+ return typeof value === "bigint";
70
+ }
67
71
  function isBoolean(value) {
68
72
  return typeof value === "boolean";
69
73
  }
@@ -76,27 +80,45 @@ function isArray(value) {
76
80
  function isEmptyArray(value) {
77
81
  return isArray(value) && value.length === 0;
78
82
  }
83
+ function isNonEmptyArray(value) {
84
+ return isArray(value) && value.length > 0;
85
+ }
79
86
  function isObject(value) {
80
- return getObjectType(value) === "Object";
87
+ return (typeof value === "object" || isFunction(value)) && !isNull(value);
81
88
  }
82
89
  function isEmptyObject(value) {
83
- return isObject(value) && Object.keys(value).length === 0;
90
+ return isObject(value) && !isMap(value) && !isSet(value) && Object.keys(value).length === 0;
84
91
  }
85
- function isRegExp(value) {
86
- return getObjectType(value) === "RegExp";
92
+ function isMap(value) {
93
+ return getObjectType(value) === "Map";
94
+ }
95
+ function isEmptyMap(value) {
96
+ return isMap(value) && value.size === 0;
87
97
  }
88
98
  function isSet(value) {
89
99
  return getObjectType(value) === "Set";
90
100
  }
91
- function isNativePromise(value) {
92
- return getObjectType(value) === "Promise";
101
+ function isEmptySet(value) {
102
+ return isSet(value) && value.size === 0;
103
+ }
104
+ function isRegExp(value) {
105
+ return getObjectType(value) === "RegExp";
106
+ }
107
+ function isError(value) {
108
+ return getObjectType(value) === "Error";
93
109
  }
94
110
  function hasPromiseApi(value) {
95
111
  return isFunction(value?.then) && isFunction(value?.catch);
96
112
  }
113
+ function isNativePromise(value) {
114
+ return getObjectType(value) === "Promise";
115
+ }
97
116
  function isPromise(value) {
98
117
  return isNativePromise(value) || hasPromiseApi(value);
99
118
  }
119
+ function isIterable(value) {
120
+ return isFunction(value?.[Symbol.iterator]);
121
+ }
100
122
 
101
123
  // src/fn/noop.ts
102
124
  var noop = () => {
@@ -549,20 +571,28 @@ export {
549
571
  interopDefault,
550
572
  isArray,
551
573
  isArrayEqual,
574
+ isBigInt,
552
575
  isBoolean,
553
576
  isBrowser,
554
577
  isDeepEqual,
555
578
  isEmptyArray,
579
+ isEmptyMap,
556
580
  isEmptyObject,
581
+ isEmptySet,
557
582
  isEmptyString,
558
583
  isEmptyStringOrWhitespace,
584
+ isError,
559
585
  isFunction,
560
586
  isInteger,
587
+ isIterable,
588
+ isMap,
561
589
  isNaN,
562
590
  isNativePromise,
563
591
  isNil,
592
+ isNonEmptyArray,
564
593
  isNonEmptyString,
565
594
  isNull,
595
+ isNullOrUndefined,
566
596
  isNumber,
567
597
  isNumbericString,
568
598
  isObject,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ntnyq/utils",
3
3
  "type": "module",
4
- "version": "0.4.3",
4
+ "version": "0.4.5",
5
5
  "description": "Common used utils.",
6
6
  "keywords": [
7
7
  "utils"