@ntnyq/utils 0.11.0 → 0.11.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.d.ts +563 -509
- package/dist/index.js +44 -76
- package/package.json +27 -26
package/dist/index.js
CHANGED
|
@@ -7,7 +7,6 @@ function noop() {}
|
|
|
7
7
|
* Alias of {@link noop}.
|
|
8
8
|
*/
|
|
9
9
|
const NOOP = noop;
|
|
10
|
-
|
|
11
10
|
//#endregion
|
|
12
11
|
//#region src/fn/once.ts
|
|
13
12
|
/**
|
|
@@ -35,7 +34,6 @@ function once(func) {
|
|
|
35
34
|
return true;
|
|
36
35
|
};
|
|
37
36
|
}
|
|
38
|
-
|
|
39
37
|
//#endregion
|
|
40
38
|
//#region src/env/isBrowser.ts
|
|
41
39
|
/**
|
|
@@ -46,7 +44,6 @@ function once(func) {
|
|
|
46
44
|
function isBrowser() {
|
|
47
45
|
return typeof document !== "undefined" && typeof window !== "undefined" && typeof navigator !== "undefined" && window === self;
|
|
48
46
|
}
|
|
49
|
-
|
|
50
47
|
//#endregion
|
|
51
48
|
//#region src/is/dom.ts
|
|
52
49
|
/**
|
|
@@ -61,7 +58,6 @@ function isHTMLElement(value) {
|
|
|
61
58
|
if (!isBrowser()) return false;
|
|
62
59
|
return typeof value === "object" && value !== null && "nodeType" in value && value.nodeType === Node.ELEMENT_NODE && value instanceof HTMLElement;
|
|
63
60
|
}
|
|
64
|
-
|
|
65
61
|
//#endregion
|
|
66
62
|
//#region src/is/core.ts
|
|
67
63
|
function getObjectType(value) {
|
|
@@ -128,24 +124,24 @@ function isEmptyArray(value) {
|
|
|
128
124
|
function isNonEmptyArray(value) {
|
|
129
125
|
return isArray(value) && value.length > 0;
|
|
130
126
|
}
|
|
131
|
-
function isObject(value) {
|
|
132
|
-
return (typeof value === "object" || isFunction(value)) && !isNull(value);
|
|
133
|
-
}
|
|
134
|
-
function isEmptyObject(value) {
|
|
135
|
-
return isObject(value) && !isMap(value) && !isSet(value) && Object.keys(value).length === 0;
|
|
136
|
-
}
|
|
137
127
|
function isMap(value) {
|
|
138
128
|
return getObjectType(value) === "Map";
|
|
139
129
|
}
|
|
140
|
-
function isEmptyMap(value) {
|
|
141
|
-
return isMap(value) && value.size === 0;
|
|
142
|
-
}
|
|
143
130
|
function isSet(value) {
|
|
144
131
|
return getObjectType(value) === "Set";
|
|
145
132
|
}
|
|
146
133
|
function isEmptySet(value) {
|
|
147
134
|
return isSet(value) && value.size === 0;
|
|
148
135
|
}
|
|
136
|
+
function isObject(value) {
|
|
137
|
+
return (typeof value === "object" || isFunction(value)) && !isNull(value);
|
|
138
|
+
}
|
|
139
|
+
function isEmptyObject(value) {
|
|
140
|
+
return isObject(value) && !isMap(value) && !isSet(value) && Object.keys(value).length === 0;
|
|
141
|
+
}
|
|
142
|
+
function isEmptyMap(value) {
|
|
143
|
+
return isMap(value) && value.size === 0;
|
|
144
|
+
}
|
|
149
145
|
function isRegExp(value) {
|
|
150
146
|
return getObjectType(value) === "RegExp";
|
|
151
147
|
}
|
|
@@ -185,7 +181,6 @@ function isUrlString(value) {
|
|
|
185
181
|
return false;
|
|
186
182
|
}
|
|
187
183
|
}
|
|
188
|
-
|
|
189
184
|
//#endregion
|
|
190
185
|
//#region src/is/isDeepEqual.ts
|
|
191
186
|
/**
|
|
@@ -204,7 +199,6 @@ function isDeepEqual(value1, value2) {
|
|
|
204
199
|
}
|
|
205
200
|
return Object.is(value1, value2);
|
|
206
201
|
}
|
|
207
|
-
|
|
208
202
|
//#endregion
|
|
209
203
|
//#region src/dom/scrollIntoView.ts
|
|
210
204
|
/**
|
|
@@ -224,7 +218,6 @@ function scrollElementIntoView(element, options = {}) {
|
|
|
224
218
|
const elementRect = element.getBoundingClientRect();
|
|
225
219
|
if (parent.scrollWidth > parent.scrollHeight ? elementRect.left < parentRect.left || elementRect.right > parentRect.right : elementRect.top < parentRect.top || elementRect.bottom > parentRect.bottom) parent.scrollIntoView(scrollIntoViewOptions);
|
|
226
220
|
}
|
|
227
|
-
|
|
228
221
|
//#endregion
|
|
229
222
|
//#region src/dom/openExternalURL.ts
|
|
230
223
|
/**
|
|
@@ -237,7 +230,6 @@ function openExternalURL(url, options = {}) {
|
|
|
237
230
|
const { target = "_blank" } = options;
|
|
238
231
|
return window.open(url, target);
|
|
239
232
|
}
|
|
240
|
-
|
|
241
233
|
//#endregion
|
|
242
234
|
//#region src/dom/isVisibleInViewport.ts
|
|
243
235
|
/**
|
|
@@ -251,7 +243,6 @@ function isElementVisibleInViewport(element, targetWindow = window) {
|
|
|
251
243
|
const { innerWidth, innerHeight } = targetWindow;
|
|
252
244
|
return (top >= 0 && top <= innerHeight || bottom >= 0 && bottom <= innerHeight) && (left >= 0 && left <= innerWidth || right >= 0 && right <= innerWidth);
|
|
253
245
|
}
|
|
254
|
-
|
|
255
246
|
//#endregion
|
|
256
247
|
//#region src/file/extension.ts
|
|
257
248
|
/**
|
|
@@ -272,7 +263,6 @@ function getFileExtension(filePath) {
|
|
|
272
263
|
if (!filePath) return;
|
|
273
264
|
return filePath.match(/\.([^.]+)$/)?.[1];
|
|
274
265
|
}
|
|
275
|
-
|
|
276
266
|
//#endregion
|
|
277
267
|
//#region src/html/escape.ts
|
|
278
268
|
const htmlEscapeMap = {
|
|
@@ -308,7 +298,6 @@ const htmlUnescapeRegexp = /&(amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g;
|
|
|
308
298
|
function unescapeHTML(str) {
|
|
309
299
|
return str.replace(htmlUnescapeRegexp, (char) => htmlUnescapeMap[char]);
|
|
310
300
|
}
|
|
311
|
-
|
|
312
301
|
//#endregion
|
|
313
302
|
//#region src/misc/raf.ts
|
|
314
303
|
/**
|
|
@@ -341,7 +330,6 @@ function cAF(id) {
|
|
|
341
330
|
const root = getRoot();
|
|
342
331
|
return root.cancelAnimationFrame.call(root, id);
|
|
343
332
|
}
|
|
344
|
-
|
|
345
333
|
//#endregion
|
|
346
334
|
//#region src/misc/clamp.ts
|
|
347
335
|
/**
|
|
@@ -354,7 +342,6 @@ function cAF(id) {
|
|
|
354
342
|
function clamp(value, min = Number.NEGATIVE_INFINITY, max = Number.POSITIVE_INFINITY) {
|
|
355
343
|
return Math.min(Math.max(value, min), max);
|
|
356
344
|
}
|
|
357
|
-
|
|
358
345
|
//#endregion
|
|
359
346
|
//#region src/misc/waitFor.ts
|
|
360
347
|
/**
|
|
@@ -373,7 +360,6 @@ function clamp(value, min = Number.NEGATIVE_INFINITY, max = Number.POSITIVE_INFI
|
|
|
373
360
|
async function waitFor(ms) {
|
|
374
361
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
375
362
|
}
|
|
376
|
-
|
|
377
363
|
//#endregion
|
|
378
364
|
//#region src/misc/throttle.ts
|
|
379
365
|
/**
|
|
@@ -391,7 +377,7 @@ function throttle(delay, callback, options = {}) {
|
|
|
391
377
|
*/
|
|
392
378
|
let lastExec = 0;
|
|
393
379
|
let cancelled = false;
|
|
394
|
-
let timeoutId;
|
|
380
|
+
let timeoutId = void 0;
|
|
395
381
|
function clearExistingTimeout() {
|
|
396
382
|
if (timeoutId) clearTimeout(timeoutId);
|
|
397
383
|
}
|
|
@@ -425,7 +411,6 @@ function debounce(delay, callback, options = {}) {
|
|
|
425
411
|
isDebounce: true
|
|
426
412
|
});
|
|
427
413
|
}
|
|
428
|
-
|
|
429
414
|
//#endregion
|
|
430
415
|
//#region src/misc/warnOnce.ts
|
|
431
416
|
/**
|
|
@@ -442,7 +427,6 @@ function warnOnce(message) {
|
|
|
442
427
|
warned.add(message);
|
|
443
428
|
console.warn(message);
|
|
444
429
|
}
|
|
445
|
-
|
|
446
430
|
//#endregion
|
|
447
431
|
//#region src/misc/convertTime.ts
|
|
448
432
|
/**
|
|
@@ -506,7 +490,6 @@ function convertFromMilliseconds(milliseconds, toUnit = "SECOND") {
|
|
|
506
490
|
function convertTimeUnit(value, fromUnit, toUnit) {
|
|
507
491
|
return convertFromMilliseconds(convertToMilliseconds(value, fromUnit), toUnit);
|
|
508
492
|
}
|
|
509
|
-
|
|
510
493
|
//#endregion
|
|
511
494
|
//#region src/misc/convertStorage.ts
|
|
512
495
|
/**
|
|
@@ -569,7 +552,6 @@ function convertFromBytes(bytes, toUnit = "MB") {
|
|
|
569
552
|
function convertStorageUnit(value, fromUnit, toUnit) {
|
|
570
553
|
return convertFromBytes(convertToBytes(value, fromUnit), toUnit);
|
|
571
554
|
}
|
|
572
|
-
|
|
573
555
|
//#endregion
|
|
574
556
|
//#region src/array/at.ts
|
|
575
557
|
/**
|
|
@@ -592,7 +574,6 @@ function at(array, index) {
|
|
|
592
574
|
function last(array) {
|
|
593
575
|
return at(array, -1);
|
|
594
576
|
}
|
|
595
|
-
|
|
596
577
|
//#endregion
|
|
597
578
|
//#region src/array/chunk.ts
|
|
598
579
|
/**
|
|
@@ -606,7 +587,6 @@ function chunk(array, size) {
|
|
|
606
587
|
for (let i = 0; i < array.length; i += size) result.push(array.slice(i, i + size));
|
|
607
588
|
return result;
|
|
608
589
|
}
|
|
609
|
-
|
|
610
590
|
//#endregion
|
|
611
591
|
//#region src/array/remove.ts
|
|
612
592
|
/**
|
|
@@ -624,7 +604,6 @@ function remove(array, value) {
|
|
|
624
604
|
}
|
|
625
605
|
return false;
|
|
626
606
|
}
|
|
627
|
-
|
|
628
607
|
//#endregion
|
|
629
608
|
//#region src/array/unique.ts
|
|
630
609
|
/**
|
|
@@ -647,7 +626,6 @@ function uniqueBy(array, equalFn) {
|
|
|
647
626
|
return acc;
|
|
648
627
|
}, []);
|
|
649
628
|
}
|
|
650
|
-
|
|
651
629
|
//#endregion
|
|
652
630
|
//#region src/number/random.ts
|
|
653
631
|
/**
|
|
@@ -665,7 +643,6 @@ function randomNumber(min, max = 0, options = {}) {
|
|
|
665
643
|
if (min > max) [min, max] = [max, min];
|
|
666
644
|
return Math.trunc(Math.random() * (max - min + (options.includeMax ? 1 : 0)) + min);
|
|
667
645
|
}
|
|
668
|
-
|
|
669
646
|
//#endregion
|
|
670
647
|
//#region src/number/toInteger.ts
|
|
671
648
|
/**
|
|
@@ -714,7 +691,6 @@ function toInteger(value, options = {}) {
|
|
|
714
691
|
}
|
|
715
692
|
return result;
|
|
716
693
|
}
|
|
717
|
-
|
|
718
694
|
//#endregion
|
|
719
695
|
//#region src/array/shuffle.ts
|
|
720
696
|
/**
|
|
@@ -730,7 +706,6 @@ function shuffle(array) {
|
|
|
730
706
|
}
|
|
731
707
|
return array;
|
|
732
708
|
}
|
|
733
|
-
|
|
734
709
|
//#endregion
|
|
735
710
|
//#region src/array/toArray.ts
|
|
736
711
|
/**
|
|
@@ -742,7 +717,6 @@ function toArray(array) {
|
|
|
742
717
|
array = array ?? [];
|
|
743
718
|
return Array.isArray(array) ? array : [array];
|
|
744
719
|
}
|
|
745
|
-
|
|
746
720
|
//#endregion
|
|
747
721
|
//#region src/array/arrayable.ts
|
|
748
722
|
/**
|
|
@@ -761,7 +735,6 @@ function flattenArrayable(array) {
|
|
|
761
735
|
function mergeArrayable(...args) {
|
|
762
736
|
return args.flatMap((i) => toArray(i));
|
|
763
737
|
}
|
|
764
|
-
|
|
765
738
|
//#endregion
|
|
766
739
|
//#region src/array/intersect.ts
|
|
767
740
|
/**
|
|
@@ -772,7 +745,6 @@ function mergeArrayable(...args) {
|
|
|
772
745
|
function intersect(a, b) {
|
|
773
746
|
return a.filter((item) => b.includes(item));
|
|
774
747
|
}
|
|
775
|
-
|
|
776
748
|
//#endregion
|
|
777
749
|
//#region src/array/isArrayEqual.ts
|
|
778
750
|
/**
|
|
@@ -785,14 +757,12 @@ function isArrayEqual(array1, array2) {
|
|
|
785
757
|
if (array1.length !== array2.length) return false;
|
|
786
758
|
return array1.every((item, idx) => item === array2[idx]);
|
|
787
759
|
}
|
|
788
|
-
|
|
789
760
|
//#endregion
|
|
790
761
|
//#region src/string/pad.ts
|
|
791
762
|
function createPadString(options) {
|
|
792
763
|
const { length, char } = options;
|
|
793
764
|
return (value) => (char.repeat(length) + value).slice(-length);
|
|
794
765
|
}
|
|
795
|
-
|
|
796
766
|
//#endregion
|
|
797
767
|
//#region src/string/join.ts
|
|
798
768
|
/**
|
|
@@ -804,27 +774,24 @@ function createPadString(options) {
|
|
|
804
774
|
function join(array, options = {}) {
|
|
805
775
|
const { separator = "" } = options;
|
|
806
776
|
if (!Array.isArray(array) || !array.length) return "";
|
|
807
|
-
return array.filter((
|
|
777
|
+
return array.filter((i) => Boolean(i) || i === 0).join(separator);
|
|
808
778
|
}
|
|
809
|
-
|
|
810
779
|
//#endregion
|
|
811
780
|
//#region src/string/slash.ts
|
|
812
781
|
/**
|
|
813
782
|
* Replace backslash to slash
|
|
814
783
|
*/
|
|
815
784
|
function slash(input) {
|
|
816
|
-
return input.
|
|
785
|
+
return input.replaceAll("\\", "/");
|
|
817
786
|
}
|
|
818
|
-
|
|
819
787
|
//#endregion
|
|
820
788
|
//#region src/string/escape.ts
|
|
821
789
|
/**
|
|
822
790
|
* @copyright {@link https://github.com/sindresorhus/escape-string-regexp}
|
|
823
791
|
*/
|
|
824
792
|
function escapeStringRegexp(value) {
|
|
825
|
-
return value.
|
|
793
|
+
return value.replaceAll(/[|\\{}()[\]^$+*?.]/g, "\\$&").replaceAll("-", "\\x2d");
|
|
826
794
|
}
|
|
827
|
-
|
|
828
795
|
//#endregion
|
|
829
796
|
//#region src/string/random.ts
|
|
830
797
|
/**
|
|
@@ -842,7 +809,6 @@ function randomString(length = 16, chars = "0123456789abcdefghijklmnopqrstuvwxyz
|
|
|
842
809
|
}
|
|
843
810
|
return result.join("");
|
|
844
811
|
}
|
|
845
|
-
|
|
846
812
|
//#endregion
|
|
847
813
|
//#region src/string/slugify.ts
|
|
848
814
|
const rControl = /[\u0000-\u001F]/g;
|
|
@@ -852,9 +818,8 @@ const rCombining = /[\u0300-\u036F]/g;
|
|
|
852
818
|
* Default slugify function
|
|
853
819
|
*/
|
|
854
820
|
function slugify(str) {
|
|
855
|
-
return str.normalize("NFKD").replace(rCombining, "").replace(rControl, "").replace(rSpecial, "-").
|
|
821
|
+
return str.normalize("NFKD").replace(rCombining, "").replace(rControl, "").replace(rSpecial, "-").replaceAll(/-{2,}/g, "-").replaceAll(/^-+|-+$/g, "").replace(/^(\d)/, "_$1").toLowerCase();
|
|
856
822
|
}
|
|
857
|
-
|
|
858
823
|
//#endregion
|
|
859
824
|
//#region src/string/unindent.ts
|
|
860
825
|
const _RE_FULL_WS = /^\s*$/;
|
|
@@ -887,7 +852,6 @@ function unindent(input) {
|
|
|
887
852
|
while (emptylinesTail < lines.length && whitespaceLines[lines.length - emptylinesTail - 1]) emptylinesTail++;
|
|
888
853
|
return lines.slice(emptylinesHead, lines.length - emptylinesTail).map((line) => line.slice(commonIndent)).join("\n");
|
|
889
854
|
}
|
|
890
|
-
|
|
891
855
|
//#endregion
|
|
892
856
|
//#region src/string/getLength.ts
|
|
893
857
|
let segmenter;
|
|
@@ -904,19 +868,16 @@ function getStringLength(value) {
|
|
|
904
868
|
segmenter ??= new Intl.Segmenter();
|
|
905
869
|
return [...segmenter.segment(value)].length;
|
|
906
870
|
}
|
|
907
|
-
|
|
908
871
|
//#endregion
|
|
909
872
|
//#region src/string/ensurePrefix.ts
|
|
910
873
|
function ensurePrefix(input, prefix) {
|
|
911
874
|
return input.startsWith(prefix) ? input : `${prefix}${input}`;
|
|
912
875
|
}
|
|
913
|
-
|
|
914
876
|
//#endregion
|
|
915
877
|
//#region src/string/ensureSuffix.ts
|
|
916
878
|
function ensureSuffix(input, suffix) {
|
|
917
879
|
return input.endsWith(suffix) ? input : `${input}${suffix}`;
|
|
918
880
|
}
|
|
919
|
-
|
|
920
881
|
//#endregion
|
|
921
882
|
//#region src/string/getSimilarity.ts
|
|
922
883
|
function getStringSimilarity(str1, str2, options = {}) {
|
|
@@ -942,7 +903,6 @@ function getStringSimilarity(str1, str2, options = {}) {
|
|
|
942
903
|
}
|
|
943
904
|
return match * 2 / (str1.length + str2.length - (sliceLength - 1) * 2);
|
|
944
905
|
}
|
|
945
|
-
|
|
946
906
|
//#endregion
|
|
947
907
|
//#region src/color/color.ts
|
|
948
908
|
const RE_VALID_HEX_COLOR = /^#(?:[0-9a-f]{6}|[0-9a-f]{3})$/i;
|
|
@@ -952,7 +912,7 @@ function validateHexColor(hex) {
|
|
|
952
912
|
return RE_VALID_HEX_COLOR.test(hex);
|
|
953
913
|
}
|
|
954
914
|
function normalizeHexString(hex) {
|
|
955
|
-
return hex.length === 6 ? hex : hex.
|
|
915
|
+
return hex.length === 6 ? hex : hex.replaceAll(/./g, "$&$&");
|
|
956
916
|
}
|
|
957
917
|
var Color = class Color {
|
|
958
918
|
red = 0;
|
|
@@ -1028,7 +988,6 @@ var Color = class Color {
|
|
|
1028
988
|
return new Color(Math.max(this.red - amount, 0), Math.max(this.green - amount, 0), Math.max(this.blue - amount, 0), this.alpha);
|
|
1029
989
|
}
|
|
1030
990
|
};
|
|
1031
|
-
|
|
1032
991
|
//#endregion
|
|
1033
992
|
//#region src/color/random.ts
|
|
1034
993
|
/**
|
|
@@ -1056,7 +1015,6 @@ function randomRGBAColor() {
|
|
|
1056
1015
|
function randomHexColor() {
|
|
1057
1016
|
return `#${Math.random().toString(16).slice(2, 8)}`;
|
|
1058
1017
|
}
|
|
1059
|
-
|
|
1060
1018
|
//#endregion
|
|
1061
1019
|
//#region src/proxy/enhance.ts
|
|
1062
1020
|
/**
|
|
@@ -1074,7 +1032,28 @@ function enhance(module, extra) {
|
|
|
1074
1032
|
}
|
|
1075
1033
|
});
|
|
1076
1034
|
}
|
|
1077
|
-
|
|
1035
|
+
//#endregion
|
|
1036
|
+
//#region src/tree/flatTree.ts
|
|
1037
|
+
function flatTree(roots, options = {}) {
|
|
1038
|
+
const { childrenKey = "children", includeSelf = true, map } = options;
|
|
1039
|
+
const out = [];
|
|
1040
|
+
function walk(nodes, parent, depth, path) {
|
|
1041
|
+
nodes.forEach((node, index) => {
|
|
1042
|
+
const nextPath = [...path, node];
|
|
1043
|
+
if (includeSelf) out.push(map ? map({
|
|
1044
|
+
node,
|
|
1045
|
+
parent,
|
|
1046
|
+
depth,
|
|
1047
|
+
index,
|
|
1048
|
+
path: nextPath
|
|
1049
|
+
}) : node);
|
|
1050
|
+
const children = node[childrenKey];
|
|
1051
|
+
if (Array.isArray(children) && children.length > 0) walk(children, node, depth + 1, nextPath);
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
1054
|
+
walk(roots, null, 0, []);
|
|
1055
|
+
return out;
|
|
1056
|
+
}
|
|
1078
1057
|
//#endregion
|
|
1079
1058
|
//#region src/module/interopDefault.ts
|
|
1080
1059
|
/**
|
|
@@ -1095,7 +1074,6 @@ async function interopDefault(mod) {
|
|
|
1095
1074
|
const resolved = await mod;
|
|
1096
1075
|
return resolved.default || resolved;
|
|
1097
1076
|
}
|
|
1098
|
-
|
|
1099
1077
|
//#endregion
|
|
1100
1078
|
//#region src/module/resolveSubOptions.ts
|
|
1101
1079
|
/**
|
|
@@ -1128,14 +1106,12 @@ async function interopDefault(mod) {
|
|
|
1128
1106
|
function resolveSubOptions(options, key) {
|
|
1129
1107
|
return typeof options[key] === "boolean" ? {} : options[key] || {};
|
|
1130
1108
|
}
|
|
1131
|
-
|
|
1132
1109
|
//#endregion
|
|
1133
1110
|
//#region src/object/omit.ts
|
|
1134
1111
|
function omit(object, ...keys) {
|
|
1135
1112
|
keys.forEach((key) => delete object[key]);
|
|
1136
1113
|
return object;
|
|
1137
1114
|
}
|
|
1138
|
-
|
|
1139
1115
|
//#endregion
|
|
1140
1116
|
//#region src/object/hasOwn.ts
|
|
1141
1117
|
/**
|
|
@@ -1148,7 +1124,6 @@ function hasOwn(object, key) {
|
|
|
1148
1124
|
if (object === null) return false;
|
|
1149
1125
|
return Object.prototype.hasOwnProperty.call(object, key);
|
|
1150
1126
|
}
|
|
1151
|
-
|
|
1152
1127
|
//#endregion
|
|
1153
1128
|
//#region src/object/pick.ts
|
|
1154
1129
|
function pick(object, keys) {
|
|
@@ -1157,7 +1132,6 @@ function pick(object, keys) {
|
|
|
1157
1132
|
return result;
|
|
1158
1133
|
}, {});
|
|
1159
1134
|
}
|
|
1160
|
-
|
|
1161
1135
|
//#endregion
|
|
1162
1136
|
//#region src/object/clean.ts
|
|
1163
1137
|
/**
|
|
@@ -1181,7 +1155,6 @@ function cleanObject(obj, options = {}) {
|
|
|
1181
1155
|
});
|
|
1182
1156
|
return obj;
|
|
1183
1157
|
}
|
|
1184
|
-
|
|
1185
1158
|
//#endregion
|
|
1186
1159
|
//#region src/object/isKeyOf.ts
|
|
1187
1160
|
/**
|
|
@@ -1195,7 +1168,6 @@ function cleanObject(obj, options = {}) {
|
|
|
1195
1168
|
function isKeyOf(obj, k) {
|
|
1196
1169
|
return k in obj;
|
|
1197
1170
|
}
|
|
1198
|
-
|
|
1199
1171
|
//#endregion
|
|
1200
1172
|
//#region src/object/isPlainObject.ts
|
|
1201
1173
|
/**
|
|
@@ -1209,32 +1181,30 @@ function isPlainObject(value) {
|
|
|
1209
1181
|
const prototype = Object.getPrototypeOf(value);
|
|
1210
1182
|
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
1211
1183
|
}
|
|
1212
|
-
|
|
1213
1184
|
//#endregion
|
|
1214
1185
|
//#region src/object/sortObject.ts
|
|
1215
1186
|
/**
|
|
1216
1187
|
* Sort object properties
|
|
1217
1188
|
*/
|
|
1218
|
-
function sortObject(
|
|
1189
|
+
function sortObject(object, options = {}) {
|
|
1219
1190
|
const { compareFn = (a, b) => a.localeCompare(b) } = options;
|
|
1220
|
-
function sortKeys(obj
|
|
1221
|
-
const sortedKeys = Object.keys(obj
|
|
1191
|
+
function sortKeys(obj) {
|
|
1192
|
+
const sortedKeys = Object.keys(obj).sort(compareFn);
|
|
1222
1193
|
const result = {};
|
|
1223
1194
|
for (const key of sortedKeys) {
|
|
1224
|
-
const value = obj
|
|
1195
|
+
const value = obj[key];
|
|
1225
1196
|
let newValue;
|
|
1226
1197
|
if (options.deep && isPlainObject(value)) newValue = sortKeys(value);
|
|
1227
1198
|
else newValue = value;
|
|
1228
1199
|
Object.defineProperty(result, key, {
|
|
1229
|
-
...Object.getOwnPropertyDescriptor(obj
|
|
1200
|
+
...Object.getOwnPropertyDescriptor(obj, key),
|
|
1230
1201
|
value: newValue
|
|
1231
1202
|
});
|
|
1232
1203
|
}
|
|
1233
1204
|
return result;
|
|
1234
1205
|
}
|
|
1235
|
-
return sortKeys(
|
|
1206
|
+
return sortKeys(object);
|
|
1236
1207
|
}
|
|
1237
|
-
|
|
1238
1208
|
//#endregion
|
|
1239
1209
|
//#region src/constants/char.ts
|
|
1240
1210
|
/**
|
|
@@ -1248,7 +1218,6 @@ const SPECIAL_CHAR = {
|
|
|
1248
1218
|
newline: "\n",
|
|
1249
1219
|
whitespace: " "
|
|
1250
1220
|
};
|
|
1251
|
-
|
|
1252
1221
|
//#endregion
|
|
1253
1222
|
//#region src/constants/regexp.ts
|
|
1254
1223
|
/**
|
|
@@ -1265,6 +1234,5 @@ const RE_LINE_COMMENT = /\/\/.*/;
|
|
|
1265
1234
|
* JavaScript block comment
|
|
1266
1235
|
*/
|
|
1267
1236
|
const RE_BLOCK_COMMENT = /\/\*[\s\S]*?\*\//g;
|
|
1268
|
-
|
|
1269
1237
|
//#endregion
|
|
1270
|
-
export { Color, NOOP, RE_BLOCK_COMMENT, RE_COMMENTS, RE_LINE_COMMENT, SPECIAL_CHAR, STORAGE_UNITS, TIME_UNITS, at, cAF, chunk, clamp, cleanObject, convertFromBytes, convertFromMilliseconds, convertStorageUnit, convertTimeUnit, convertToBytes, convertToMilliseconds, createPadString, debounce, enhance, ensurePrefix, ensureSuffix, escapeHTML, escapeStringRegexp, flattenArrayable, getFileExtension, getObjectType, getRoot, getStringLength, getStringSimilarity, hasOwn, interopDefault, intersect, isArray, isArrayEqual, isBigInt, isBlob, isBoolean, isBrowser, isDeepEqual, isElementVisibleInViewport, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isEmptyStringOrWhitespace, isError, isFile, isFormData, isFunction, isHTMLElement, isInteger, isIterable, isKeyOf, isMap, isNaN, isNativePromise, isNil, isNonEmptyArray, isNonEmptyString, isNull, isNullOrUndefined, isNumber, isNumbericString, isObject, isPlainObject, isPromise, isRegExp, isSet, isString, isTruthy, isUndefined, isUrlString, isWhitespaceString, isZero, join, last, mergeArrayable, noop, omit, once, openExternalURL, pick, rAF, randomHexColor, randomNumber, randomRGBAColor, randomRGBColor, randomString, remove, removeFileExtension, resolveSubOptions, scrollElementIntoView, shuffle, slash, slugify, sortObject, throttle, toArray, toInteger, unescapeHTML, unindent, unique, uniqueBy, waitFor, warnOnce };
|
|
1238
|
+
export { Color, NOOP, RE_BLOCK_COMMENT, RE_COMMENTS, RE_LINE_COMMENT, SPECIAL_CHAR, STORAGE_UNITS, TIME_UNITS, at, cAF, chunk, clamp, cleanObject, convertFromBytes, convertFromMilliseconds, convertStorageUnit, convertTimeUnit, convertToBytes, convertToMilliseconds, createPadString, debounce, enhance, ensurePrefix, ensureSuffix, escapeHTML, escapeStringRegexp, flatTree, flattenArrayable, getFileExtension, getObjectType, getRoot, getStringLength, getStringSimilarity, hasOwn, interopDefault, intersect, isArray, isArrayEqual, isBigInt, isBlob, isBoolean, isBrowser, isDeepEqual, isElementVisibleInViewport, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isEmptyStringOrWhitespace, isError, isFile, isFormData, isFunction, isHTMLElement, isInteger, isIterable, isKeyOf, isMap, isNaN, isNativePromise, isNil, isNonEmptyArray, isNonEmptyString, isNull, isNullOrUndefined, isNumber, isNumbericString, isObject, isPlainObject, isPromise, isRegExp, isSet, isString, isTruthy, isUndefined, isUrlString, isWhitespaceString, isZero, join, last, mergeArrayable, noop, omit, once, openExternalURL, pick, rAF, randomHexColor, randomNumber, randomRGBAColor, randomRGBColor, randomString, remove, removeFileExtension, resolveSubOptions, scrollElementIntoView, shuffle, slash, slugify, sortObject, throttle, toArray, toInteger, unescapeHTML, unindent, unique, uniqueBy, waitFor, warnOnce };
|
package/package.json
CHANGED
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ntnyq/utils",
|
|
3
|
-
"
|
|
4
|
-
"version": "0.11.0",
|
|
3
|
+
"version": "0.11.1",
|
|
5
4
|
"description": "Common used utils.",
|
|
6
5
|
"keywords": [
|
|
7
6
|
"utils"
|
|
8
7
|
],
|
|
8
|
+
"homepage": "https://github.com/ntnyq/utils#readme",
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/ntnyq/utils/issues"
|
|
11
|
+
},
|
|
9
12
|
"license": "MIT",
|
|
10
13
|
"author": {
|
|
11
14
|
"name": "ntnyq",
|
|
12
15
|
"email": "ntnyq13@gmail.com"
|
|
13
16
|
},
|
|
14
|
-
"homepage": "https://github.com/ntnyq/utils#readme",
|
|
15
17
|
"repository": "ntnyq/utils",
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"type": "module",
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
19
25
|
"exports": {
|
|
20
26
|
"./package.json": "./package.json",
|
|
21
27
|
".": {
|
|
@@ -23,40 +29,35 @@
|
|
|
23
29
|
"default": "./dist/index.js"
|
|
24
30
|
}
|
|
25
31
|
},
|
|
26
|
-
"main": "./dist/index.js",
|
|
27
|
-
"types": "./dist/index.d.ts",
|
|
28
|
-
"files": [
|
|
29
|
-
"dist"
|
|
30
|
-
],
|
|
31
|
-
"sideEffects": false,
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@ntnyq/eslint-config": "^5.9.0",
|
|
34
|
-
"@ntnyq/prettier-config": "^3.0.1",
|
|
35
33
|
"@ntnyq/tsconfig": "^3.1.0",
|
|
36
|
-
"
|
|
37
|
-
"
|
|
34
|
+
"@typescript/native-preview": "7.0.0-dev.20260317.1",
|
|
35
|
+
"bumpp": "^11.0.1",
|
|
38
36
|
"husky": "^9.1.7",
|
|
39
37
|
"nano-staged": "^0.9.0",
|
|
40
38
|
"npm-run-all2": "^8.0.4",
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"vitest": "^4.0
|
|
39
|
+
"oxfmt": "^0.41.0",
|
|
40
|
+
"oxlint": "^1.56.0",
|
|
41
|
+
"tsdown": "^0.21.4",
|
|
42
|
+
"vitest": "^4.1.0"
|
|
43
|
+
},
|
|
44
|
+
"nano-staged": {
|
|
45
|
+
"*.{js,ts,mjs,tsx}": "oxlint --fix",
|
|
46
|
+
"*": "oxfmt --no-error-on-unmatched-pattern"
|
|
45
47
|
},
|
|
46
48
|
"engines": {
|
|
47
49
|
"node": "^20.19.0 || ^22.13.0 || >=24"
|
|
48
50
|
},
|
|
49
|
-
"nano-staged": {
|
|
50
|
-
"*.{js,ts,mjs,cjs,md,yml,yaml,toml,json}": "eslint --fix"
|
|
51
|
-
},
|
|
52
51
|
"scripts": {
|
|
53
52
|
"build": "tsdown",
|
|
54
53
|
"dev": "tsdown --watch src",
|
|
55
|
-
"
|
|
54
|
+
"format": "oxfmt",
|
|
55
|
+
"format:check": "oxfmt --check",
|
|
56
|
+
"lint": "oxlint",
|
|
56
57
|
"release": "run-s release:check release:version",
|
|
57
|
-
"release:check": "run-s lint typecheck test",
|
|
58
|
+
"release:check": "run-s format:check lint typecheck test",
|
|
58
59
|
"release:version": "bumpp",
|
|
59
60
|
"test": "vitest",
|
|
60
|
-
"typecheck": "
|
|
61
|
+
"typecheck": "tsgo --noEmit"
|
|
61
62
|
}
|
|
62
63
|
}
|