@ntnyq/utils 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +107 -0
- package/dist/index.d.cts +57 -1
- package/dist/index.d.ts +57 -1
- package/dist/index.js +93 -0
- package/package.json +10 -11
package/dist/index.cjs
CHANGED
|
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
NOOP: () => NOOP,
|
|
24
|
+
at: () => at,
|
|
24
25
|
cAF: () => cAF,
|
|
25
26
|
camelCase: () => camelCase,
|
|
26
27
|
capitalize: () => capitalize,
|
|
@@ -31,6 +32,7 @@ __export(src_exports, {
|
|
|
31
32
|
ensurePrefix: () => ensurePrefix,
|
|
32
33
|
ensureSuffix: () => ensureSuffix,
|
|
33
34
|
flatCase: () => flatCase,
|
|
35
|
+
flattenArrayable: () => flattenArrayable,
|
|
34
36
|
getObjectType: () => getObjectType,
|
|
35
37
|
hasOwn: () => hasOwn,
|
|
36
38
|
hours: () => hours,
|
|
@@ -38,18 +40,29 @@ __export(src_exports, {
|
|
|
38
40
|
isArrayEqual: () => isArrayEqual,
|
|
39
41
|
isBoolean: () => isBoolean,
|
|
40
42
|
isBrowser: () => isBrowser,
|
|
43
|
+
isEmptyString: () => isEmptyString,
|
|
44
|
+
isEmptyStringOrWhitespace: () => isEmptyStringOrWhitespace,
|
|
41
45
|
isFunction: () => isFunction,
|
|
42
46
|
isInteger: () => isInteger,
|
|
43
47
|
isNativePromise: () => isNativePromise,
|
|
48
|
+
isNil: () => isNil,
|
|
49
|
+
isNonEmptyString: () => isNonEmptyString,
|
|
44
50
|
isNull: () => isNull,
|
|
45
51
|
isNumber: () => isNumber,
|
|
52
|
+
isNumbericString: () => isNumbericString,
|
|
53
|
+
isObject: () => isObject,
|
|
46
54
|
isPromise: () => isPromise,
|
|
55
|
+
isRegExp: () => isRegExp,
|
|
56
|
+
isSet: () => isSet,
|
|
47
57
|
isString: () => isString,
|
|
48
58
|
isUndefined: () => isUndefined,
|
|
49
59
|
isUppercase: () => isUppercase,
|
|
60
|
+
isWhitespaceString: () => isWhitespaceString,
|
|
50
61
|
join: () => join,
|
|
51
62
|
kebabCase: () => kebabCase,
|
|
63
|
+
last: () => last,
|
|
52
64
|
lowerFirst: () => lowerFirst,
|
|
65
|
+
mergeArrayable: () => mergeArrayable,
|
|
53
66
|
minutes: () => minutes,
|
|
54
67
|
noop: () => noop,
|
|
55
68
|
omit: () => omit,
|
|
@@ -60,6 +73,7 @@ __export(src_exports, {
|
|
|
60
73
|
seconds: () => seconds,
|
|
61
74
|
slash: () => slash,
|
|
62
75
|
snakeCase: () => snakeCase,
|
|
76
|
+
sortObject: () => sortObject,
|
|
63
77
|
splitByCase: () => splitByCase,
|
|
64
78
|
throttle: () => throttle,
|
|
65
79
|
titleCase: () => titleCase,
|
|
@@ -85,6 +99,21 @@ function isString(value) {
|
|
|
85
99
|
function isNumber(value) {
|
|
86
100
|
return typeof value === "number";
|
|
87
101
|
}
|
|
102
|
+
function isEmptyString(value) {
|
|
103
|
+
return isString(value) && value.length === 0;
|
|
104
|
+
}
|
|
105
|
+
function isNonEmptyString(value) {
|
|
106
|
+
return isString(value) && value.length > 0;
|
|
107
|
+
}
|
|
108
|
+
function isWhitespaceString(value) {
|
|
109
|
+
return isString(value) && /^\s*$/.test(value);
|
|
110
|
+
}
|
|
111
|
+
function isEmptyStringOrWhitespace(value) {
|
|
112
|
+
return isEmptyString(value) || isWhitespaceString(value);
|
|
113
|
+
}
|
|
114
|
+
function isNumbericString(value) {
|
|
115
|
+
return isString(value) && !isEmptyStringOrWhitespace(value) && !Number.isNaN(Number(value));
|
|
116
|
+
}
|
|
88
117
|
function isInteger(value) {
|
|
89
118
|
return Number.isInteger(value);
|
|
90
119
|
}
|
|
@@ -103,6 +132,18 @@ function isUndefined(value) {
|
|
|
103
132
|
function isNull(value) {
|
|
104
133
|
return value === null;
|
|
105
134
|
}
|
|
135
|
+
function isNil(value) {
|
|
136
|
+
return isNull(value) || isUndefined(value);
|
|
137
|
+
}
|
|
138
|
+
function isObject(value) {
|
|
139
|
+
return getObjectType(value) === "Object";
|
|
140
|
+
}
|
|
141
|
+
function isRegExp(value) {
|
|
142
|
+
return getObjectType(value) === "RegExp";
|
|
143
|
+
}
|
|
144
|
+
function isSet(value) {
|
|
145
|
+
return getObjectType(value) === "Set";
|
|
146
|
+
}
|
|
106
147
|
function isNativePromise(value) {
|
|
107
148
|
return getObjectType(value) === "Promise";
|
|
108
149
|
}
|
|
@@ -325,6 +366,19 @@ var warnOnce = (message) => {
|
|
|
325
366
|
console.warn(message);
|
|
326
367
|
};
|
|
327
368
|
|
|
369
|
+
// src/array/at.ts
|
|
370
|
+
function at(array, index) {
|
|
371
|
+
const length = array.length;
|
|
372
|
+
if (!length) return void 0;
|
|
373
|
+
if (index < 0) {
|
|
374
|
+
index += length;
|
|
375
|
+
}
|
|
376
|
+
return array[index];
|
|
377
|
+
}
|
|
378
|
+
function last(array) {
|
|
379
|
+
return at(array, -1);
|
|
380
|
+
}
|
|
381
|
+
|
|
328
382
|
// src/array/chunk.ts
|
|
329
383
|
function chunk(array, size) {
|
|
330
384
|
const result = [];
|
|
@@ -354,6 +408,14 @@ function toArray(array) {
|
|
|
354
408
|
return Array.isArray(array) ? array : [array];
|
|
355
409
|
}
|
|
356
410
|
|
|
411
|
+
// src/array/arrayable.ts
|
|
412
|
+
function flattenArrayable(array) {
|
|
413
|
+
return toArray(array).flat(1);
|
|
414
|
+
}
|
|
415
|
+
function mergeArrayable(...args) {
|
|
416
|
+
return args.flatMap((i) => toArray(i));
|
|
417
|
+
}
|
|
418
|
+
|
|
357
419
|
// src/array/isArrayEqual.ts
|
|
358
420
|
function isArrayEqual(array1, array2) {
|
|
359
421
|
if (array1.length !== array2.length) {
|
|
@@ -429,9 +491,41 @@ function pick(object, keys) {
|
|
|
429
491
|
})
|
|
430
492
|
);
|
|
431
493
|
}
|
|
494
|
+
|
|
495
|
+
// src/object/isPlainObject.ts
|
|
496
|
+
function isPlainObject(value) {
|
|
497
|
+
if (!isObject(value)) return false;
|
|
498
|
+
const prototype = Object.getPrototypeOf(value);
|
|
499
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// src/object/sortObject.ts
|
|
503
|
+
function sortObject(obj, options = {}) {
|
|
504
|
+
const { compareFn = (a, b) => a.localeCompare(b) } = options;
|
|
505
|
+
function sortKeys(obj2) {
|
|
506
|
+
const sortedKeys = Object.keys(obj2).sort(compareFn);
|
|
507
|
+
const result = {};
|
|
508
|
+
for (const key of sortedKeys) {
|
|
509
|
+
const value = obj2[key];
|
|
510
|
+
let newValue;
|
|
511
|
+
if (options.deep && isPlainObject(value)) {
|
|
512
|
+
newValue = sortKeys(value);
|
|
513
|
+
} else {
|
|
514
|
+
newValue = value;
|
|
515
|
+
}
|
|
516
|
+
Object.defineProperty(result, key, {
|
|
517
|
+
...Object.getOwnPropertyDescriptor(obj2, key),
|
|
518
|
+
value: newValue
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
return result;
|
|
522
|
+
}
|
|
523
|
+
return sortKeys(obj);
|
|
524
|
+
}
|
|
432
525
|
// Annotate the CommonJS export names for ESM import in node:
|
|
433
526
|
0 && (module.exports = {
|
|
434
527
|
NOOP,
|
|
528
|
+
at,
|
|
435
529
|
cAF,
|
|
436
530
|
camelCase,
|
|
437
531
|
capitalize,
|
|
@@ -442,6 +536,7 @@ function pick(object, keys) {
|
|
|
442
536
|
ensurePrefix,
|
|
443
537
|
ensureSuffix,
|
|
444
538
|
flatCase,
|
|
539
|
+
flattenArrayable,
|
|
445
540
|
getObjectType,
|
|
446
541
|
hasOwn,
|
|
447
542
|
hours,
|
|
@@ -449,18 +544,29 @@ function pick(object, keys) {
|
|
|
449
544
|
isArrayEqual,
|
|
450
545
|
isBoolean,
|
|
451
546
|
isBrowser,
|
|
547
|
+
isEmptyString,
|
|
548
|
+
isEmptyStringOrWhitespace,
|
|
452
549
|
isFunction,
|
|
453
550
|
isInteger,
|
|
454
551
|
isNativePromise,
|
|
552
|
+
isNil,
|
|
553
|
+
isNonEmptyString,
|
|
455
554
|
isNull,
|
|
456
555
|
isNumber,
|
|
556
|
+
isNumbericString,
|
|
557
|
+
isObject,
|
|
457
558
|
isPromise,
|
|
559
|
+
isRegExp,
|
|
560
|
+
isSet,
|
|
458
561
|
isString,
|
|
459
562
|
isUndefined,
|
|
460
563
|
isUppercase,
|
|
564
|
+
isWhitespaceString,
|
|
461
565
|
join,
|
|
462
566
|
kebabCase,
|
|
567
|
+
last,
|
|
463
568
|
lowerFirst,
|
|
569
|
+
mergeArrayable,
|
|
464
570
|
minutes,
|
|
465
571
|
noop,
|
|
466
572
|
omit,
|
|
@@ -471,6 +577,7 @@ function pick(object, keys) {
|
|
|
471
577
|
seconds,
|
|
472
578
|
slash,
|
|
473
579
|
snakeCase,
|
|
580
|
+
sortObject,
|
|
474
581
|
splitByCase,
|
|
475
582
|
throttle,
|
|
476
583
|
titleCase,
|
package/dist/index.d.cts
CHANGED
|
@@ -6,15 +6,28 @@ export * from 'scule';
|
|
|
6
6
|
* @category is
|
|
7
7
|
* @copyright {@link https://github.com/sindresorhus/is}
|
|
8
8
|
*/
|
|
9
|
+
type Whitespace = ' ';
|
|
10
|
+
type NonEmptyString = string & {
|
|
11
|
+
0: '';
|
|
12
|
+
};
|
|
9
13
|
declare function getObjectType(value: unknown): string;
|
|
10
14
|
declare function isString(value: unknown): value is string;
|
|
11
15
|
declare function isNumber(value: unknown): value is number;
|
|
16
|
+
declare function isEmptyString(value: unknown): value is '';
|
|
17
|
+
declare function isNonEmptyString(value: unknown): value is NonEmptyString;
|
|
18
|
+
declare function isWhitespaceString(value: unknown): value is Whitespace;
|
|
19
|
+
declare function isEmptyStringOrWhitespace(value: unknown): value is '' | Whitespace;
|
|
20
|
+
declare function isNumbericString(value: unknown): value is `${number}`;
|
|
12
21
|
declare function isInteger(value: unknown): value is number;
|
|
13
22
|
declare function isBoolean(value: unknown): value is boolean;
|
|
14
23
|
declare function isFunction(value: unknown): value is Function;
|
|
15
24
|
declare function isArray(value: unknown): value is unknown[];
|
|
16
25
|
declare function isUndefined(value: unknown): value is undefined;
|
|
17
26
|
declare function isNull(value: unknown): value is null;
|
|
27
|
+
declare function isNil(value: unknown): value is null | undefined;
|
|
28
|
+
declare function isObject(value: unknown): value is object;
|
|
29
|
+
declare function isRegExp(value: unknown): value is RegExp;
|
|
30
|
+
declare function isSet<Value = unknown>(value: unknown): value is Set<Value>;
|
|
18
31
|
declare function isNativePromise<T = unknown>(value: unknown): value is Promise<T>;
|
|
19
32
|
declare function isPromise<T = unknown>(value: unknown): value is Promise<T>;
|
|
20
33
|
|
|
@@ -123,6 +136,20 @@ declare function debounce<T extends ((...args: any[]) => undefined | void) | und
|
|
|
123
136
|
|
|
124
137
|
declare const warnOnce: (message: string) => void;
|
|
125
138
|
|
|
139
|
+
/**
|
|
140
|
+
* Get array item by index, negative for backward
|
|
141
|
+
* @param array - given array
|
|
142
|
+
* @param index - index of item
|
|
143
|
+
* @returns undefined if not match, otherwise matched item
|
|
144
|
+
*/
|
|
145
|
+
declare function at<T>(array: readonly T[], index: number): T | undefined;
|
|
146
|
+
/**
|
|
147
|
+
* Get the last item of given array
|
|
148
|
+
* @param array - given array
|
|
149
|
+
* @returns undefined if empty array, otherwise last item
|
|
150
|
+
*/
|
|
151
|
+
declare function last<T>(array: readonly T[]): T | undefined;
|
|
152
|
+
|
|
126
153
|
/**
|
|
127
154
|
* Splits an array into smaller chunks of a given size.
|
|
128
155
|
* @param array The array to split
|
|
@@ -163,6 +190,19 @@ type PrimitiveType = number | bigint | string | boolean | symbol | null | undefi
|
|
|
163
190
|
*/
|
|
164
191
|
declare function toArray<T>(array?: Nullable<Arrayable<T>>): T[];
|
|
165
192
|
|
|
193
|
+
/**
|
|
194
|
+
* Convert `Arrayable<T>` to `Array<T>` and flatten the result
|
|
195
|
+
* @param array - given array
|
|
196
|
+
* @returns Array<T>
|
|
197
|
+
*/
|
|
198
|
+
declare function flattenArrayable<T>(array?: Nullable<Arrayable<T | Array<T>>>): Array<T>;
|
|
199
|
+
/**
|
|
200
|
+
* Use rest arguments to merge arrays
|
|
201
|
+
* @param args - rest arguments
|
|
202
|
+
* @returns Array<T>
|
|
203
|
+
*/
|
|
204
|
+
declare function mergeArrayable<T>(...args: Nullable<Arrayable<T>>[]): Array<T>;
|
|
205
|
+
|
|
166
206
|
declare function isArrayEqual(array1: unknown[], array2: unknown[]): boolean;
|
|
167
207
|
|
|
168
208
|
type JoinableValue = string | number | null | undefined;
|
|
@@ -212,4 +252,20 @@ declare function pick<T, K extends keyof T>(object: T, keys: K[]): Pick<T, K>;
|
|
|
212
252
|
|
|
213
253
|
declare function hasOwn<T, K extends keyof T>(object: T, key: K): boolean;
|
|
214
254
|
|
|
215
|
-
|
|
255
|
+
interface SortObjectOptions {
|
|
256
|
+
/**
|
|
257
|
+
* Recursive sorting
|
|
258
|
+
* @default false
|
|
259
|
+
*/
|
|
260
|
+
deep?: boolean;
|
|
261
|
+
/**
|
|
262
|
+
* Compare function
|
|
263
|
+
*/
|
|
264
|
+
compareFn?: (left: string, right: string) => number;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Sort object properties
|
|
268
|
+
*/
|
|
269
|
+
declare function sortObject<T extends Record<string, any>>(obj: T, options?: SortObjectOptions): T;
|
|
270
|
+
|
|
271
|
+
export { type AnyFn, type Arrayable, type Awaitable, type MayBe, NOOP, type NonEmptyString, type Nullable, type Prettify, type PrettifyV2, type PrimitiveType, type SortObjectOptions, type ThrottleDebounceOptions, type Whitespace, at, cAF, capitalize, chunk, clamp, days, debounce, ensurePrefix, ensureSuffix, flattenArrayable, getObjectType, hasOwn, hours, isArray, isArrayEqual, isBoolean, isBrowser, isEmptyString, isEmptyStringOrWhitespace, isFunction, isInteger, isNativePromise, isNil, isNonEmptyString, isNull, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isUndefined, isWhitespaceString, 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
|
@@ -6,15 +6,28 @@ export * from 'scule';
|
|
|
6
6
|
* @category is
|
|
7
7
|
* @copyright {@link https://github.com/sindresorhus/is}
|
|
8
8
|
*/
|
|
9
|
+
type Whitespace = ' ';
|
|
10
|
+
type NonEmptyString = string & {
|
|
11
|
+
0: '';
|
|
12
|
+
};
|
|
9
13
|
declare function getObjectType(value: unknown): string;
|
|
10
14
|
declare function isString(value: unknown): value is string;
|
|
11
15
|
declare function isNumber(value: unknown): value is number;
|
|
16
|
+
declare function isEmptyString(value: unknown): value is '';
|
|
17
|
+
declare function isNonEmptyString(value: unknown): value is NonEmptyString;
|
|
18
|
+
declare function isWhitespaceString(value: unknown): value is Whitespace;
|
|
19
|
+
declare function isEmptyStringOrWhitespace(value: unknown): value is '' | Whitespace;
|
|
20
|
+
declare function isNumbericString(value: unknown): value is `${number}`;
|
|
12
21
|
declare function isInteger(value: unknown): value is number;
|
|
13
22
|
declare function isBoolean(value: unknown): value is boolean;
|
|
14
23
|
declare function isFunction(value: unknown): value is Function;
|
|
15
24
|
declare function isArray(value: unknown): value is unknown[];
|
|
16
25
|
declare function isUndefined(value: unknown): value is undefined;
|
|
17
26
|
declare function isNull(value: unknown): value is null;
|
|
27
|
+
declare function isNil(value: unknown): value is null | undefined;
|
|
28
|
+
declare function isObject(value: unknown): value is object;
|
|
29
|
+
declare function isRegExp(value: unknown): value is RegExp;
|
|
30
|
+
declare function isSet<Value = unknown>(value: unknown): value is Set<Value>;
|
|
18
31
|
declare function isNativePromise<T = unknown>(value: unknown): value is Promise<T>;
|
|
19
32
|
declare function isPromise<T = unknown>(value: unknown): value is Promise<T>;
|
|
20
33
|
|
|
@@ -123,6 +136,20 @@ declare function debounce<T extends ((...args: any[]) => undefined | void) | und
|
|
|
123
136
|
|
|
124
137
|
declare const warnOnce: (message: string) => void;
|
|
125
138
|
|
|
139
|
+
/**
|
|
140
|
+
* Get array item by index, negative for backward
|
|
141
|
+
* @param array - given array
|
|
142
|
+
* @param index - index of item
|
|
143
|
+
* @returns undefined if not match, otherwise matched item
|
|
144
|
+
*/
|
|
145
|
+
declare function at<T>(array: readonly T[], index: number): T | undefined;
|
|
146
|
+
/**
|
|
147
|
+
* Get the last item of given array
|
|
148
|
+
* @param array - given array
|
|
149
|
+
* @returns undefined if empty array, otherwise last item
|
|
150
|
+
*/
|
|
151
|
+
declare function last<T>(array: readonly T[]): T | undefined;
|
|
152
|
+
|
|
126
153
|
/**
|
|
127
154
|
* Splits an array into smaller chunks of a given size.
|
|
128
155
|
* @param array The array to split
|
|
@@ -163,6 +190,19 @@ type PrimitiveType = number | bigint | string | boolean | symbol | null | undefi
|
|
|
163
190
|
*/
|
|
164
191
|
declare function toArray<T>(array?: Nullable<Arrayable<T>>): T[];
|
|
165
192
|
|
|
193
|
+
/**
|
|
194
|
+
* Convert `Arrayable<T>` to `Array<T>` and flatten the result
|
|
195
|
+
* @param array - given array
|
|
196
|
+
* @returns Array<T>
|
|
197
|
+
*/
|
|
198
|
+
declare function flattenArrayable<T>(array?: Nullable<Arrayable<T | Array<T>>>): Array<T>;
|
|
199
|
+
/**
|
|
200
|
+
* Use rest arguments to merge arrays
|
|
201
|
+
* @param args - rest arguments
|
|
202
|
+
* @returns Array<T>
|
|
203
|
+
*/
|
|
204
|
+
declare function mergeArrayable<T>(...args: Nullable<Arrayable<T>>[]): Array<T>;
|
|
205
|
+
|
|
166
206
|
declare function isArrayEqual(array1: unknown[], array2: unknown[]): boolean;
|
|
167
207
|
|
|
168
208
|
type JoinableValue = string | number | null | undefined;
|
|
@@ -212,4 +252,20 @@ declare function pick<T, K extends keyof T>(object: T, keys: K[]): Pick<T, K>;
|
|
|
212
252
|
|
|
213
253
|
declare function hasOwn<T, K extends keyof T>(object: T, key: K): boolean;
|
|
214
254
|
|
|
215
|
-
|
|
255
|
+
interface SortObjectOptions {
|
|
256
|
+
/**
|
|
257
|
+
* Recursive sorting
|
|
258
|
+
* @default false
|
|
259
|
+
*/
|
|
260
|
+
deep?: boolean;
|
|
261
|
+
/**
|
|
262
|
+
* Compare function
|
|
263
|
+
*/
|
|
264
|
+
compareFn?: (left: string, right: string) => number;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Sort object properties
|
|
268
|
+
*/
|
|
269
|
+
declare function sortObject<T extends Record<string, any>>(obj: T, options?: SortObjectOptions): T;
|
|
270
|
+
|
|
271
|
+
export { type AnyFn, type Arrayable, type Awaitable, type MayBe, NOOP, type NonEmptyString, type Nullable, type Prettify, type PrettifyV2, type PrimitiveType, type SortObjectOptions, type ThrottleDebounceOptions, type Whitespace, at, cAF, capitalize, chunk, clamp, days, debounce, ensurePrefix, ensureSuffix, flattenArrayable, getObjectType, hasOwn, hours, isArray, isArrayEqual, isBoolean, isBrowser, isEmptyString, isEmptyStringOrWhitespace, isFunction, isInteger, isNativePromise, isNil, isNonEmptyString, isNull, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isUndefined, isWhitespaceString, 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
|
@@ -8,6 +8,21 @@ function isString(value) {
|
|
|
8
8
|
function isNumber(value) {
|
|
9
9
|
return typeof value === "number";
|
|
10
10
|
}
|
|
11
|
+
function isEmptyString(value) {
|
|
12
|
+
return isString(value) && value.length === 0;
|
|
13
|
+
}
|
|
14
|
+
function isNonEmptyString(value) {
|
|
15
|
+
return isString(value) && value.length > 0;
|
|
16
|
+
}
|
|
17
|
+
function isWhitespaceString(value) {
|
|
18
|
+
return isString(value) && /^\s*$/.test(value);
|
|
19
|
+
}
|
|
20
|
+
function isEmptyStringOrWhitespace(value) {
|
|
21
|
+
return isEmptyString(value) || isWhitespaceString(value);
|
|
22
|
+
}
|
|
23
|
+
function isNumbericString(value) {
|
|
24
|
+
return isString(value) && !isEmptyStringOrWhitespace(value) && !Number.isNaN(Number(value));
|
|
25
|
+
}
|
|
11
26
|
function isInteger(value) {
|
|
12
27
|
return Number.isInteger(value);
|
|
13
28
|
}
|
|
@@ -26,6 +41,18 @@ function isUndefined(value) {
|
|
|
26
41
|
function isNull(value) {
|
|
27
42
|
return value === null;
|
|
28
43
|
}
|
|
44
|
+
function isNil(value) {
|
|
45
|
+
return isNull(value) || isUndefined(value);
|
|
46
|
+
}
|
|
47
|
+
function isObject(value) {
|
|
48
|
+
return getObjectType(value) === "Object";
|
|
49
|
+
}
|
|
50
|
+
function isRegExp(value) {
|
|
51
|
+
return getObjectType(value) === "RegExp";
|
|
52
|
+
}
|
|
53
|
+
function isSet(value) {
|
|
54
|
+
return getObjectType(value) === "Set";
|
|
55
|
+
}
|
|
29
56
|
function isNativePromise(value) {
|
|
30
57
|
return getObjectType(value) === "Promise";
|
|
31
58
|
}
|
|
@@ -248,6 +275,19 @@ var warnOnce = (message) => {
|
|
|
248
275
|
console.warn(message);
|
|
249
276
|
};
|
|
250
277
|
|
|
278
|
+
// src/array/at.ts
|
|
279
|
+
function at(array, index) {
|
|
280
|
+
const length = array.length;
|
|
281
|
+
if (!length) return void 0;
|
|
282
|
+
if (index < 0) {
|
|
283
|
+
index += length;
|
|
284
|
+
}
|
|
285
|
+
return array[index];
|
|
286
|
+
}
|
|
287
|
+
function last(array) {
|
|
288
|
+
return at(array, -1);
|
|
289
|
+
}
|
|
290
|
+
|
|
251
291
|
// src/array/chunk.ts
|
|
252
292
|
function chunk(array, size) {
|
|
253
293
|
const result = [];
|
|
@@ -277,6 +317,14 @@ function toArray(array) {
|
|
|
277
317
|
return Array.isArray(array) ? array : [array];
|
|
278
318
|
}
|
|
279
319
|
|
|
320
|
+
// src/array/arrayable.ts
|
|
321
|
+
function flattenArrayable(array) {
|
|
322
|
+
return toArray(array).flat(1);
|
|
323
|
+
}
|
|
324
|
+
function mergeArrayable(...args) {
|
|
325
|
+
return args.flatMap((i) => toArray(i));
|
|
326
|
+
}
|
|
327
|
+
|
|
280
328
|
// src/array/isArrayEqual.ts
|
|
281
329
|
function isArrayEqual(array1, array2) {
|
|
282
330
|
if (array1.length !== array2.length) {
|
|
@@ -352,8 +400,40 @@ function pick(object, keys) {
|
|
|
352
400
|
})
|
|
353
401
|
);
|
|
354
402
|
}
|
|
403
|
+
|
|
404
|
+
// src/object/isPlainObject.ts
|
|
405
|
+
function isPlainObject(value) {
|
|
406
|
+
if (!isObject(value)) return false;
|
|
407
|
+
const prototype = Object.getPrototypeOf(value);
|
|
408
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// src/object/sortObject.ts
|
|
412
|
+
function sortObject(obj, options = {}) {
|
|
413
|
+
const { compareFn = (a, b) => a.localeCompare(b) } = options;
|
|
414
|
+
function sortKeys(obj2) {
|
|
415
|
+
const sortedKeys = Object.keys(obj2).sort(compareFn);
|
|
416
|
+
const result = {};
|
|
417
|
+
for (const key of sortedKeys) {
|
|
418
|
+
const value = obj2[key];
|
|
419
|
+
let newValue;
|
|
420
|
+
if (options.deep && isPlainObject(value)) {
|
|
421
|
+
newValue = sortKeys(value);
|
|
422
|
+
} else {
|
|
423
|
+
newValue = value;
|
|
424
|
+
}
|
|
425
|
+
Object.defineProperty(result, key, {
|
|
426
|
+
...Object.getOwnPropertyDescriptor(obj2, key),
|
|
427
|
+
value: newValue
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
return result;
|
|
431
|
+
}
|
|
432
|
+
return sortKeys(obj);
|
|
433
|
+
}
|
|
355
434
|
export {
|
|
356
435
|
NOOP,
|
|
436
|
+
at,
|
|
357
437
|
cAF,
|
|
358
438
|
camelCase,
|
|
359
439
|
capitalize,
|
|
@@ -364,6 +444,7 @@ export {
|
|
|
364
444
|
ensurePrefix,
|
|
365
445
|
ensureSuffix,
|
|
366
446
|
flatCase,
|
|
447
|
+
flattenArrayable,
|
|
367
448
|
getObjectType,
|
|
368
449
|
hasOwn,
|
|
369
450
|
hours,
|
|
@@ -371,18 +452,29 @@ export {
|
|
|
371
452
|
isArrayEqual,
|
|
372
453
|
isBoolean,
|
|
373
454
|
isBrowser,
|
|
455
|
+
isEmptyString,
|
|
456
|
+
isEmptyStringOrWhitespace,
|
|
374
457
|
isFunction,
|
|
375
458
|
isInteger,
|
|
376
459
|
isNativePromise,
|
|
460
|
+
isNil,
|
|
461
|
+
isNonEmptyString,
|
|
377
462
|
isNull,
|
|
378
463
|
isNumber,
|
|
464
|
+
isNumbericString,
|
|
465
|
+
isObject,
|
|
379
466
|
isPromise,
|
|
467
|
+
isRegExp,
|
|
468
|
+
isSet,
|
|
380
469
|
isString,
|
|
381
470
|
isUndefined,
|
|
382
471
|
isUppercase,
|
|
472
|
+
isWhitespaceString,
|
|
383
473
|
join,
|
|
384
474
|
kebabCase,
|
|
475
|
+
last,
|
|
385
476
|
lowerFirst,
|
|
477
|
+
mergeArrayable,
|
|
386
478
|
minutes,
|
|
387
479
|
noop,
|
|
388
480
|
omit,
|
|
@@ -393,6 +485,7 @@ export {
|
|
|
393
485
|
seconds,
|
|
394
486
|
slash,
|
|
395
487
|
snakeCase,
|
|
488
|
+
sortObject,
|
|
396
489
|
splitByCase,
|
|
397
490
|
throttle,
|
|
398
491
|
titleCase,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ntnyq/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.1",
|
|
5
5
|
"description": "Common used utils.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"utils"
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
"email": "ntnyq13@gmail.com"
|
|
13
13
|
},
|
|
14
14
|
"homepage": "https://github.com/ntnyq/utils#readme",
|
|
15
|
+
"repository": "ntnyq/utils",
|
|
15
16
|
"bugs": {
|
|
16
17
|
"url": "https://github.com/ntnyq/utils/issues"
|
|
17
18
|
},
|
|
18
|
-
"repository": "ntnyq/utils",
|
|
19
19
|
"exports": {
|
|
20
20
|
"./package.json": "./package.json",
|
|
21
21
|
".": {
|
|
@@ -40,19 +40,18 @@
|
|
|
40
40
|
"scule": "^1.3.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@ntnyq/eslint-config": "^3.
|
|
43
|
+
"@ntnyq/eslint-config": "^3.2.2",
|
|
44
44
|
"@ntnyq/prettier-config": "^1.21.3",
|
|
45
|
-
"@vitest/coverage-v8": "^2.1.
|
|
46
|
-
"bumpp": "^9.
|
|
47
|
-
"eslint": "^9.
|
|
48
|
-
"husky": "^9.1.
|
|
45
|
+
"@vitest/coverage-v8": "^2.1.5",
|
|
46
|
+
"bumpp": "^9.8.1",
|
|
47
|
+
"eslint": "^9.15.0",
|
|
48
|
+
"husky": "^9.1.7",
|
|
49
49
|
"nano-staged": "^0.8.0",
|
|
50
|
-
"npm-run-all2": "^
|
|
51
|
-
"pnpm": "^9.12.1",
|
|
50
|
+
"npm-run-all2": "^7.0.1",
|
|
52
51
|
"prettier": "^3.3.3",
|
|
53
|
-
"tsup": "^8.3.
|
|
52
|
+
"tsup": "^8.3.5",
|
|
54
53
|
"typescript": "^5.6.3",
|
|
55
|
-
"vitest": "^2.1.
|
|
54
|
+
"vitest": "^2.1.5"
|
|
56
55
|
},
|
|
57
56
|
"engines": {
|
|
58
57
|
"node": ">=18.18.0"
|