@ntnyq/utils 0.3.2 → 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 +121 -20
- package/dist/index.d.cts +88 -15
- package/dist/index.d.ts +88 -15
- package/dist/index.js +122 -21
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -27,6 +27,7 @@ __export(src_exports, {
|
|
|
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,
|
|
@@ -39,10 +40,14 @@ __export(src_exports, {
|
|
|
39
40
|
isArrayEqual: () => isArrayEqual,
|
|
40
41
|
isBoolean: () => isBoolean,
|
|
41
42
|
isBrowser: () => isBrowser,
|
|
43
|
+
isDeepEqual: () => isDeepEqual,
|
|
44
|
+
isEmptyArray: () => isEmptyArray,
|
|
45
|
+
isEmptyObject: () => isEmptyObject,
|
|
42
46
|
isEmptyString: () => isEmptyString,
|
|
43
47
|
isEmptyStringOrWhitespace: () => isEmptyStringOrWhitespace,
|
|
44
48
|
isFunction: () => isFunction,
|
|
45
49
|
isInteger: () => isInteger,
|
|
50
|
+
isNaN: () => isNaN,
|
|
46
51
|
isNativePromise: () => isNativePromise,
|
|
47
52
|
isNil: () => isNil,
|
|
48
53
|
isNonEmptyString: () => isNonEmptyString,
|
|
@@ -56,6 +61,7 @@ __export(src_exports, {
|
|
|
56
61
|
isString: () => isString,
|
|
57
62
|
isUndefined: () => isUndefined,
|
|
58
63
|
isWhitespaceString: () => isWhitespaceString,
|
|
64
|
+
isZero: () => isZero,
|
|
59
65
|
join: () => join,
|
|
60
66
|
last: () => last,
|
|
61
67
|
mergeArrayable: () => mergeArrayable,
|
|
@@ -79,16 +85,54 @@ __export(src_exports, {
|
|
|
79
85
|
});
|
|
80
86
|
module.exports = __toCommonJS(src_exports);
|
|
81
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
|
+
|
|
82
111
|
// src/is/index.ts
|
|
83
112
|
function getObjectType(value) {
|
|
84
113
|
return Object.prototype.toString.call(value).slice(8, -1);
|
|
85
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
|
+
}
|
|
86
124
|
function isString(value) {
|
|
87
125
|
return typeof value === "string";
|
|
88
126
|
}
|
|
89
127
|
function isNumber(value) {
|
|
90
128
|
return typeof value === "number";
|
|
91
129
|
}
|
|
130
|
+
function isZero(value) {
|
|
131
|
+
return value === 0;
|
|
132
|
+
}
|
|
133
|
+
function isNaN(value) {
|
|
134
|
+
return Number.isNaN(value);
|
|
135
|
+
}
|
|
92
136
|
function isEmptyString(value) {
|
|
93
137
|
return isString(value) && value.length === 0;
|
|
94
138
|
}
|
|
@@ -116,18 +160,15 @@ function isFunction(value) {
|
|
|
116
160
|
function isArray(value) {
|
|
117
161
|
return Array.isArray(value);
|
|
118
162
|
}
|
|
119
|
-
function
|
|
120
|
-
return value ===
|
|
121
|
-
}
|
|
122
|
-
function isNull(value) {
|
|
123
|
-
return value === null;
|
|
124
|
-
}
|
|
125
|
-
function isNil(value) {
|
|
126
|
-
return isNull(value) || isUndefined(value);
|
|
163
|
+
function isEmptyArray(value) {
|
|
164
|
+
return isArray(value) && value.length === 0;
|
|
127
165
|
}
|
|
128
166
|
function isObject(value) {
|
|
129
167
|
return getObjectType(value) === "Object";
|
|
130
168
|
}
|
|
169
|
+
function isEmptyObject(value) {
|
|
170
|
+
return isObject(value) && Object.keys(value).length === 0;
|
|
171
|
+
}
|
|
131
172
|
function isRegExp(value) {
|
|
132
173
|
return getObjectType(value) === "RegExp";
|
|
133
174
|
}
|
|
@@ -165,18 +206,6 @@ function once(func) {
|
|
|
165
206
|
// src/env/isBrowser.ts
|
|
166
207
|
var isBrowser = () => typeof document !== "undefined";
|
|
167
208
|
|
|
168
|
-
// src/case.ts
|
|
169
|
-
var case_exports = {};
|
|
170
|
-
__export(case_exports, {
|
|
171
|
-
capitalize: () => capitalize
|
|
172
|
-
});
|
|
173
|
-
var import_scule = require("scule");
|
|
174
|
-
__reExport(case_exports, require("scule"));
|
|
175
|
-
var capitalize = import_scule.upperFirst;
|
|
176
|
-
|
|
177
|
-
// src/index.ts
|
|
178
|
-
__reExport(src_exports, case_exports, module.exports);
|
|
179
|
-
|
|
180
209
|
// src/misc/raf.ts
|
|
181
210
|
var root = isBrowser() ? window : globalThis;
|
|
182
211
|
var prev = Date.now();
|
|
@@ -396,6 +425,9 @@ function omit(object, ...keys) {
|
|
|
396
425
|
|
|
397
426
|
// src/object/hasOwn.ts
|
|
398
427
|
function hasOwn(object, key) {
|
|
428
|
+
if (object === null) {
|
|
429
|
+
return false;
|
|
430
|
+
}
|
|
399
431
|
return Object.prototype.hasOwnProperty.call(object, key);
|
|
400
432
|
}
|
|
401
433
|
|
|
@@ -411,6 +443,48 @@ function pick(object, keys) {
|
|
|
411
443
|
);
|
|
412
444
|
}
|
|
413
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
|
+
|
|
414
488
|
// src/object/isPlainObject.ts
|
|
415
489
|
function isPlainObject(value) {
|
|
416
490
|
if (!isObject(value)) return false;
|
|
@@ -441,6 +515,27 @@ function sortObject(obj, options = {}) {
|
|
|
441
515
|
}
|
|
442
516
|
return sortKeys(obj);
|
|
443
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);
|
|
444
539
|
// Annotate the CommonJS export names for ESM import in node:
|
|
445
540
|
0 && (module.exports = {
|
|
446
541
|
NOOP,
|
|
@@ -449,6 +544,7 @@ function sortObject(obj, options = {}) {
|
|
|
449
544
|
capitalize,
|
|
450
545
|
chunk,
|
|
451
546
|
clamp,
|
|
547
|
+
cleanObject,
|
|
452
548
|
days,
|
|
453
549
|
debounce,
|
|
454
550
|
ensurePrefix,
|
|
@@ -461,10 +557,14 @@ function sortObject(obj, options = {}) {
|
|
|
461
557
|
isArrayEqual,
|
|
462
558
|
isBoolean,
|
|
463
559
|
isBrowser,
|
|
560
|
+
isDeepEqual,
|
|
561
|
+
isEmptyArray,
|
|
562
|
+
isEmptyObject,
|
|
464
563
|
isEmptyString,
|
|
465
564
|
isEmptyStringOrWhitespace,
|
|
466
565
|
isFunction,
|
|
467
566
|
isInteger,
|
|
567
|
+
isNaN,
|
|
468
568
|
isNativePromise,
|
|
469
569
|
isNil,
|
|
470
570
|
isNonEmptyString,
|
|
@@ -478,6 +578,7 @@ function sortObject(obj, options = {}) {
|
|
|
478
578
|
isString,
|
|
479
579
|
isUndefined,
|
|
480
580
|
isWhitespaceString,
|
|
581
|
+
isZero,
|
|
481
582
|
join,
|
|
482
583
|
last,
|
|
483
584
|
mergeArrayable,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
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
|
|
@@ -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,16 +61,6 @@ 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
|
-
* @module 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
|
*/
|
|
@@ -269,7 +268,71 @@ declare function omit<T, K extends keyof T>(object: T, ...keys: K[]): Omit<T, K>
|
|
|
269
268
|
|
|
270
269
|
declare function pick<T, K extends keyof T>(object: T, keys: K[]): Pick<T, K>;
|
|
271
270
|
|
|
272
|
-
|
|
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;
|
|
273
336
|
|
|
274
337
|
interface SortObjectOptions {
|
|
275
338
|
/**
|
|
@@ -287,4 +350,14 @@ interface SortObjectOptions {
|
|
|
287
350
|
*/
|
|
288
351
|
declare function sortObject<T extends Record<string, any>>(obj: T, options?: SortObjectOptions): T;
|
|
289
352
|
|
|
290
|
-
|
|
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,6 +1,11 @@
|
|
|
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
|
|
@@ -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,16 +61,6 @@ 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
|
-
* @module 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
|
*/
|
|
@@ -269,7 +268,71 @@ declare function omit<T, K extends keyof T>(object: T, ...keys: K[]): Omit<T, K>
|
|
|
269
268
|
|
|
270
269
|
declare function pick<T, K extends keyof T>(object: T, keys: K[]): Pick<T, K>;
|
|
271
270
|
|
|
272
|
-
|
|
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;
|
|
273
336
|
|
|
274
337
|
interface SortObjectOptions {
|
|
275
338
|
/**
|
|
@@ -287,4 +350,14 @@ interface SortObjectOptions {
|
|
|
287
350
|
*/
|
|
288
351
|
declare function sortObject<T extends Record<string, any>>(obj: T, options?: SortObjectOptions): T;
|
|
289
352
|
|
|
290
|
-
|
|
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
|
@@ -25,6 +25,7 @@ __export(src_exports, {
|
|
|
25
25
|
capitalize: () => capitalize,
|
|
26
26
|
chunk: () => chunk,
|
|
27
27
|
clamp: () => clamp,
|
|
28
|
+
cleanObject: () => cleanObject,
|
|
28
29
|
days: () => days,
|
|
29
30
|
debounce: () => debounce,
|
|
30
31
|
ensurePrefix: () => ensurePrefix,
|
|
@@ -37,10 +38,14 @@ __export(src_exports, {
|
|
|
37
38
|
isArrayEqual: () => isArrayEqual,
|
|
38
39
|
isBoolean: () => isBoolean,
|
|
39
40
|
isBrowser: () => isBrowser,
|
|
41
|
+
isDeepEqual: () => isDeepEqual,
|
|
42
|
+
isEmptyArray: () => isEmptyArray,
|
|
43
|
+
isEmptyObject: () => isEmptyObject,
|
|
40
44
|
isEmptyString: () => isEmptyString,
|
|
41
45
|
isEmptyStringOrWhitespace: () => isEmptyStringOrWhitespace,
|
|
42
46
|
isFunction: () => isFunction,
|
|
43
47
|
isInteger: () => isInteger,
|
|
48
|
+
isNaN: () => isNaN,
|
|
44
49
|
isNativePromise: () => isNativePromise,
|
|
45
50
|
isNil: () => isNil,
|
|
46
51
|
isNonEmptyString: () => isNonEmptyString,
|
|
@@ -54,6 +59,7 @@ __export(src_exports, {
|
|
|
54
59
|
isString: () => isString,
|
|
55
60
|
isUndefined: () => isUndefined,
|
|
56
61
|
isWhitespaceString: () => isWhitespaceString,
|
|
62
|
+
isZero: () => isZero,
|
|
57
63
|
join: () => join,
|
|
58
64
|
last: () => last,
|
|
59
65
|
mergeArrayable: () => mergeArrayable,
|
|
@@ -76,16 +82,54 @@ __export(src_exports, {
|
|
|
76
82
|
weeks: () => weeks
|
|
77
83
|
});
|
|
78
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
|
+
|
|
79
108
|
// src/is/index.ts
|
|
80
109
|
function getObjectType(value) {
|
|
81
110
|
return Object.prototype.toString.call(value).slice(8, -1);
|
|
82
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
|
+
}
|
|
83
121
|
function isString(value) {
|
|
84
122
|
return typeof value === "string";
|
|
85
123
|
}
|
|
86
124
|
function isNumber(value) {
|
|
87
125
|
return typeof value === "number";
|
|
88
126
|
}
|
|
127
|
+
function isZero(value) {
|
|
128
|
+
return value === 0;
|
|
129
|
+
}
|
|
130
|
+
function isNaN(value) {
|
|
131
|
+
return Number.isNaN(value);
|
|
132
|
+
}
|
|
89
133
|
function isEmptyString(value) {
|
|
90
134
|
return isString(value) && value.length === 0;
|
|
91
135
|
}
|
|
@@ -113,18 +157,15 @@ function isFunction(value) {
|
|
|
113
157
|
function isArray(value) {
|
|
114
158
|
return Array.isArray(value);
|
|
115
159
|
}
|
|
116
|
-
function
|
|
117
|
-
return value ===
|
|
118
|
-
}
|
|
119
|
-
function isNull(value) {
|
|
120
|
-
return value === null;
|
|
121
|
-
}
|
|
122
|
-
function isNil(value) {
|
|
123
|
-
return isNull(value) || isUndefined(value);
|
|
160
|
+
function isEmptyArray(value) {
|
|
161
|
+
return isArray(value) && value.length === 0;
|
|
124
162
|
}
|
|
125
163
|
function isObject(value) {
|
|
126
164
|
return getObjectType(value) === "Object";
|
|
127
165
|
}
|
|
166
|
+
function isEmptyObject(value) {
|
|
167
|
+
return isObject(value) && Object.keys(value).length === 0;
|
|
168
|
+
}
|
|
128
169
|
function isRegExp(value) {
|
|
129
170
|
return getObjectType(value) === "RegExp";
|
|
130
171
|
}
|
|
@@ -162,19 +203,6 @@ function once(func) {
|
|
|
162
203
|
// src/env/isBrowser.ts
|
|
163
204
|
var isBrowser = () => typeof document !== "undefined";
|
|
164
205
|
|
|
165
|
-
// src/case.ts
|
|
166
|
-
var case_exports = {};
|
|
167
|
-
__export(case_exports, {
|
|
168
|
-
capitalize: () => capitalize
|
|
169
|
-
});
|
|
170
|
-
__reExport(case_exports, scule_star);
|
|
171
|
-
import { upperFirst } from "scule";
|
|
172
|
-
import * as scule_star from "scule";
|
|
173
|
-
var capitalize = upperFirst;
|
|
174
|
-
|
|
175
|
-
// src/index.ts
|
|
176
|
-
__reExport(src_exports, case_exports);
|
|
177
|
-
|
|
178
206
|
// src/misc/raf.ts
|
|
179
207
|
var root = isBrowser() ? window : globalThis;
|
|
180
208
|
var prev = Date.now();
|
|
@@ -394,6 +422,9 @@ function omit(object, ...keys) {
|
|
|
394
422
|
|
|
395
423
|
// src/object/hasOwn.ts
|
|
396
424
|
function hasOwn(object, key) {
|
|
425
|
+
if (object === null) {
|
|
426
|
+
return false;
|
|
427
|
+
}
|
|
397
428
|
return Object.prototype.hasOwnProperty.call(object, key);
|
|
398
429
|
}
|
|
399
430
|
|
|
@@ -409,6 +440,48 @@ function pick(object, keys) {
|
|
|
409
440
|
);
|
|
410
441
|
}
|
|
411
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
|
+
|
|
412
485
|
// src/object/isPlainObject.ts
|
|
413
486
|
function isPlainObject(value) {
|
|
414
487
|
if (!isObject(value)) return false;
|
|
@@ -439,6 +512,28 @@ function sortObject(obj, options = {}) {
|
|
|
439
512
|
}
|
|
440
513
|
return sortKeys(obj);
|
|
441
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);
|
|
442
537
|
export {
|
|
443
538
|
NOOP,
|
|
444
539
|
at,
|
|
@@ -446,6 +541,7 @@ export {
|
|
|
446
541
|
capitalize,
|
|
447
542
|
chunk,
|
|
448
543
|
clamp,
|
|
544
|
+
cleanObject,
|
|
449
545
|
days,
|
|
450
546
|
debounce,
|
|
451
547
|
ensurePrefix,
|
|
@@ -458,10 +554,14 @@ export {
|
|
|
458
554
|
isArrayEqual,
|
|
459
555
|
isBoolean,
|
|
460
556
|
isBrowser,
|
|
557
|
+
isDeepEqual,
|
|
558
|
+
isEmptyArray,
|
|
559
|
+
isEmptyObject,
|
|
461
560
|
isEmptyString,
|
|
462
561
|
isEmptyStringOrWhitespace,
|
|
463
562
|
isFunction,
|
|
464
563
|
isInteger,
|
|
564
|
+
isNaN,
|
|
465
565
|
isNativePromise,
|
|
466
566
|
isNil,
|
|
467
567
|
isNonEmptyString,
|
|
@@ -475,6 +575,7 @@ export {
|
|
|
475
575
|
isString,
|
|
476
576
|
isUndefined,
|
|
477
577
|
isWhitespaceString,
|
|
578
|
+
isZero,
|
|
478
579
|
join,
|
|
479
580
|
last,
|
|
480
581
|
mergeArrayable,
|