@ntnyq/utils 0.3.1 → 0.3.3
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 +122 -113
- package/dist/index.d.cts +122 -30
- package/dist/index.d.ts +122 -30
- package/dist/index.js +200 -102
- package/package.json +8 -9
package/dist/index.cjs
CHANGED
|
@@ -15,6 +15,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
}
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
20
|
|
|
20
21
|
// src/index.ts
|
|
@@ -23,15 +24,14 @@ __export(src_exports, {
|
|
|
23
24
|
NOOP: () => NOOP,
|
|
24
25
|
at: () => at,
|
|
25
26
|
cAF: () => cAF,
|
|
26
|
-
camelCase: () => camelCase,
|
|
27
27
|
capitalize: () => capitalize,
|
|
28
28
|
chunk: () => chunk,
|
|
29
29
|
clamp: () => clamp,
|
|
30
|
+
cleanObject: () => cleanObject,
|
|
30
31
|
days: () => days,
|
|
31
32
|
debounce: () => debounce,
|
|
32
33
|
ensurePrefix: () => ensurePrefix,
|
|
33
34
|
ensureSuffix: () => ensureSuffix,
|
|
34
|
-
flatCase: () => flatCase,
|
|
35
35
|
flattenArrayable: () => flattenArrayable,
|
|
36
36
|
getObjectType: () => getObjectType,
|
|
37
37
|
hasOwn: () => hasOwn,
|
|
@@ -40,10 +40,14 @@ __export(src_exports, {
|
|
|
40
40
|
isArrayEqual: () => isArrayEqual,
|
|
41
41
|
isBoolean: () => isBoolean,
|
|
42
42
|
isBrowser: () => isBrowser,
|
|
43
|
+
isDeepEqual: () => isDeepEqual,
|
|
44
|
+
isEmptyArray: () => isEmptyArray,
|
|
45
|
+
isEmptyObject: () => isEmptyObject,
|
|
43
46
|
isEmptyString: () => isEmptyString,
|
|
44
47
|
isEmptyStringOrWhitespace: () => isEmptyStringOrWhitespace,
|
|
45
48
|
isFunction: () => isFunction,
|
|
46
49
|
isInteger: () => isInteger,
|
|
50
|
+
isNaN: () => isNaN,
|
|
47
51
|
isNativePromise: () => isNativePromise,
|
|
48
52
|
isNil: () => isNil,
|
|
49
53
|
isNonEmptyString: () => isNonEmptyString,
|
|
@@ -56,49 +60,79 @@ __export(src_exports, {
|
|
|
56
60
|
isSet: () => isSet,
|
|
57
61
|
isString: () => isString,
|
|
58
62
|
isUndefined: () => isUndefined,
|
|
59
|
-
isUppercase: () => isUppercase,
|
|
60
63
|
isWhitespaceString: () => isWhitespaceString,
|
|
64
|
+
isZero: () => isZero,
|
|
61
65
|
join: () => join,
|
|
62
|
-
kebabCase: () => kebabCase,
|
|
63
66
|
last: () => last,
|
|
64
|
-
lowerFirst: () => lowerFirst,
|
|
65
67
|
mergeArrayable: () => mergeArrayable,
|
|
66
68
|
minutes: () => minutes,
|
|
67
69
|
noop: () => noop,
|
|
68
70
|
omit: () => omit,
|
|
69
71
|
once: () => once,
|
|
70
|
-
pascalCase: () => pascalCase,
|
|
71
72
|
pick: () => pick,
|
|
72
73
|
rAF: () => rAF,
|
|
73
74
|
seconds: () => seconds,
|
|
74
75
|
slash: () => slash,
|
|
75
|
-
snakeCase: () => snakeCase,
|
|
76
76
|
sortObject: () => sortObject,
|
|
77
|
-
splitByCase: () => splitByCase,
|
|
78
77
|
throttle: () => throttle,
|
|
79
|
-
titleCase: () => titleCase,
|
|
80
78
|
toArray: () => toArray,
|
|
81
|
-
trainCase: () => trainCase,
|
|
82
79
|
unindent: () => unindent,
|
|
83
80
|
unique: () => unique,
|
|
84
81
|
uniqueBy: () => uniqueBy,
|
|
85
|
-
upperFirst: () => upperFirst,
|
|
86
82
|
waitFor: () => waitFor,
|
|
87
83
|
warnOnce: () => warnOnce,
|
|
88
84
|
weeks: () => weeks
|
|
89
85
|
});
|
|
90
86
|
module.exports = __toCommonJS(src_exports);
|
|
91
87
|
|
|
88
|
+
// src/is/isDeepEqual.ts
|
|
89
|
+
function isDeepEqual(value1, value2) {
|
|
90
|
+
const type1 = getObjectType(value1);
|
|
91
|
+
const type2 = getObjectType(value2);
|
|
92
|
+
if (type1 !== type2) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
if (isArray(value1)) {
|
|
96
|
+
if (value1.length !== value2.length) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
return value1.every((item, index) => isDeepEqual(item, value2[index]));
|
|
100
|
+
}
|
|
101
|
+
if (isObject(value1)) {
|
|
102
|
+
const keys = Object.keys(value1);
|
|
103
|
+
if (keys.length !== Object.keys(value2).length) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
return keys.every((key) => isDeepEqual(value1[key], value2[key]));
|
|
107
|
+
}
|
|
108
|
+
return Object.is(value1, value2);
|
|
109
|
+
}
|
|
110
|
+
|
|
92
111
|
// src/is/index.ts
|
|
93
112
|
function getObjectType(value) {
|
|
94
113
|
return Object.prototype.toString.call(value).slice(8, -1);
|
|
95
114
|
}
|
|
115
|
+
function isUndefined(value) {
|
|
116
|
+
return value === void 0;
|
|
117
|
+
}
|
|
118
|
+
function isNull(value) {
|
|
119
|
+
return value === null;
|
|
120
|
+
}
|
|
121
|
+
function isNil(value) {
|
|
122
|
+
return isNull(value) || isUndefined(value);
|
|
123
|
+
}
|
|
96
124
|
function isString(value) {
|
|
97
125
|
return typeof value === "string";
|
|
98
126
|
}
|
|
99
127
|
function isNumber(value) {
|
|
100
128
|
return typeof value === "number";
|
|
101
129
|
}
|
|
130
|
+
function isZero(value) {
|
|
131
|
+
return value === 0;
|
|
132
|
+
}
|
|
133
|
+
function isNaN(value) {
|
|
134
|
+
return Number.isNaN(value);
|
|
135
|
+
}
|
|
102
136
|
function isEmptyString(value) {
|
|
103
137
|
return isString(value) && value.length === 0;
|
|
104
138
|
}
|
|
@@ -126,18 +160,15 @@ function isFunction(value) {
|
|
|
126
160
|
function isArray(value) {
|
|
127
161
|
return Array.isArray(value);
|
|
128
162
|
}
|
|
129
|
-
function
|
|
130
|
-
return value ===
|
|
131
|
-
}
|
|
132
|
-
function isNull(value) {
|
|
133
|
-
return value === null;
|
|
134
|
-
}
|
|
135
|
-
function isNil(value) {
|
|
136
|
-
return isNull(value) || isUndefined(value);
|
|
163
|
+
function isEmptyArray(value) {
|
|
164
|
+
return isArray(value) && value.length === 0;
|
|
137
165
|
}
|
|
138
166
|
function isObject(value) {
|
|
139
167
|
return getObjectType(value) === "Object";
|
|
140
168
|
}
|
|
169
|
+
function isEmptyObject(value) {
|
|
170
|
+
return isObject(value) && Object.keys(value).length === 0;
|
|
171
|
+
}
|
|
141
172
|
function isRegExp(value) {
|
|
142
173
|
return getObjectType(value) === "RegExp";
|
|
143
174
|
}
|
|
@@ -175,89 +206,6 @@ function once(func) {
|
|
|
175
206
|
// src/env/isBrowser.ts
|
|
176
207
|
var isBrowser = () => typeof document !== "undefined";
|
|
177
208
|
|
|
178
|
-
// node_modules/.pnpm/scule@1.3.0/node_modules/scule/dist/index.mjs
|
|
179
|
-
var NUMBER_CHAR_RE = /\d/;
|
|
180
|
-
var STR_SPLITTERS = ["-", "_", "/", "."];
|
|
181
|
-
function isUppercase(char = "") {
|
|
182
|
-
if (NUMBER_CHAR_RE.test(char)) {
|
|
183
|
-
return void 0;
|
|
184
|
-
}
|
|
185
|
-
return char !== char.toLowerCase();
|
|
186
|
-
}
|
|
187
|
-
function splitByCase(str, separators) {
|
|
188
|
-
const splitters = separators ?? STR_SPLITTERS;
|
|
189
|
-
const parts = [];
|
|
190
|
-
if (!str || typeof str !== "string") {
|
|
191
|
-
return parts;
|
|
192
|
-
}
|
|
193
|
-
let buff = "";
|
|
194
|
-
let previousUpper;
|
|
195
|
-
let previousSplitter;
|
|
196
|
-
for (const char of str) {
|
|
197
|
-
const isSplitter = splitters.includes(char);
|
|
198
|
-
if (isSplitter === true) {
|
|
199
|
-
parts.push(buff);
|
|
200
|
-
buff = "";
|
|
201
|
-
previousUpper = void 0;
|
|
202
|
-
continue;
|
|
203
|
-
}
|
|
204
|
-
const isUpper = isUppercase(char);
|
|
205
|
-
if (previousSplitter === false) {
|
|
206
|
-
if (previousUpper === false && isUpper === true) {
|
|
207
|
-
parts.push(buff);
|
|
208
|
-
buff = char;
|
|
209
|
-
previousUpper = isUpper;
|
|
210
|
-
continue;
|
|
211
|
-
}
|
|
212
|
-
if (previousUpper === true && isUpper === false && buff.length > 1) {
|
|
213
|
-
const lastChar = buff.at(-1);
|
|
214
|
-
parts.push(buff.slice(0, Math.max(0, buff.length - 1)));
|
|
215
|
-
buff = lastChar + char;
|
|
216
|
-
previousUpper = isUpper;
|
|
217
|
-
continue;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
buff += char;
|
|
221
|
-
previousUpper = isUpper;
|
|
222
|
-
previousSplitter = isSplitter;
|
|
223
|
-
}
|
|
224
|
-
parts.push(buff);
|
|
225
|
-
return parts;
|
|
226
|
-
}
|
|
227
|
-
function upperFirst(str) {
|
|
228
|
-
return str ? str[0].toUpperCase() + str.slice(1) : "";
|
|
229
|
-
}
|
|
230
|
-
function lowerFirst(str) {
|
|
231
|
-
return str ? str[0].toLowerCase() + str.slice(1) : "";
|
|
232
|
-
}
|
|
233
|
-
function pascalCase(str, opts) {
|
|
234
|
-
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => upperFirst(opts?.normalize ? p.toLowerCase() : p)).join("") : "";
|
|
235
|
-
}
|
|
236
|
-
function camelCase(str, opts) {
|
|
237
|
-
return lowerFirst(pascalCase(str || "", opts));
|
|
238
|
-
}
|
|
239
|
-
function kebabCase(str, joiner) {
|
|
240
|
-
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => p.toLowerCase()).join(joiner ?? "-") : "";
|
|
241
|
-
}
|
|
242
|
-
function snakeCase(str) {
|
|
243
|
-
return kebabCase(str || "", "_");
|
|
244
|
-
}
|
|
245
|
-
function flatCase(str) {
|
|
246
|
-
return kebabCase(str || "", "");
|
|
247
|
-
}
|
|
248
|
-
function trainCase(str, opts) {
|
|
249
|
-
return (Array.isArray(str) ? str : splitByCase(str)).filter(Boolean).map((p) => upperFirst(opts?.normalize ? p.toLowerCase() : p)).join("-");
|
|
250
|
-
}
|
|
251
|
-
var titleCaseExceptions = /^(a|an|and|as|at|but|by|for|if|in|is|nor|of|on|or|the|to|with)$/i;
|
|
252
|
-
function titleCase(str, opts) {
|
|
253
|
-
return (Array.isArray(str) ? str : splitByCase(str)).filter(Boolean).map(
|
|
254
|
-
(p) => titleCaseExceptions.test(p) ? p.toLowerCase() : upperFirst(opts?.normalize ? p.toLowerCase() : p)
|
|
255
|
-
).join(" ");
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// src/case.ts
|
|
259
|
-
var capitalize = upperFirst;
|
|
260
|
-
|
|
261
209
|
// src/misc/raf.ts
|
|
262
210
|
var root = isBrowser() ? window : globalThis;
|
|
263
211
|
var prev = Date.now();
|
|
@@ -477,6 +425,9 @@ function omit(object, ...keys) {
|
|
|
477
425
|
|
|
478
426
|
// src/object/hasOwn.ts
|
|
479
427
|
function hasOwn(object, key) {
|
|
428
|
+
if (object === null) {
|
|
429
|
+
return false;
|
|
430
|
+
}
|
|
480
431
|
return Object.prototype.hasOwnProperty.call(object, key);
|
|
481
432
|
}
|
|
482
433
|
|
|
@@ -492,6 +443,48 @@ function pick(object, keys) {
|
|
|
492
443
|
);
|
|
493
444
|
}
|
|
494
445
|
|
|
446
|
+
// src/object/clean.ts
|
|
447
|
+
function cleanObject(obj, options = {}) {
|
|
448
|
+
const {
|
|
449
|
+
cleanUndefined = true,
|
|
450
|
+
cleanNull = true,
|
|
451
|
+
cleanZero = false,
|
|
452
|
+
cleanNaN = true,
|
|
453
|
+
cleanEmptyString = true,
|
|
454
|
+
cleanEmptyArray = true,
|
|
455
|
+
cleanEmptyObject = true,
|
|
456
|
+
recursive = true
|
|
457
|
+
} = options;
|
|
458
|
+
Object.keys(obj).forEach((key) => {
|
|
459
|
+
const v = obj[key];
|
|
460
|
+
if (cleanUndefined && isUndefined(v)) {
|
|
461
|
+
delete obj[key];
|
|
462
|
+
}
|
|
463
|
+
if (cleanNull && isNull(v)) {
|
|
464
|
+
delete obj[key];
|
|
465
|
+
}
|
|
466
|
+
if (cleanZero && isZero(v)) {
|
|
467
|
+
delete obj[key];
|
|
468
|
+
}
|
|
469
|
+
if (cleanNaN && isZero(v)) {
|
|
470
|
+
delete obj[key];
|
|
471
|
+
}
|
|
472
|
+
if (cleanEmptyString && isEmptyString(v)) {
|
|
473
|
+
delete obj[key];
|
|
474
|
+
}
|
|
475
|
+
if (cleanEmptyArray && isEmptyArray(v)) {
|
|
476
|
+
delete obj[key];
|
|
477
|
+
}
|
|
478
|
+
if (cleanEmptyObject && isEmptyObject(v)) {
|
|
479
|
+
delete obj[key];
|
|
480
|
+
}
|
|
481
|
+
if (recursive && isObject(v)) {
|
|
482
|
+
cleanObject(v, options);
|
|
483
|
+
}
|
|
484
|
+
});
|
|
485
|
+
return obj;
|
|
486
|
+
}
|
|
487
|
+
|
|
495
488
|
// src/object/isPlainObject.ts
|
|
496
489
|
function isPlainObject(value) {
|
|
497
490
|
if (!isObject(value)) return false;
|
|
@@ -522,20 +515,40 @@ function sortObject(obj, options = {}) {
|
|
|
522
515
|
}
|
|
523
516
|
return sortKeys(obj);
|
|
524
517
|
}
|
|
518
|
+
|
|
519
|
+
// src/vendor/index.ts
|
|
520
|
+
var vendor_exports = {};
|
|
521
|
+
__export(vendor_exports, {
|
|
522
|
+
capitalize: () => capitalize
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
// src/vendor/scule.ts
|
|
526
|
+
var scule_exports = {};
|
|
527
|
+
__export(scule_exports, {
|
|
528
|
+
capitalize: () => capitalize
|
|
529
|
+
});
|
|
530
|
+
var import_scule = require("scule");
|
|
531
|
+
__reExport(scule_exports, require("scule"));
|
|
532
|
+
var capitalize = import_scule.upperFirst;
|
|
533
|
+
|
|
534
|
+
// src/vendor/index.ts
|
|
535
|
+
__reExport(vendor_exports, scule_exports);
|
|
536
|
+
|
|
537
|
+
// src/index.ts
|
|
538
|
+
__reExport(src_exports, vendor_exports, module.exports);
|
|
525
539
|
// Annotate the CommonJS export names for ESM import in node:
|
|
526
540
|
0 && (module.exports = {
|
|
527
541
|
NOOP,
|
|
528
542
|
at,
|
|
529
543
|
cAF,
|
|
530
|
-
camelCase,
|
|
531
544
|
capitalize,
|
|
532
545
|
chunk,
|
|
533
546
|
clamp,
|
|
547
|
+
cleanObject,
|
|
534
548
|
days,
|
|
535
549
|
debounce,
|
|
536
550
|
ensurePrefix,
|
|
537
551
|
ensureSuffix,
|
|
538
|
-
flatCase,
|
|
539
552
|
flattenArrayable,
|
|
540
553
|
getObjectType,
|
|
541
554
|
hasOwn,
|
|
@@ -544,10 +557,14 @@ function sortObject(obj, options = {}) {
|
|
|
544
557
|
isArrayEqual,
|
|
545
558
|
isBoolean,
|
|
546
559
|
isBrowser,
|
|
560
|
+
isDeepEqual,
|
|
561
|
+
isEmptyArray,
|
|
562
|
+
isEmptyObject,
|
|
547
563
|
isEmptyString,
|
|
548
564
|
isEmptyStringOrWhitespace,
|
|
549
565
|
isFunction,
|
|
550
566
|
isInteger,
|
|
567
|
+
isNaN,
|
|
551
568
|
isNativePromise,
|
|
552
569
|
isNil,
|
|
553
570
|
isNonEmptyString,
|
|
@@ -560,33 +577,25 @@ function sortObject(obj, options = {}) {
|
|
|
560
577
|
isSet,
|
|
561
578
|
isString,
|
|
562
579
|
isUndefined,
|
|
563
|
-
isUppercase,
|
|
564
580
|
isWhitespaceString,
|
|
581
|
+
isZero,
|
|
565
582
|
join,
|
|
566
|
-
kebabCase,
|
|
567
583
|
last,
|
|
568
|
-
lowerFirst,
|
|
569
584
|
mergeArrayable,
|
|
570
585
|
minutes,
|
|
571
586
|
noop,
|
|
572
587
|
omit,
|
|
573
588
|
once,
|
|
574
|
-
pascalCase,
|
|
575
589
|
pick,
|
|
576
590
|
rAF,
|
|
577
591
|
seconds,
|
|
578
592
|
slash,
|
|
579
|
-
snakeCase,
|
|
580
593
|
sortObject,
|
|
581
|
-
splitByCase,
|
|
582
594
|
throttle,
|
|
583
|
-
titleCase,
|
|
584
595
|
toArray,
|
|
585
|
-
trainCase,
|
|
586
596
|
unindent,
|
|
587
597
|
unique,
|
|
588
598
|
uniqueBy,
|
|
589
|
-
upperFirst,
|
|
590
599
|
waitFor,
|
|
591
600
|
warnOnce,
|
|
592
601
|
weeks
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { upperFirst } from 'scule';
|
|
2
2
|
export * from 'scule';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* check if two values are deeply equal
|
|
6
|
+
*/
|
|
7
|
+
declare function isDeepEqual(value1: any, value2: any): boolean;
|
|
8
|
+
|
|
4
9
|
/**
|
|
5
10
|
* @file is utils
|
|
6
|
-
* @
|
|
11
|
+
* @module is
|
|
7
12
|
* @copyright {@link https://github.com/sindresorhus/is}
|
|
8
13
|
*/
|
|
9
14
|
type Whitespace = ' ';
|
|
@@ -11,8 +16,13 @@ type NonEmptyString = string & {
|
|
|
11
16
|
0: '';
|
|
12
17
|
};
|
|
13
18
|
declare function getObjectType(value: unknown): string;
|
|
19
|
+
declare function isUndefined(value: unknown): value is undefined;
|
|
20
|
+
declare function isNull(value: unknown): value is null;
|
|
21
|
+
declare function isNil(value: unknown): value is null | undefined;
|
|
14
22
|
declare function isString(value: unknown): value is string;
|
|
15
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;
|
|
16
26
|
declare function isEmptyString(value: unknown): value is '';
|
|
17
27
|
declare function isNonEmptyString(value: unknown): value is NonEmptyString;
|
|
18
28
|
declare function isWhitespaceString(value: unknown): value is Whitespace;
|
|
@@ -22,10 +32,9 @@ declare function isInteger(value: unknown): value is number;
|
|
|
22
32
|
declare function isBoolean(value: unknown): value is boolean;
|
|
23
33
|
declare function isFunction(value: unknown): value is Function;
|
|
24
34
|
declare function isArray(value: unknown): value is unknown[];
|
|
25
|
-
declare function
|
|
26
|
-
declare function isNull(value: unknown): value is null;
|
|
27
|
-
declare function isNil(value: unknown): value is null | undefined;
|
|
35
|
+
declare function isEmptyArray(value: unknown): value is [];
|
|
28
36
|
declare function isObject(value: unknown): value is object;
|
|
37
|
+
declare function isEmptyObject(value: unknown): value is {};
|
|
29
38
|
declare function isRegExp(value: unknown): value is RegExp;
|
|
30
39
|
declare function isSet<Value = unknown>(value: unknown): value is Set<Value>;
|
|
31
40
|
declare function isNativePromise<T = unknown>(value: unknown): value is Promise<T>;
|
|
@@ -52,36 +61,27 @@ declare function once<T extends unknown[]>(func: (...args: T) => void): (this: u
|
|
|
52
61
|
*/
|
|
53
62
|
declare const isBrowser: () => boolean;
|
|
54
63
|
|
|
55
|
-
/**
|
|
56
|
-
* @file case utils
|
|
57
|
-
* @category Case
|
|
58
|
-
*/
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* @deprecated use upperFirst instead
|
|
62
|
-
*/
|
|
63
|
-
declare const capitalize: typeof upperFirst;
|
|
64
|
-
|
|
65
64
|
/**
|
|
66
65
|
* @file raf.ts
|
|
67
66
|
*/
|
|
68
67
|
/**
|
|
69
68
|
* Request animation frame
|
|
70
69
|
*
|
|
71
|
-
* @param fn callback
|
|
70
|
+
* @param fn - callback
|
|
72
71
|
* @returns id
|
|
73
72
|
*/
|
|
74
73
|
declare function rAF(fn: FrameRequestCallback): number;
|
|
75
74
|
/**
|
|
76
75
|
* Cancel animation frame
|
|
77
76
|
*
|
|
78
|
-
* @param id id
|
|
77
|
+
* @param id - id
|
|
79
78
|
* @returns void
|
|
80
79
|
*/
|
|
81
80
|
declare function cAF(id: number): void;
|
|
82
81
|
|
|
83
82
|
/**
|
|
84
|
-
* @
|
|
83
|
+
* @file time utils
|
|
84
|
+
* @module Time
|
|
85
85
|
*/
|
|
86
86
|
declare function seconds(count: number): number;
|
|
87
87
|
declare function minutes(count: number): number;
|
|
@@ -91,9 +91,9 @@ declare function weeks(count: number): number;
|
|
|
91
91
|
|
|
92
92
|
/**
|
|
93
93
|
* Clamps a number between a minimum and maximum value
|
|
94
|
-
* @param value the value to clamp within the given range
|
|
95
|
-
* @param min the minimum value to clamp
|
|
96
|
-
* @param max the maximum value to clamp
|
|
94
|
+
* @param value - the value to clamp within the given range
|
|
95
|
+
* @param min - the minimum value to clamp
|
|
96
|
+
* @param max - the maximum value to clamp
|
|
97
97
|
* @returns the new value
|
|
98
98
|
*/
|
|
99
99
|
declare function clamp(value: number, min?: number, max?: number): number;
|
|
@@ -101,7 +101,7 @@ declare function clamp(value: number, min?: number, max?: number): number;
|
|
|
101
101
|
/**
|
|
102
102
|
* Wait for a number of milliseconds
|
|
103
103
|
*
|
|
104
|
-
* @param ms millseconds to wait
|
|
104
|
+
* @param ms - millseconds to wait
|
|
105
105
|
* @returns a promise that resolves after ms milliseconds
|
|
106
106
|
*
|
|
107
107
|
* @example
|
|
@@ -152,8 +152,8 @@ declare function last<T>(array: readonly T[]): T | undefined;
|
|
|
152
152
|
|
|
153
153
|
/**
|
|
154
154
|
* Splits an array into smaller chunks of a given size.
|
|
155
|
-
* @param array The array to split
|
|
156
|
-
* @param size The size of each chunk
|
|
155
|
+
* @param array - The array to split
|
|
156
|
+
* @param size - The size of each chunk
|
|
157
157
|
* @returns An array of arrays, where each sub-array has `size` elements from the original array.
|
|
158
158
|
*/
|
|
159
159
|
declare function chunk<T>(array: T[], size: number): T[][];
|
|
@@ -172,16 +172,34 @@ declare function unique<T>(array: T[]): T[];
|
|
|
172
172
|
*/
|
|
173
173
|
declare function uniqueBy<T>(array: T[], equalFn: (a: T, b: T) => boolean): T[];
|
|
174
174
|
|
|
175
|
-
|
|
176
|
-
|
|
175
|
+
/**
|
|
176
|
+
* interop module
|
|
177
|
+
*/
|
|
178
|
+
type InteropModuleDefault<T> = T extends {
|
|
179
|
+
default: infer U;
|
|
180
|
+
} ? U : T;
|
|
181
|
+
|
|
177
182
|
type AnyFn<T = any, R = any> = (...args: T[]) => R;
|
|
178
183
|
type Arrayable<T> = T | T[];
|
|
179
|
-
type Awaitable<T> = T |
|
|
184
|
+
type Awaitable<T> = Promise<T> | T;
|
|
185
|
+
type MayBe<T> = T | undefined;
|
|
186
|
+
type Nullable<T> = T | null;
|
|
187
|
+
type PrimitiveType = bigint | boolean | number | string | symbol | null | undefined;
|
|
188
|
+
/**
|
|
189
|
+
* Prettify object type
|
|
190
|
+
*/
|
|
180
191
|
type Prettify<T> = {
|
|
181
192
|
[K in keyof T]: T[K];
|
|
182
193
|
} & {};
|
|
183
194
|
type PrettifyV2<T> = Omit<T, never>;
|
|
184
|
-
|
|
195
|
+
/**
|
|
196
|
+
* Overwrite some keys type
|
|
197
|
+
*/
|
|
198
|
+
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
|
|
199
|
+
/**
|
|
200
|
+
* Resolve `boolean | Record<string, any>` to `Record<string, any>`
|
|
201
|
+
*/
|
|
202
|
+
type ResolvedOptions<T> = T extends boolean ? never : NonNullable<T>;
|
|
185
203
|
|
|
186
204
|
/**
|
|
187
205
|
* Converts a value to an array.
|
|
@@ -228,7 +246,7 @@ declare function slash(input: string): string;
|
|
|
228
246
|
/**
|
|
229
247
|
* Remove leading whitespace from a template string
|
|
230
248
|
* Empty lines at the beginning and end of the template string are also removed.
|
|
231
|
-
* @param input template string
|
|
249
|
+
* @param input - template string
|
|
232
250
|
*
|
|
233
251
|
* @example
|
|
234
252
|
*
|
|
@@ -250,7 +268,71 @@ declare function omit<T, K extends keyof T>(object: T, ...keys: K[]): Omit<T, K>
|
|
|
250
268
|
|
|
251
269
|
declare function pick<T, K extends keyof T>(object: T, keys: K[]): Pick<T, K>;
|
|
252
270
|
|
|
253
|
-
|
|
271
|
+
interface CleanObjectOptions {
|
|
272
|
+
/**
|
|
273
|
+
* clean undefined
|
|
274
|
+
*
|
|
275
|
+
* @default true
|
|
276
|
+
*/
|
|
277
|
+
cleanUndefined?: boolean;
|
|
278
|
+
/**
|
|
279
|
+
* clean null
|
|
280
|
+
*
|
|
281
|
+
* @default true
|
|
282
|
+
*/
|
|
283
|
+
cleanNull?: boolean;
|
|
284
|
+
/**
|
|
285
|
+
* clean zero
|
|
286
|
+
*
|
|
287
|
+
* @default false
|
|
288
|
+
*/
|
|
289
|
+
cleanZero?: boolean;
|
|
290
|
+
/**
|
|
291
|
+
* clean NaN
|
|
292
|
+
*
|
|
293
|
+
* @default true
|
|
294
|
+
*/
|
|
295
|
+
cleanNaN?: boolean;
|
|
296
|
+
/**
|
|
297
|
+
* clean empty string
|
|
298
|
+
*
|
|
299
|
+
* @default true
|
|
300
|
+
*/
|
|
301
|
+
cleanEmptyString?: boolean;
|
|
302
|
+
/**
|
|
303
|
+
* clean empty array
|
|
304
|
+
*
|
|
305
|
+
* @default true
|
|
306
|
+
*/
|
|
307
|
+
cleanEmptyArray?: boolean;
|
|
308
|
+
/**
|
|
309
|
+
* clean empty object
|
|
310
|
+
*
|
|
311
|
+
* @default true
|
|
312
|
+
*/
|
|
313
|
+
cleanEmptyObject?: boolean;
|
|
314
|
+
/**
|
|
315
|
+
* recursive clean object
|
|
316
|
+
*
|
|
317
|
+
* @default true
|
|
318
|
+
*/
|
|
319
|
+
recursive?: boolean;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* clean undefined, null, zero, empty string, empty array, empty object from object
|
|
323
|
+
* @param obj - object to be cleaned
|
|
324
|
+
* @param options - clean options
|
|
325
|
+
* @returns cleaned object
|
|
326
|
+
*/
|
|
327
|
+
declare function cleanObject<T extends object>(obj: T, options?: CleanObjectOptions): T;
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* check object has a property with given key
|
|
331
|
+
* @param object - the object to check
|
|
332
|
+
* @param key - the key to check
|
|
333
|
+
* @returns true if object has a property with given key, false otherwise
|
|
334
|
+
*/
|
|
335
|
+
declare function hasOwn<T>(object: T, key: PropertyKey): boolean;
|
|
254
336
|
|
|
255
337
|
interface SortObjectOptions {
|
|
256
338
|
/**
|
|
@@ -268,4 +350,14 @@ interface SortObjectOptions {
|
|
|
268
350
|
*/
|
|
269
351
|
declare function sortObject<T extends Record<string, any>>(obj: T, options?: SortObjectOptions): T;
|
|
270
352
|
|
|
271
|
-
|
|
353
|
+
/**
|
|
354
|
+
* @file case utils
|
|
355
|
+
* @module vendor
|
|
356
|
+
*/
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* @deprecated use upperFirst instead
|
|
360
|
+
*/
|
|
361
|
+
declare const capitalize: typeof upperFirst;
|
|
362
|
+
|
|
363
|
+
export { type AnyFn, type Arrayable, type Awaitable, type CleanObjectOptions, type InteropModuleDefault, 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, flattenArrayable, getObjectType, hasOwn, hours, 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, seconds, slash, sortObject, throttle, toArray, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { upperFirst } from 'scule';
|
|
2
2
|
export * from 'scule';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* check if two values are deeply equal
|
|
6
|
+
*/
|
|
7
|
+
declare function isDeepEqual(value1: any, value2: any): boolean;
|
|
8
|
+
|
|
4
9
|
/**
|
|
5
10
|
* @file is utils
|
|
6
|
-
* @
|
|
11
|
+
* @module is
|
|
7
12
|
* @copyright {@link https://github.com/sindresorhus/is}
|
|
8
13
|
*/
|
|
9
14
|
type Whitespace = ' ';
|
|
@@ -11,8 +16,13 @@ type NonEmptyString = string & {
|
|
|
11
16
|
0: '';
|
|
12
17
|
};
|
|
13
18
|
declare function getObjectType(value: unknown): string;
|
|
19
|
+
declare function isUndefined(value: unknown): value is undefined;
|
|
20
|
+
declare function isNull(value: unknown): value is null;
|
|
21
|
+
declare function isNil(value: unknown): value is null | undefined;
|
|
14
22
|
declare function isString(value: unknown): value is string;
|
|
15
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;
|
|
16
26
|
declare function isEmptyString(value: unknown): value is '';
|
|
17
27
|
declare function isNonEmptyString(value: unknown): value is NonEmptyString;
|
|
18
28
|
declare function isWhitespaceString(value: unknown): value is Whitespace;
|
|
@@ -22,10 +32,9 @@ declare function isInteger(value: unknown): value is number;
|
|
|
22
32
|
declare function isBoolean(value: unknown): value is boolean;
|
|
23
33
|
declare function isFunction(value: unknown): value is Function;
|
|
24
34
|
declare function isArray(value: unknown): value is unknown[];
|
|
25
|
-
declare function
|
|
26
|
-
declare function isNull(value: unknown): value is null;
|
|
27
|
-
declare function isNil(value: unknown): value is null | undefined;
|
|
35
|
+
declare function isEmptyArray(value: unknown): value is [];
|
|
28
36
|
declare function isObject(value: unknown): value is object;
|
|
37
|
+
declare function isEmptyObject(value: unknown): value is {};
|
|
29
38
|
declare function isRegExp(value: unknown): value is RegExp;
|
|
30
39
|
declare function isSet<Value = unknown>(value: unknown): value is Set<Value>;
|
|
31
40
|
declare function isNativePromise<T = unknown>(value: unknown): value is Promise<T>;
|
|
@@ -52,36 +61,27 @@ declare function once<T extends unknown[]>(func: (...args: T) => void): (this: u
|
|
|
52
61
|
*/
|
|
53
62
|
declare const isBrowser: () => boolean;
|
|
54
63
|
|
|
55
|
-
/**
|
|
56
|
-
* @file case utils
|
|
57
|
-
* @category Case
|
|
58
|
-
*/
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* @deprecated use upperFirst instead
|
|
62
|
-
*/
|
|
63
|
-
declare const capitalize: typeof upperFirst;
|
|
64
|
-
|
|
65
64
|
/**
|
|
66
65
|
* @file raf.ts
|
|
67
66
|
*/
|
|
68
67
|
/**
|
|
69
68
|
* Request animation frame
|
|
70
69
|
*
|
|
71
|
-
* @param fn callback
|
|
70
|
+
* @param fn - callback
|
|
72
71
|
* @returns id
|
|
73
72
|
*/
|
|
74
73
|
declare function rAF(fn: FrameRequestCallback): number;
|
|
75
74
|
/**
|
|
76
75
|
* Cancel animation frame
|
|
77
76
|
*
|
|
78
|
-
* @param id id
|
|
77
|
+
* @param id - id
|
|
79
78
|
* @returns void
|
|
80
79
|
*/
|
|
81
80
|
declare function cAF(id: number): void;
|
|
82
81
|
|
|
83
82
|
/**
|
|
84
|
-
* @
|
|
83
|
+
* @file time utils
|
|
84
|
+
* @module Time
|
|
85
85
|
*/
|
|
86
86
|
declare function seconds(count: number): number;
|
|
87
87
|
declare function minutes(count: number): number;
|
|
@@ -91,9 +91,9 @@ declare function weeks(count: number): number;
|
|
|
91
91
|
|
|
92
92
|
/**
|
|
93
93
|
* Clamps a number between a minimum and maximum value
|
|
94
|
-
* @param value the value to clamp within the given range
|
|
95
|
-
* @param min the minimum value to clamp
|
|
96
|
-
* @param max the maximum value to clamp
|
|
94
|
+
* @param value - the value to clamp within the given range
|
|
95
|
+
* @param min - the minimum value to clamp
|
|
96
|
+
* @param max - the maximum value to clamp
|
|
97
97
|
* @returns the new value
|
|
98
98
|
*/
|
|
99
99
|
declare function clamp(value: number, min?: number, max?: number): number;
|
|
@@ -101,7 +101,7 @@ declare function clamp(value: number, min?: number, max?: number): number;
|
|
|
101
101
|
/**
|
|
102
102
|
* Wait for a number of milliseconds
|
|
103
103
|
*
|
|
104
|
-
* @param ms millseconds to wait
|
|
104
|
+
* @param ms - millseconds to wait
|
|
105
105
|
* @returns a promise that resolves after ms milliseconds
|
|
106
106
|
*
|
|
107
107
|
* @example
|
|
@@ -152,8 +152,8 @@ declare function last<T>(array: readonly T[]): T | undefined;
|
|
|
152
152
|
|
|
153
153
|
/**
|
|
154
154
|
* Splits an array into smaller chunks of a given size.
|
|
155
|
-
* @param array The array to split
|
|
156
|
-
* @param size The size of each chunk
|
|
155
|
+
* @param array - The array to split
|
|
156
|
+
* @param size - The size of each chunk
|
|
157
157
|
* @returns An array of arrays, where each sub-array has `size` elements from the original array.
|
|
158
158
|
*/
|
|
159
159
|
declare function chunk<T>(array: T[], size: number): T[][];
|
|
@@ -172,16 +172,34 @@ declare function unique<T>(array: T[]): T[];
|
|
|
172
172
|
*/
|
|
173
173
|
declare function uniqueBy<T>(array: T[], equalFn: (a: T, b: T) => boolean): T[];
|
|
174
174
|
|
|
175
|
-
|
|
176
|
-
|
|
175
|
+
/**
|
|
176
|
+
* interop module
|
|
177
|
+
*/
|
|
178
|
+
type InteropModuleDefault<T> = T extends {
|
|
179
|
+
default: infer U;
|
|
180
|
+
} ? U : T;
|
|
181
|
+
|
|
177
182
|
type AnyFn<T = any, R = any> = (...args: T[]) => R;
|
|
178
183
|
type Arrayable<T> = T | T[];
|
|
179
|
-
type Awaitable<T> = T |
|
|
184
|
+
type Awaitable<T> = Promise<T> | T;
|
|
185
|
+
type MayBe<T> = T | undefined;
|
|
186
|
+
type Nullable<T> = T | null;
|
|
187
|
+
type PrimitiveType = bigint | boolean | number | string | symbol | null | undefined;
|
|
188
|
+
/**
|
|
189
|
+
* Prettify object type
|
|
190
|
+
*/
|
|
180
191
|
type Prettify<T> = {
|
|
181
192
|
[K in keyof T]: T[K];
|
|
182
193
|
} & {};
|
|
183
194
|
type PrettifyV2<T> = Omit<T, never>;
|
|
184
|
-
|
|
195
|
+
/**
|
|
196
|
+
* Overwrite some keys type
|
|
197
|
+
*/
|
|
198
|
+
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
|
|
199
|
+
/**
|
|
200
|
+
* Resolve `boolean | Record<string, any>` to `Record<string, any>`
|
|
201
|
+
*/
|
|
202
|
+
type ResolvedOptions<T> = T extends boolean ? never : NonNullable<T>;
|
|
185
203
|
|
|
186
204
|
/**
|
|
187
205
|
* Converts a value to an array.
|
|
@@ -228,7 +246,7 @@ declare function slash(input: string): string;
|
|
|
228
246
|
/**
|
|
229
247
|
* Remove leading whitespace from a template string
|
|
230
248
|
* Empty lines at the beginning and end of the template string are also removed.
|
|
231
|
-
* @param input template string
|
|
249
|
+
* @param input - template string
|
|
232
250
|
*
|
|
233
251
|
* @example
|
|
234
252
|
*
|
|
@@ -250,7 +268,71 @@ declare function omit<T, K extends keyof T>(object: T, ...keys: K[]): Omit<T, K>
|
|
|
250
268
|
|
|
251
269
|
declare function pick<T, K extends keyof T>(object: T, keys: K[]): Pick<T, K>;
|
|
252
270
|
|
|
253
|
-
|
|
271
|
+
interface CleanObjectOptions {
|
|
272
|
+
/**
|
|
273
|
+
* clean undefined
|
|
274
|
+
*
|
|
275
|
+
* @default true
|
|
276
|
+
*/
|
|
277
|
+
cleanUndefined?: boolean;
|
|
278
|
+
/**
|
|
279
|
+
* clean null
|
|
280
|
+
*
|
|
281
|
+
* @default true
|
|
282
|
+
*/
|
|
283
|
+
cleanNull?: boolean;
|
|
284
|
+
/**
|
|
285
|
+
* clean zero
|
|
286
|
+
*
|
|
287
|
+
* @default false
|
|
288
|
+
*/
|
|
289
|
+
cleanZero?: boolean;
|
|
290
|
+
/**
|
|
291
|
+
* clean NaN
|
|
292
|
+
*
|
|
293
|
+
* @default true
|
|
294
|
+
*/
|
|
295
|
+
cleanNaN?: boolean;
|
|
296
|
+
/**
|
|
297
|
+
* clean empty string
|
|
298
|
+
*
|
|
299
|
+
* @default true
|
|
300
|
+
*/
|
|
301
|
+
cleanEmptyString?: boolean;
|
|
302
|
+
/**
|
|
303
|
+
* clean empty array
|
|
304
|
+
*
|
|
305
|
+
* @default true
|
|
306
|
+
*/
|
|
307
|
+
cleanEmptyArray?: boolean;
|
|
308
|
+
/**
|
|
309
|
+
* clean empty object
|
|
310
|
+
*
|
|
311
|
+
* @default true
|
|
312
|
+
*/
|
|
313
|
+
cleanEmptyObject?: boolean;
|
|
314
|
+
/**
|
|
315
|
+
* recursive clean object
|
|
316
|
+
*
|
|
317
|
+
* @default true
|
|
318
|
+
*/
|
|
319
|
+
recursive?: boolean;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* clean undefined, null, zero, empty string, empty array, empty object from object
|
|
323
|
+
* @param obj - object to be cleaned
|
|
324
|
+
* @param options - clean options
|
|
325
|
+
* @returns cleaned object
|
|
326
|
+
*/
|
|
327
|
+
declare function cleanObject<T extends object>(obj: T, options?: CleanObjectOptions): T;
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* check object has a property with given key
|
|
331
|
+
* @param object - the object to check
|
|
332
|
+
* @param key - the key to check
|
|
333
|
+
* @returns true if object has a property with given key, false otherwise
|
|
334
|
+
*/
|
|
335
|
+
declare function hasOwn<T>(object: T, key: PropertyKey): boolean;
|
|
254
336
|
|
|
255
337
|
interface SortObjectOptions {
|
|
256
338
|
/**
|
|
@@ -268,4 +350,14 @@ interface SortObjectOptions {
|
|
|
268
350
|
*/
|
|
269
351
|
declare function sortObject<T extends Record<string, any>>(obj: T, options?: SortObjectOptions): T;
|
|
270
352
|
|
|
271
|
-
|
|
353
|
+
/**
|
|
354
|
+
* @file case utils
|
|
355
|
+
* @module vendor
|
|
356
|
+
*/
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* @deprecated use upperFirst instead
|
|
360
|
+
*/
|
|
361
|
+
declare const capitalize: typeof upperFirst;
|
|
362
|
+
|
|
363
|
+
export { type AnyFn, type Arrayable, type Awaitable, type CleanObjectOptions, type InteropModuleDefault, 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, flattenArrayable, getObjectType, hasOwn, hours, 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, seconds, slash, sortObject, throttle, toArray, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,135 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
+
|
|
19
|
+
// src/index.ts
|
|
20
|
+
var src_exports = {};
|
|
21
|
+
__export(src_exports, {
|
|
22
|
+
NOOP: () => NOOP,
|
|
23
|
+
at: () => at,
|
|
24
|
+
cAF: () => cAF,
|
|
25
|
+
capitalize: () => capitalize,
|
|
26
|
+
chunk: () => chunk,
|
|
27
|
+
clamp: () => clamp,
|
|
28
|
+
cleanObject: () => cleanObject,
|
|
29
|
+
days: () => days,
|
|
30
|
+
debounce: () => debounce,
|
|
31
|
+
ensurePrefix: () => ensurePrefix,
|
|
32
|
+
ensureSuffix: () => ensureSuffix,
|
|
33
|
+
flattenArrayable: () => flattenArrayable,
|
|
34
|
+
getObjectType: () => getObjectType,
|
|
35
|
+
hasOwn: () => hasOwn,
|
|
36
|
+
hours: () => hours,
|
|
37
|
+
isArray: () => isArray,
|
|
38
|
+
isArrayEqual: () => isArrayEqual,
|
|
39
|
+
isBoolean: () => isBoolean,
|
|
40
|
+
isBrowser: () => isBrowser,
|
|
41
|
+
isDeepEqual: () => isDeepEqual,
|
|
42
|
+
isEmptyArray: () => isEmptyArray,
|
|
43
|
+
isEmptyObject: () => isEmptyObject,
|
|
44
|
+
isEmptyString: () => isEmptyString,
|
|
45
|
+
isEmptyStringOrWhitespace: () => isEmptyStringOrWhitespace,
|
|
46
|
+
isFunction: () => isFunction,
|
|
47
|
+
isInteger: () => isInteger,
|
|
48
|
+
isNaN: () => isNaN,
|
|
49
|
+
isNativePromise: () => isNativePromise,
|
|
50
|
+
isNil: () => isNil,
|
|
51
|
+
isNonEmptyString: () => isNonEmptyString,
|
|
52
|
+
isNull: () => isNull,
|
|
53
|
+
isNumber: () => isNumber,
|
|
54
|
+
isNumbericString: () => isNumbericString,
|
|
55
|
+
isObject: () => isObject,
|
|
56
|
+
isPromise: () => isPromise,
|
|
57
|
+
isRegExp: () => isRegExp,
|
|
58
|
+
isSet: () => isSet,
|
|
59
|
+
isString: () => isString,
|
|
60
|
+
isUndefined: () => isUndefined,
|
|
61
|
+
isWhitespaceString: () => isWhitespaceString,
|
|
62
|
+
isZero: () => isZero,
|
|
63
|
+
join: () => join,
|
|
64
|
+
last: () => last,
|
|
65
|
+
mergeArrayable: () => mergeArrayable,
|
|
66
|
+
minutes: () => minutes,
|
|
67
|
+
noop: () => noop,
|
|
68
|
+
omit: () => omit,
|
|
69
|
+
once: () => once,
|
|
70
|
+
pick: () => pick,
|
|
71
|
+
rAF: () => rAF,
|
|
72
|
+
seconds: () => seconds,
|
|
73
|
+
slash: () => slash,
|
|
74
|
+
sortObject: () => sortObject,
|
|
75
|
+
throttle: () => throttle,
|
|
76
|
+
toArray: () => toArray,
|
|
77
|
+
unindent: () => unindent,
|
|
78
|
+
unique: () => unique,
|
|
79
|
+
uniqueBy: () => uniqueBy,
|
|
80
|
+
waitFor: () => waitFor,
|
|
81
|
+
warnOnce: () => warnOnce,
|
|
82
|
+
weeks: () => weeks
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// src/is/isDeepEqual.ts
|
|
86
|
+
function isDeepEqual(value1, value2) {
|
|
87
|
+
const type1 = getObjectType(value1);
|
|
88
|
+
const type2 = getObjectType(value2);
|
|
89
|
+
if (type1 !== type2) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
if (isArray(value1)) {
|
|
93
|
+
if (value1.length !== value2.length) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
return value1.every((item, index) => isDeepEqual(item, value2[index]));
|
|
97
|
+
}
|
|
98
|
+
if (isObject(value1)) {
|
|
99
|
+
const keys = Object.keys(value1);
|
|
100
|
+
if (keys.length !== Object.keys(value2).length) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
return keys.every((key) => isDeepEqual(value1[key], value2[key]));
|
|
104
|
+
}
|
|
105
|
+
return Object.is(value1, value2);
|
|
106
|
+
}
|
|
107
|
+
|
|
1
108
|
// src/is/index.ts
|
|
2
109
|
function getObjectType(value) {
|
|
3
110
|
return Object.prototype.toString.call(value).slice(8, -1);
|
|
4
111
|
}
|
|
112
|
+
function isUndefined(value) {
|
|
113
|
+
return value === void 0;
|
|
114
|
+
}
|
|
115
|
+
function isNull(value) {
|
|
116
|
+
return value === null;
|
|
117
|
+
}
|
|
118
|
+
function isNil(value) {
|
|
119
|
+
return isNull(value) || isUndefined(value);
|
|
120
|
+
}
|
|
5
121
|
function isString(value) {
|
|
6
122
|
return typeof value === "string";
|
|
7
123
|
}
|
|
8
124
|
function isNumber(value) {
|
|
9
125
|
return typeof value === "number";
|
|
10
126
|
}
|
|
127
|
+
function isZero(value) {
|
|
128
|
+
return value === 0;
|
|
129
|
+
}
|
|
130
|
+
function isNaN(value) {
|
|
131
|
+
return Number.isNaN(value);
|
|
132
|
+
}
|
|
11
133
|
function isEmptyString(value) {
|
|
12
134
|
return isString(value) && value.length === 0;
|
|
13
135
|
}
|
|
@@ -35,18 +157,15 @@ function isFunction(value) {
|
|
|
35
157
|
function isArray(value) {
|
|
36
158
|
return Array.isArray(value);
|
|
37
159
|
}
|
|
38
|
-
function
|
|
39
|
-
return value ===
|
|
40
|
-
}
|
|
41
|
-
function isNull(value) {
|
|
42
|
-
return value === null;
|
|
43
|
-
}
|
|
44
|
-
function isNil(value) {
|
|
45
|
-
return isNull(value) || isUndefined(value);
|
|
160
|
+
function isEmptyArray(value) {
|
|
161
|
+
return isArray(value) && value.length === 0;
|
|
46
162
|
}
|
|
47
163
|
function isObject(value) {
|
|
48
164
|
return getObjectType(value) === "Object";
|
|
49
165
|
}
|
|
166
|
+
function isEmptyObject(value) {
|
|
167
|
+
return isObject(value) && Object.keys(value).length === 0;
|
|
168
|
+
}
|
|
50
169
|
function isRegExp(value) {
|
|
51
170
|
return getObjectType(value) === "RegExp";
|
|
52
171
|
}
|
|
@@ -84,89 +203,6 @@ function once(func) {
|
|
|
84
203
|
// src/env/isBrowser.ts
|
|
85
204
|
var isBrowser = () => typeof document !== "undefined";
|
|
86
205
|
|
|
87
|
-
// node_modules/.pnpm/scule@1.3.0/node_modules/scule/dist/index.mjs
|
|
88
|
-
var NUMBER_CHAR_RE = /\d/;
|
|
89
|
-
var STR_SPLITTERS = ["-", "_", "/", "."];
|
|
90
|
-
function isUppercase(char = "") {
|
|
91
|
-
if (NUMBER_CHAR_RE.test(char)) {
|
|
92
|
-
return void 0;
|
|
93
|
-
}
|
|
94
|
-
return char !== char.toLowerCase();
|
|
95
|
-
}
|
|
96
|
-
function splitByCase(str, separators) {
|
|
97
|
-
const splitters = separators ?? STR_SPLITTERS;
|
|
98
|
-
const parts = [];
|
|
99
|
-
if (!str || typeof str !== "string") {
|
|
100
|
-
return parts;
|
|
101
|
-
}
|
|
102
|
-
let buff = "";
|
|
103
|
-
let previousUpper;
|
|
104
|
-
let previousSplitter;
|
|
105
|
-
for (const char of str) {
|
|
106
|
-
const isSplitter = splitters.includes(char);
|
|
107
|
-
if (isSplitter === true) {
|
|
108
|
-
parts.push(buff);
|
|
109
|
-
buff = "";
|
|
110
|
-
previousUpper = void 0;
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
const isUpper = isUppercase(char);
|
|
114
|
-
if (previousSplitter === false) {
|
|
115
|
-
if (previousUpper === false && isUpper === true) {
|
|
116
|
-
parts.push(buff);
|
|
117
|
-
buff = char;
|
|
118
|
-
previousUpper = isUpper;
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
if (previousUpper === true && isUpper === false && buff.length > 1) {
|
|
122
|
-
const lastChar = buff.at(-1);
|
|
123
|
-
parts.push(buff.slice(0, Math.max(0, buff.length - 1)));
|
|
124
|
-
buff = lastChar + char;
|
|
125
|
-
previousUpper = isUpper;
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
buff += char;
|
|
130
|
-
previousUpper = isUpper;
|
|
131
|
-
previousSplitter = isSplitter;
|
|
132
|
-
}
|
|
133
|
-
parts.push(buff);
|
|
134
|
-
return parts;
|
|
135
|
-
}
|
|
136
|
-
function upperFirst(str) {
|
|
137
|
-
return str ? str[0].toUpperCase() + str.slice(1) : "";
|
|
138
|
-
}
|
|
139
|
-
function lowerFirst(str) {
|
|
140
|
-
return str ? str[0].toLowerCase() + str.slice(1) : "";
|
|
141
|
-
}
|
|
142
|
-
function pascalCase(str, opts) {
|
|
143
|
-
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => upperFirst(opts?.normalize ? p.toLowerCase() : p)).join("") : "";
|
|
144
|
-
}
|
|
145
|
-
function camelCase(str, opts) {
|
|
146
|
-
return lowerFirst(pascalCase(str || "", opts));
|
|
147
|
-
}
|
|
148
|
-
function kebabCase(str, joiner) {
|
|
149
|
-
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => p.toLowerCase()).join(joiner ?? "-") : "";
|
|
150
|
-
}
|
|
151
|
-
function snakeCase(str) {
|
|
152
|
-
return kebabCase(str || "", "_");
|
|
153
|
-
}
|
|
154
|
-
function flatCase(str) {
|
|
155
|
-
return kebabCase(str || "", "");
|
|
156
|
-
}
|
|
157
|
-
function trainCase(str, opts) {
|
|
158
|
-
return (Array.isArray(str) ? str : splitByCase(str)).filter(Boolean).map((p) => upperFirst(opts?.normalize ? p.toLowerCase() : p)).join("-");
|
|
159
|
-
}
|
|
160
|
-
var titleCaseExceptions = /^(a|an|and|as|at|but|by|for|if|in|is|nor|of|on|or|the|to|with)$/i;
|
|
161
|
-
function titleCase(str, opts) {
|
|
162
|
-
return (Array.isArray(str) ? str : splitByCase(str)).filter(Boolean).map(
|
|
163
|
-
(p) => titleCaseExceptions.test(p) ? p.toLowerCase() : upperFirst(opts?.normalize ? p.toLowerCase() : p)
|
|
164
|
-
).join(" ");
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// src/case.ts
|
|
168
|
-
var capitalize = upperFirst;
|
|
169
|
-
|
|
170
206
|
// src/misc/raf.ts
|
|
171
207
|
var root = isBrowser() ? window : globalThis;
|
|
172
208
|
var prev = Date.now();
|
|
@@ -386,6 +422,9 @@ function omit(object, ...keys) {
|
|
|
386
422
|
|
|
387
423
|
// src/object/hasOwn.ts
|
|
388
424
|
function hasOwn(object, key) {
|
|
425
|
+
if (object === null) {
|
|
426
|
+
return false;
|
|
427
|
+
}
|
|
389
428
|
return Object.prototype.hasOwnProperty.call(object, key);
|
|
390
429
|
}
|
|
391
430
|
|
|
@@ -401,6 +440,48 @@ function pick(object, keys) {
|
|
|
401
440
|
);
|
|
402
441
|
}
|
|
403
442
|
|
|
443
|
+
// src/object/clean.ts
|
|
444
|
+
function cleanObject(obj, options = {}) {
|
|
445
|
+
const {
|
|
446
|
+
cleanUndefined = true,
|
|
447
|
+
cleanNull = true,
|
|
448
|
+
cleanZero = false,
|
|
449
|
+
cleanNaN = true,
|
|
450
|
+
cleanEmptyString = true,
|
|
451
|
+
cleanEmptyArray = true,
|
|
452
|
+
cleanEmptyObject = true,
|
|
453
|
+
recursive = true
|
|
454
|
+
} = options;
|
|
455
|
+
Object.keys(obj).forEach((key) => {
|
|
456
|
+
const v = obj[key];
|
|
457
|
+
if (cleanUndefined && isUndefined(v)) {
|
|
458
|
+
delete obj[key];
|
|
459
|
+
}
|
|
460
|
+
if (cleanNull && isNull(v)) {
|
|
461
|
+
delete obj[key];
|
|
462
|
+
}
|
|
463
|
+
if (cleanZero && isZero(v)) {
|
|
464
|
+
delete obj[key];
|
|
465
|
+
}
|
|
466
|
+
if (cleanNaN && isZero(v)) {
|
|
467
|
+
delete obj[key];
|
|
468
|
+
}
|
|
469
|
+
if (cleanEmptyString && isEmptyString(v)) {
|
|
470
|
+
delete obj[key];
|
|
471
|
+
}
|
|
472
|
+
if (cleanEmptyArray && isEmptyArray(v)) {
|
|
473
|
+
delete obj[key];
|
|
474
|
+
}
|
|
475
|
+
if (cleanEmptyObject && isEmptyObject(v)) {
|
|
476
|
+
delete obj[key];
|
|
477
|
+
}
|
|
478
|
+
if (recursive && isObject(v)) {
|
|
479
|
+
cleanObject(v, options);
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
return obj;
|
|
483
|
+
}
|
|
484
|
+
|
|
404
485
|
// src/object/isPlainObject.ts
|
|
405
486
|
function isPlainObject(value) {
|
|
406
487
|
if (!isObject(value)) return false;
|
|
@@ -431,19 +512,40 @@ function sortObject(obj, options = {}) {
|
|
|
431
512
|
}
|
|
432
513
|
return sortKeys(obj);
|
|
433
514
|
}
|
|
515
|
+
|
|
516
|
+
// src/vendor/index.ts
|
|
517
|
+
var vendor_exports = {};
|
|
518
|
+
__export(vendor_exports, {
|
|
519
|
+
capitalize: () => capitalize
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
// src/vendor/scule.ts
|
|
523
|
+
var scule_exports = {};
|
|
524
|
+
__export(scule_exports, {
|
|
525
|
+
capitalize: () => capitalize
|
|
526
|
+
});
|
|
527
|
+
__reExport(scule_exports, scule_star);
|
|
528
|
+
import { upperFirst } from "scule";
|
|
529
|
+
import * as scule_star from "scule";
|
|
530
|
+
var capitalize = upperFirst;
|
|
531
|
+
|
|
532
|
+
// src/vendor/index.ts
|
|
533
|
+
__reExport(vendor_exports, scule_exports);
|
|
534
|
+
|
|
535
|
+
// src/index.ts
|
|
536
|
+
__reExport(src_exports, vendor_exports);
|
|
434
537
|
export {
|
|
435
538
|
NOOP,
|
|
436
539
|
at,
|
|
437
540
|
cAF,
|
|
438
|
-
camelCase,
|
|
439
541
|
capitalize,
|
|
440
542
|
chunk,
|
|
441
543
|
clamp,
|
|
544
|
+
cleanObject,
|
|
442
545
|
days,
|
|
443
546
|
debounce,
|
|
444
547
|
ensurePrefix,
|
|
445
548
|
ensureSuffix,
|
|
446
|
-
flatCase,
|
|
447
549
|
flattenArrayable,
|
|
448
550
|
getObjectType,
|
|
449
551
|
hasOwn,
|
|
@@ -452,10 +554,14 @@ export {
|
|
|
452
554
|
isArrayEqual,
|
|
453
555
|
isBoolean,
|
|
454
556
|
isBrowser,
|
|
557
|
+
isDeepEqual,
|
|
558
|
+
isEmptyArray,
|
|
559
|
+
isEmptyObject,
|
|
455
560
|
isEmptyString,
|
|
456
561
|
isEmptyStringOrWhitespace,
|
|
457
562
|
isFunction,
|
|
458
563
|
isInteger,
|
|
564
|
+
isNaN,
|
|
459
565
|
isNativePromise,
|
|
460
566
|
isNil,
|
|
461
567
|
isNonEmptyString,
|
|
@@ -468,33 +574,25 @@ export {
|
|
|
468
574
|
isSet,
|
|
469
575
|
isString,
|
|
470
576
|
isUndefined,
|
|
471
|
-
isUppercase,
|
|
472
577
|
isWhitespaceString,
|
|
578
|
+
isZero,
|
|
473
579
|
join,
|
|
474
|
-
kebabCase,
|
|
475
580
|
last,
|
|
476
|
-
lowerFirst,
|
|
477
581
|
mergeArrayable,
|
|
478
582
|
minutes,
|
|
479
583
|
noop,
|
|
480
584
|
omit,
|
|
481
585
|
once,
|
|
482
|
-
pascalCase,
|
|
483
586
|
pick,
|
|
484
587
|
rAF,
|
|
485
588
|
seconds,
|
|
486
589
|
slash,
|
|
487
|
-
snakeCase,
|
|
488
590
|
sortObject,
|
|
489
|
-
splitByCase,
|
|
490
591
|
throttle,
|
|
491
|
-
titleCase,
|
|
492
592
|
toArray,
|
|
493
|
-
trainCase,
|
|
494
593
|
unindent,
|
|
495
594
|
unique,
|
|
496
595
|
uniqueBy,
|
|
497
|
-
upperFirst,
|
|
498
596
|
waitFor,
|
|
499
597
|
warnOnce,
|
|
500
598
|
weeks
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ntnyq/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.3",
|
|
5
5
|
"description": "Common used utils.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"utils"
|
|
@@ -40,23 +40,22 @@
|
|
|
40
40
|
"scule": "^1.3.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@ntnyq/eslint-config": "^3.
|
|
44
|
-
"@ntnyq/prettier-config": "^1.
|
|
45
|
-
"@vitest/coverage-v8": "^2.1.
|
|
43
|
+
"@ntnyq/eslint-config": "^3.8.1",
|
|
44
|
+
"@ntnyq/prettier-config": "^1.22.0",
|
|
45
|
+
"@vitest/coverage-v8": "^2.1.8",
|
|
46
46
|
"bumpp": "^9.8.1",
|
|
47
|
-
"eslint": "^9.
|
|
47
|
+
"eslint": "^9.16.0",
|
|
48
48
|
"husky": "^9.1.7",
|
|
49
49
|
"nano-staged": "^0.8.0",
|
|
50
50
|
"npm-run-all2": "^7.0.1",
|
|
51
|
-
"prettier": "^3.
|
|
51
|
+
"prettier": "^3.4.2",
|
|
52
52
|
"tsup": "^8.3.5",
|
|
53
|
-
"typescript": "^5.
|
|
54
|
-
"vitest": "^2.1.
|
|
53
|
+
"typescript": "^5.7.2",
|
|
54
|
+
"vitest": "^2.1.8"
|
|
55
55
|
},
|
|
56
56
|
"engines": {
|
|
57
57
|
"node": ">=18.18.0"
|
|
58
58
|
},
|
|
59
|
-
"prettier": "@ntnyq/prettier-config",
|
|
60
59
|
"nano-staged": {
|
|
61
60
|
"*.{js,ts,mjs,cjs,json,md,yml,yaml}": "eslint --fix"
|
|
62
61
|
},
|