@ntnyq/utils 0.5.0 → 0.5.2
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 +156 -116
- package/dist/index.d.cts +80 -17
- package/dist/index.d.ts +80 -17
- package/dist/index.js +253 -104
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -15,26 +15,26 @@ 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
|
|
21
22
|
var index_exports = {};
|
|
22
23
|
__export(index_exports, {
|
|
24
|
+
Color: () => Color,
|
|
23
25
|
NOOP: () => NOOP,
|
|
24
26
|
at: () => at,
|
|
25
27
|
cAF: () => cAF,
|
|
26
|
-
camelCase: () => camelCase,
|
|
27
|
-
capitalize: () => capitalize,
|
|
28
28
|
chunk: () => chunk,
|
|
29
29
|
clamp: () => clamp,
|
|
30
30
|
cleanObject: () => cleanObject,
|
|
31
31
|
createPadString: () => createPadString,
|
|
32
32
|
days: () => days,
|
|
33
33
|
debounce: () => debounce,
|
|
34
|
+
enhance: () => enhance,
|
|
34
35
|
ensurePrefix: () => ensurePrefix,
|
|
35
36
|
ensureSuffix: () => ensureSuffix,
|
|
36
37
|
escapeHtml: () => escapeHtml,
|
|
37
|
-
flatCase: () => flatCase,
|
|
38
38
|
flattenArrayable: () => flattenArrayable,
|
|
39
39
|
getObjectType: () => getObjectType,
|
|
40
40
|
hasOwn: () => hasOwn,
|
|
@@ -73,36 +73,31 @@ __export(index_exports, {
|
|
|
73
73
|
isSet: () => isSet,
|
|
74
74
|
isString: () => isString,
|
|
75
75
|
isUndefined: () => isUndefined,
|
|
76
|
-
isUppercase: () => isUppercase,
|
|
77
76
|
isWhitespaceString: () => isWhitespaceString,
|
|
78
77
|
isZero: () => isZero,
|
|
79
78
|
join: () => join,
|
|
80
|
-
kebabCase: () => kebabCase,
|
|
81
79
|
last: () => last,
|
|
82
|
-
lowerFirst: () => lowerFirst,
|
|
83
80
|
mergeArrayable: () => mergeArrayable,
|
|
84
81
|
minutes: () => minutes,
|
|
85
82
|
noop: () => noop,
|
|
86
83
|
omit: () => omit,
|
|
87
84
|
once: () => once,
|
|
88
|
-
pascalCase: () => pascalCase,
|
|
89
85
|
pick: () => pick,
|
|
90
86
|
rAF: () => rAF,
|
|
87
|
+
randomHexColor: () => randomHexColor,
|
|
88
|
+
randomNumber: () => randomNumber,
|
|
89
|
+
randomRGBAColor: () => randomRGBAColor,
|
|
90
|
+
randomRGBColor: () => randomRGBColor,
|
|
91
91
|
randomString: () => randomString,
|
|
92
92
|
resolveSubOptions: () => resolveSubOptions,
|
|
93
93
|
seconds: () => seconds,
|
|
94
94
|
slash: () => slash,
|
|
95
|
-
snakeCase: () => snakeCase,
|
|
96
95
|
sortObject: () => sortObject,
|
|
97
|
-
splitByCase: () => splitByCase,
|
|
98
96
|
throttle: () => throttle,
|
|
99
|
-
titleCase: () => titleCase,
|
|
100
97
|
toArray: () => toArray,
|
|
101
|
-
trainCase: () => trainCase,
|
|
102
98
|
unindent: () => unindent,
|
|
103
99
|
unique: () => unique,
|
|
104
100
|
uniqueBy: () => uniqueBy,
|
|
105
|
-
upperFirst: () => upperFirst,
|
|
106
101
|
waitFor: () => waitFor,
|
|
107
102
|
warnOnce: () => warnOnce,
|
|
108
103
|
weeks: () => weeks
|
|
@@ -116,19 +111,22 @@ function isDeepEqual(value1, value2) {
|
|
|
116
111
|
if (type1 !== type2) {
|
|
117
112
|
return false;
|
|
118
113
|
}
|
|
119
|
-
if (isArray(value1)) {
|
|
114
|
+
if (isArray(value1) && isArray(value2)) {
|
|
120
115
|
if (value1.length !== value2.length) {
|
|
121
116
|
return false;
|
|
122
117
|
}
|
|
123
118
|
return value1.every((item, index) => isDeepEqual(item, value2[index]));
|
|
124
119
|
}
|
|
125
|
-
if (isObject(value1)) {
|
|
120
|
+
if (isObject(value1) && isObject(value2)) {
|
|
126
121
|
const keys = Object.keys(value1);
|
|
127
122
|
if (keys.length !== Object.keys(value2).length) {
|
|
128
123
|
return false;
|
|
129
124
|
}
|
|
130
125
|
return keys.every(
|
|
131
|
-
(key) => isDeepEqual(
|
|
126
|
+
(key) => isDeepEqual(
|
|
127
|
+
value1[key],
|
|
128
|
+
value2[key]
|
|
129
|
+
)
|
|
132
130
|
);
|
|
133
131
|
}
|
|
134
132
|
return Object.is(value1, value2);
|
|
@@ -221,7 +219,10 @@ function isError(value) {
|
|
|
221
219
|
return getObjectType(value) === "Error";
|
|
222
220
|
}
|
|
223
221
|
function hasPromiseApi(value) {
|
|
224
|
-
return
|
|
222
|
+
return (
|
|
223
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
224
|
+
isFunction(value?.then) && isFunction(value?.catch)
|
|
225
|
+
);
|
|
225
226
|
}
|
|
226
227
|
function isNativePromise(value) {
|
|
227
228
|
return getObjectType(value) === "Promise";
|
|
@@ -301,7 +302,7 @@ function clamp(value, min = Number.NEGATIVE_INFINITY, max = Number.POSITIVE_INFI
|
|
|
301
302
|
}
|
|
302
303
|
|
|
303
304
|
// src/misc/waitFor.ts
|
|
304
|
-
function waitFor(ms) {
|
|
305
|
+
async function waitFor(ms) {
|
|
305
306
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
306
307
|
}
|
|
307
308
|
|
|
@@ -452,7 +453,7 @@ function slash(input) {
|
|
|
452
453
|
}
|
|
453
454
|
|
|
454
455
|
// src/number/random.ts
|
|
455
|
-
function randomNumber(min, max = 0) {
|
|
456
|
+
function randomNumber(min, max = 0, options = {}) {
|
|
456
457
|
if (max === 0) {
|
|
457
458
|
max = min;
|
|
458
459
|
min = 0;
|
|
@@ -461,7 +462,9 @@ function randomNumber(min, max = 0) {
|
|
|
461
462
|
;
|
|
462
463
|
[min, max] = [max, min];
|
|
463
464
|
}
|
|
464
|
-
return Math.trunc(
|
|
465
|
+
return Math.trunc(
|
|
466
|
+
Math.random() * (max - min + (options.includeMax ? 1 : 0)) + min
|
|
467
|
+
);
|
|
465
468
|
}
|
|
466
469
|
|
|
467
470
|
// src/string/random.ts
|
|
@@ -506,6 +509,119 @@ function ensureSuffix(input, suffix) {
|
|
|
506
509
|
return input.endsWith(suffix) ? input : `${input}${suffix}`;
|
|
507
510
|
}
|
|
508
511
|
|
|
512
|
+
// src/color/color.ts
|
|
513
|
+
var pad2 = createPadString({ length: 2, char: "0" });
|
|
514
|
+
var RE_VALID_HEX_COLOR = /^#(?:[0-9a-f]{6}|[0-9a-f]{3})$/i;
|
|
515
|
+
function validateHexColor(hex) {
|
|
516
|
+
if (hex.length !== 4 && hex.length !== 7) return false;
|
|
517
|
+
if (!hex.startsWith("#")) return false;
|
|
518
|
+
return RE_VALID_HEX_COLOR.test(hex);
|
|
519
|
+
}
|
|
520
|
+
function normalizeHexString(hex) {
|
|
521
|
+
return hex.length === 6 ? hex : hex.replace(/./g, "$&$&");
|
|
522
|
+
}
|
|
523
|
+
var Color = class _Color {
|
|
524
|
+
constructor(red = 0, green = 0, blue = 0, alpha = 1) {
|
|
525
|
+
this.red = red;
|
|
526
|
+
this.green = green;
|
|
527
|
+
this.blue = blue;
|
|
528
|
+
this.alpha = alpha;
|
|
529
|
+
}
|
|
530
|
+
static fromRGB(red, green, blue) {
|
|
531
|
+
return new _Color(red, green, blue);
|
|
532
|
+
}
|
|
533
|
+
static fromRGBA(red, green, blue, alpha) {
|
|
534
|
+
return new _Color(red, green, blue, alpha);
|
|
535
|
+
}
|
|
536
|
+
static fromHex(hex) {
|
|
537
|
+
if (!validateHexColor(hex)) {
|
|
538
|
+
throw new Error("Invalid hex color");
|
|
539
|
+
}
|
|
540
|
+
const [red, green, blue] = normalizeHexString(hex.slice(1)).match(/.{2}/g)?.map((value) => Number.parseInt(value, 16)) ?? [0, 0, 0];
|
|
541
|
+
return new _Color(red, green, blue);
|
|
542
|
+
}
|
|
543
|
+
get brightness() {
|
|
544
|
+
return (this.red * 299 + this.green * 587 + this.blue * 114) / 1e3;
|
|
545
|
+
}
|
|
546
|
+
get isDark() {
|
|
547
|
+
return this.brightness < 128;
|
|
548
|
+
}
|
|
549
|
+
get isLight() {
|
|
550
|
+
return !this.isDark;
|
|
551
|
+
}
|
|
552
|
+
toHexString(isUpperCase = true) {
|
|
553
|
+
const hexString = `#${pad2(this.red.toString(16))}${pad2(this.green.toString(16))}${pad2(this.blue.toString(16))}`;
|
|
554
|
+
return isUpperCase ? hexString.toUpperCase() : hexString;
|
|
555
|
+
}
|
|
556
|
+
toRGBAString() {
|
|
557
|
+
return `rgba(${this.red}, ${this.green}, ${this.blue}, ${this.alpha})`;
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* add alpha value to {@link Color}
|
|
561
|
+
*
|
|
562
|
+
* @param alpha - alpha value
|
|
563
|
+
* @returns instance of {@link Color}
|
|
564
|
+
*/
|
|
565
|
+
withAlpha(alpha = 1) {
|
|
566
|
+
return new _Color(this.red, this.green, this.blue, alpha);
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* lighten the color by percentage
|
|
570
|
+
*
|
|
571
|
+
* @param percentage - percentage to lighten
|
|
572
|
+
*/
|
|
573
|
+
lighten(percentage = 0) {
|
|
574
|
+
const amount = Math.round(percentage / 100 * 255);
|
|
575
|
+
return new _Color(
|
|
576
|
+
Math.min(this.red + amount, 255),
|
|
577
|
+
Math.min(this.green + amount, 255),
|
|
578
|
+
Math.min(this.blue + amount, 255),
|
|
579
|
+
this.alpha
|
|
580
|
+
);
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* darken the color by percentage
|
|
584
|
+
*
|
|
585
|
+
* @param percentage - percentage to darken
|
|
586
|
+
*/
|
|
587
|
+
darken(percentage = 0) {
|
|
588
|
+
const amount = Math.round(percentage / 100 * 255);
|
|
589
|
+
return new _Color(
|
|
590
|
+
Math.max(this.red - amount, 0),
|
|
591
|
+
Math.max(this.green - amount, 0),
|
|
592
|
+
Math.max(this.blue - amount, 0),
|
|
593
|
+
this.alpha
|
|
594
|
+
);
|
|
595
|
+
}
|
|
596
|
+
};
|
|
597
|
+
|
|
598
|
+
// src/color/random.ts
|
|
599
|
+
var MAX_RGB = 255;
|
|
600
|
+
function randomRGBColor() {
|
|
601
|
+
return `rgb(${randomNumber(MAX_RGB)}, ${randomNumber(MAX_RGB)}, ${randomNumber(MAX_RGB)})`;
|
|
602
|
+
}
|
|
603
|
+
function randomRGBAColor() {
|
|
604
|
+
return `rgba(${randomNumber(MAX_RGB)}, ${randomNumber(MAX_RGB)}, ${randomNumber(MAX_RGB)}, ${Math.random().toFixed(1)})`;
|
|
605
|
+
}
|
|
606
|
+
function randomHexColor() {
|
|
607
|
+
return `#${Math.random().toString(16).slice(2, 8)}`;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
// src/proxy/enhance.ts
|
|
611
|
+
function enhance(module2, extra) {
|
|
612
|
+
return new Proxy(module2, {
|
|
613
|
+
get(target, key, receiver) {
|
|
614
|
+
if (Reflect.has(extra, key)) {
|
|
615
|
+
return Reflect.get(extra, key, receiver);
|
|
616
|
+
}
|
|
617
|
+
return Reflect.get(target, key, receiver);
|
|
618
|
+
},
|
|
619
|
+
has(target, key) {
|
|
620
|
+
return Reflect.has(extra, key) || Reflect.has(target, key);
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
|
|
509
625
|
// src/object/omit.ts
|
|
510
626
|
function omit(object, ...keys) {
|
|
511
627
|
keys.forEach((key) => delete object[key]);
|
|
@@ -537,11 +653,11 @@ function cleanObject(obj, options = {}) {
|
|
|
537
653
|
const {
|
|
538
654
|
cleanUndefined = true,
|
|
539
655
|
cleanNull = true,
|
|
540
|
-
cleanZero = false,
|
|
541
656
|
cleanNaN = true,
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
657
|
+
cleanZero = false,
|
|
658
|
+
cleanEmptyString = false,
|
|
659
|
+
cleanEmptyArray = false,
|
|
660
|
+
cleanEmptyObject = false,
|
|
545
661
|
recursive = true
|
|
546
662
|
} = options;
|
|
547
663
|
Object.keys(obj).forEach((key) => {
|
|
@@ -605,88 +721,18 @@ function sortObject(obj, options = {}) {
|
|
|
605
721
|
return sortKeys(obj);
|
|
606
722
|
}
|
|
607
723
|
|
|
608
|
-
//
|
|
609
|
-
var
|
|
610
|
-
var STR_SPLITTERS = ["-", "_", "/", "."];
|
|
611
|
-
function isUppercase(char = "") {
|
|
612
|
-
if (NUMBER_CHAR_RE.test(char)) {
|
|
613
|
-
return void 0;
|
|
614
|
-
}
|
|
615
|
-
return char !== char.toLowerCase();
|
|
616
|
-
}
|
|
617
|
-
function splitByCase(str, separators) {
|
|
618
|
-
const splitters = separators ?? STR_SPLITTERS;
|
|
619
|
-
const parts = [];
|
|
620
|
-
if (!str || typeof str !== "string") {
|
|
621
|
-
return parts;
|
|
622
|
-
}
|
|
623
|
-
let buff = "";
|
|
624
|
-
let previousUpper;
|
|
625
|
-
let previousSplitter;
|
|
626
|
-
for (const char of str) {
|
|
627
|
-
const isSplitter = splitters.includes(char);
|
|
628
|
-
if (isSplitter === true) {
|
|
629
|
-
parts.push(buff);
|
|
630
|
-
buff = "";
|
|
631
|
-
previousUpper = void 0;
|
|
632
|
-
continue;
|
|
633
|
-
}
|
|
634
|
-
const isUpper = isUppercase(char);
|
|
635
|
-
if (previousSplitter === false) {
|
|
636
|
-
if (previousUpper === false && isUpper === true) {
|
|
637
|
-
parts.push(buff);
|
|
638
|
-
buff = char;
|
|
639
|
-
previousUpper = isUpper;
|
|
640
|
-
continue;
|
|
641
|
-
}
|
|
642
|
-
if (previousUpper === true && isUpper === false && buff.length > 1) {
|
|
643
|
-
const lastChar = buff.at(-1);
|
|
644
|
-
parts.push(buff.slice(0, Math.max(0, buff.length - 1)));
|
|
645
|
-
buff = lastChar + char;
|
|
646
|
-
previousUpper = isUpper;
|
|
647
|
-
continue;
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
buff += char;
|
|
651
|
-
previousUpper = isUpper;
|
|
652
|
-
previousSplitter = isSplitter;
|
|
653
|
-
}
|
|
654
|
-
parts.push(buff);
|
|
655
|
-
return parts;
|
|
656
|
-
}
|
|
657
|
-
function upperFirst(str) {
|
|
658
|
-
return str ? str[0].toUpperCase() + str.slice(1) : "";
|
|
659
|
-
}
|
|
660
|
-
function lowerFirst(str) {
|
|
661
|
-
return str ? str[0].toLowerCase() + str.slice(1) : "";
|
|
662
|
-
}
|
|
663
|
-
function pascalCase(str, opts) {
|
|
664
|
-
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => upperFirst(opts?.normalize ? p.toLowerCase() : p)).join("") : "";
|
|
665
|
-
}
|
|
666
|
-
function camelCase(str, opts) {
|
|
667
|
-
return lowerFirst(pascalCase(str || "", opts));
|
|
668
|
-
}
|
|
669
|
-
function kebabCase(str, joiner) {
|
|
670
|
-
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => p.toLowerCase()).join(joiner ?? "-") : "";
|
|
671
|
-
}
|
|
672
|
-
function snakeCase(str) {
|
|
673
|
-
return kebabCase(str || "", "_");
|
|
674
|
-
}
|
|
675
|
-
function flatCase(str) {
|
|
676
|
-
return kebabCase(str || "", "");
|
|
677
|
-
}
|
|
678
|
-
function trainCase(str, opts) {
|
|
679
|
-
return (Array.isArray(str) ? str : splitByCase(str)).filter(Boolean).map((p) => upperFirst(opts?.normalize ? p.toLowerCase() : p)).join("-");
|
|
680
|
-
}
|
|
681
|
-
var titleCaseExceptions = /^(a|an|and|as|at|but|by|for|if|in|is|nor|of|on|or|the|to|with)$/i;
|
|
682
|
-
function titleCase(str, opts) {
|
|
683
|
-
return (Array.isArray(str) ? str : splitByCase(str)).filter(Boolean).map(
|
|
684
|
-
(p) => titleCaseExceptions.test(p) ? p.toLowerCase() : upperFirst(opts?.normalize ? p.toLowerCase() : p)
|
|
685
|
-
).join(" ");
|
|
686
|
-
}
|
|
724
|
+
// src/vendor/index.ts
|
|
725
|
+
var vendor_exports = {};
|
|
687
726
|
|
|
688
|
-
// src/vendor/
|
|
689
|
-
var
|
|
727
|
+
// src/vendor/changeCase.ts
|
|
728
|
+
var changeCase_exports = {};
|
|
729
|
+
__reExport(changeCase_exports, require("change-case"));
|
|
730
|
+
|
|
731
|
+
// src/vendor/index.ts
|
|
732
|
+
__reExport(vendor_exports, changeCase_exports);
|
|
733
|
+
|
|
734
|
+
// src/index.ts
|
|
735
|
+
__reExport(index_exports, vendor_exports, module.exports);
|
|
690
736
|
|
|
691
737
|
// src/module/interopDefault.ts
|
|
692
738
|
async function interopDefault(mod) {
|
|
@@ -700,21 +746,20 @@ function resolveSubOptions(options, key) {
|
|
|
700
746
|
}
|
|
701
747
|
// Annotate the CommonJS export names for ESM import in node:
|
|
702
748
|
0 && (module.exports = {
|
|
749
|
+
Color,
|
|
703
750
|
NOOP,
|
|
704
751
|
at,
|
|
705
752
|
cAF,
|
|
706
|
-
camelCase,
|
|
707
|
-
capitalize,
|
|
708
753
|
chunk,
|
|
709
754
|
clamp,
|
|
710
755
|
cleanObject,
|
|
711
756
|
createPadString,
|
|
712
757
|
days,
|
|
713
758
|
debounce,
|
|
759
|
+
enhance,
|
|
714
760
|
ensurePrefix,
|
|
715
761
|
ensureSuffix,
|
|
716
762
|
escapeHtml,
|
|
717
|
-
flatCase,
|
|
718
763
|
flattenArrayable,
|
|
719
764
|
getObjectType,
|
|
720
765
|
hasOwn,
|
|
@@ -753,36 +798,31 @@ function resolveSubOptions(options, key) {
|
|
|
753
798
|
isSet,
|
|
754
799
|
isString,
|
|
755
800
|
isUndefined,
|
|
756
|
-
isUppercase,
|
|
757
801
|
isWhitespaceString,
|
|
758
802
|
isZero,
|
|
759
803
|
join,
|
|
760
|
-
kebabCase,
|
|
761
804
|
last,
|
|
762
|
-
lowerFirst,
|
|
763
805
|
mergeArrayable,
|
|
764
806
|
minutes,
|
|
765
807
|
noop,
|
|
766
808
|
omit,
|
|
767
809
|
once,
|
|
768
|
-
pascalCase,
|
|
769
810
|
pick,
|
|
770
811
|
rAF,
|
|
812
|
+
randomHexColor,
|
|
813
|
+
randomNumber,
|
|
814
|
+
randomRGBAColor,
|
|
815
|
+
randomRGBColor,
|
|
771
816
|
randomString,
|
|
772
817
|
resolveSubOptions,
|
|
773
818
|
seconds,
|
|
774
819
|
slash,
|
|
775
|
-
snakeCase,
|
|
776
820
|
sortObject,
|
|
777
|
-
splitByCase,
|
|
778
821
|
throttle,
|
|
779
|
-
titleCase,
|
|
780
822
|
toArray,
|
|
781
|
-
trainCase,
|
|
782
823
|
unindent,
|
|
783
824
|
unique,
|
|
784
825
|
uniqueBy,
|
|
785
|
-
upperFirst,
|
|
786
826
|
waitFor,
|
|
787
827
|
warnOnce,
|
|
788
828
|
weeks
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export * from 'scule';
|
|
1
|
+
export * from 'change-case';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* check if two values are deeply equal
|
|
@@ -119,7 +118,7 @@ declare function clamp(value: number, min?: number, max?: number): number;
|
|
|
119
118
|
* // do somthing after 3 seconds
|
|
120
119
|
* ```
|
|
121
120
|
*/
|
|
122
|
-
declare function waitFor(ms: number): Promise<
|
|
121
|
+
declare function waitFor(ms: number): Promise<void>;
|
|
123
122
|
|
|
124
123
|
interface ThrottleDebounceOptions {
|
|
125
124
|
/**
|
|
@@ -253,6 +252,63 @@ declare function intersect<T>(a: T[], b: T[]): T[];
|
|
|
253
252
|
|
|
254
253
|
declare function isArrayEqual(array1: unknown[], array2: unknown[]): boolean;
|
|
255
254
|
|
|
255
|
+
declare class Color {
|
|
256
|
+
red: number;
|
|
257
|
+
green: number;
|
|
258
|
+
blue: number;
|
|
259
|
+
alpha: number;
|
|
260
|
+
constructor(red?: number, green?: number, blue?: number, alpha?: number);
|
|
261
|
+
static fromRGB(red: number, green: number, blue: number): Color;
|
|
262
|
+
static fromRGBA(red: number, green: number, blue: number, alpha: number): Color;
|
|
263
|
+
static fromHex(hex: string): Color;
|
|
264
|
+
get brightness(): number;
|
|
265
|
+
get isDark(): boolean;
|
|
266
|
+
get isLight(): boolean;
|
|
267
|
+
toHexString(isUpperCase?: boolean): string;
|
|
268
|
+
toRGBAString(): string;
|
|
269
|
+
/**
|
|
270
|
+
* add alpha value to {@link Color}
|
|
271
|
+
*
|
|
272
|
+
* @param alpha - alpha value
|
|
273
|
+
* @returns instance of {@link Color}
|
|
274
|
+
*/
|
|
275
|
+
withAlpha(alpha?: number): Color;
|
|
276
|
+
/**
|
|
277
|
+
* lighten the color by percentage
|
|
278
|
+
*
|
|
279
|
+
* @param percentage - percentage to lighten
|
|
280
|
+
*/
|
|
281
|
+
lighten(percentage?: number): Color;
|
|
282
|
+
/**
|
|
283
|
+
* darken the color by percentage
|
|
284
|
+
*
|
|
285
|
+
* @param percentage - percentage to darken
|
|
286
|
+
*/
|
|
287
|
+
darken(percentage?: number): Color;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* get a random RGB color
|
|
292
|
+
* @returns a random RGB color
|
|
293
|
+
*/
|
|
294
|
+
declare function randomRGBColor(): string;
|
|
295
|
+
/**
|
|
296
|
+
* get a random RGBA color
|
|
297
|
+
* @returns a random RGBA color
|
|
298
|
+
*/
|
|
299
|
+
declare function randomRGBAColor(): string;
|
|
300
|
+
/**
|
|
301
|
+
* get a random hex color
|
|
302
|
+
* @returns a random hex color
|
|
303
|
+
*/
|
|
304
|
+
declare function randomHexColor(): string;
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* enhance object
|
|
308
|
+
* @module proxy
|
|
309
|
+
*/
|
|
310
|
+
declare function enhance<T extends Record<PropertyKey, any>, E extends Record<PropertyKey, any>>(module: T, extra: E): T;
|
|
311
|
+
|
|
256
312
|
interface CreatePadStringOptions {
|
|
257
313
|
length: number;
|
|
258
314
|
char: string;
|
|
@@ -341,19 +397,19 @@ interface CleanObjectOptions {
|
|
|
341
397
|
/**
|
|
342
398
|
* clean empty string
|
|
343
399
|
*
|
|
344
|
-
* @default
|
|
400
|
+
* @default false
|
|
345
401
|
*/
|
|
346
402
|
cleanEmptyString?: boolean;
|
|
347
403
|
/**
|
|
348
404
|
* clean empty array
|
|
349
405
|
*
|
|
350
|
-
* @default
|
|
406
|
+
* @default false
|
|
351
407
|
*/
|
|
352
408
|
cleanEmptyArray?: boolean;
|
|
353
409
|
/**
|
|
354
410
|
* clean empty object
|
|
355
411
|
*
|
|
356
|
-
* @default
|
|
412
|
+
* @default false
|
|
357
413
|
*/
|
|
358
414
|
cleanEmptyObject?: boolean;
|
|
359
415
|
/**
|
|
@@ -395,16 +451,6 @@ interface SortObjectOptions {
|
|
|
395
451
|
*/
|
|
396
452
|
declare function sortObject<T extends Record<string, any>>(obj: T, options?: SortObjectOptions): T;
|
|
397
453
|
|
|
398
|
-
/**
|
|
399
|
-
* @file case utils
|
|
400
|
-
* @module vendor
|
|
401
|
-
*/
|
|
402
|
-
|
|
403
|
-
/**
|
|
404
|
-
* @deprecated use upperFirst instead
|
|
405
|
-
*/
|
|
406
|
-
declare const capitalize: typeof upperFirst;
|
|
407
|
-
|
|
408
454
|
/**
|
|
409
455
|
* Interop default export from a module
|
|
410
456
|
*
|
|
@@ -450,4 +496,21 @@ declare function interopDefault<T>(mod: Awaitable<T>): Promise<InteropModuleDefa
|
|
|
450
496
|
*/
|
|
451
497
|
declare function resolveSubOptions<T extends Record<string, any>, K extends keyof T>(options: T, key: K): Partial<ResolvedOptions<T[K]>>;
|
|
452
498
|
|
|
453
|
-
|
|
499
|
+
interface RamdomNumberOptions {
|
|
500
|
+
/**
|
|
501
|
+
* include max value
|
|
502
|
+
*
|
|
503
|
+
* @default false
|
|
504
|
+
*/
|
|
505
|
+
includeMax?: boolean;
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* random an integer by given range
|
|
509
|
+
*
|
|
510
|
+
* @param min - min value
|
|
511
|
+
* @param max - max value
|
|
512
|
+
* @returns random integer in range
|
|
513
|
+
*/
|
|
514
|
+
declare function randomNumber(min: number, max?: number, options?: RamdomNumberOptions): number;
|
|
515
|
+
|
|
516
|
+
export { type AnyFn, type Arrayable, type Awaitable, type Callable, type CleanObjectOptions, Color, type CreatePadStringOptions, type InteropModuleDefault, type JsonArray, type JsonObject, type JsonPrimitive, type JsonValue, type MayBe, NOOP, type NonEmptyString, type Nullable, type Overwrite, type Prettify, type PrettifyV2, type PrimitiveType, type RamdomNumberOptions, type ResolvedOptions, type SortObjectOptions, type ThrottleDebounceOptions, type Whitespace, at, cAF, chunk, clamp, cleanObject, createPadString, days, debounce, enhance, ensurePrefix, ensureSuffix, escapeHtml, flattenArrayable, getObjectType, hasOwn, hours, interopDefault, intersect, isArray, isArrayEqual, isBigInt, isBoolean, isBrowser, isDeepEqual, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isEmptyStringOrWhitespace, isError, isFunction, isInteger, isIterable, isMap, isNaN, isNativePromise, isNil, isNonEmptyArray, isNonEmptyString, isNull, isNullOrUndefined, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isUndefined, isWhitespaceString, isZero, join, last, mergeArrayable, minutes, noop, omit, once, pick, rAF, randomHexColor, randomNumber, randomRGBAColor, randomRGBColor, randomString, resolveSubOptions, seconds, slash, sortObject, throttle, toArray, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export * from 'scule';
|
|
1
|
+
export * from 'change-case';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* check if two values are deeply equal
|
|
@@ -119,7 +118,7 @@ declare function clamp(value: number, min?: number, max?: number): number;
|
|
|
119
118
|
* // do somthing after 3 seconds
|
|
120
119
|
* ```
|
|
121
120
|
*/
|
|
122
|
-
declare function waitFor(ms: number): Promise<
|
|
121
|
+
declare function waitFor(ms: number): Promise<void>;
|
|
123
122
|
|
|
124
123
|
interface ThrottleDebounceOptions {
|
|
125
124
|
/**
|
|
@@ -253,6 +252,63 @@ declare function intersect<T>(a: T[], b: T[]): T[];
|
|
|
253
252
|
|
|
254
253
|
declare function isArrayEqual(array1: unknown[], array2: unknown[]): boolean;
|
|
255
254
|
|
|
255
|
+
declare class Color {
|
|
256
|
+
red: number;
|
|
257
|
+
green: number;
|
|
258
|
+
blue: number;
|
|
259
|
+
alpha: number;
|
|
260
|
+
constructor(red?: number, green?: number, blue?: number, alpha?: number);
|
|
261
|
+
static fromRGB(red: number, green: number, blue: number): Color;
|
|
262
|
+
static fromRGBA(red: number, green: number, blue: number, alpha: number): Color;
|
|
263
|
+
static fromHex(hex: string): Color;
|
|
264
|
+
get brightness(): number;
|
|
265
|
+
get isDark(): boolean;
|
|
266
|
+
get isLight(): boolean;
|
|
267
|
+
toHexString(isUpperCase?: boolean): string;
|
|
268
|
+
toRGBAString(): string;
|
|
269
|
+
/**
|
|
270
|
+
* add alpha value to {@link Color}
|
|
271
|
+
*
|
|
272
|
+
* @param alpha - alpha value
|
|
273
|
+
* @returns instance of {@link Color}
|
|
274
|
+
*/
|
|
275
|
+
withAlpha(alpha?: number): Color;
|
|
276
|
+
/**
|
|
277
|
+
* lighten the color by percentage
|
|
278
|
+
*
|
|
279
|
+
* @param percentage - percentage to lighten
|
|
280
|
+
*/
|
|
281
|
+
lighten(percentage?: number): Color;
|
|
282
|
+
/**
|
|
283
|
+
* darken the color by percentage
|
|
284
|
+
*
|
|
285
|
+
* @param percentage - percentage to darken
|
|
286
|
+
*/
|
|
287
|
+
darken(percentage?: number): Color;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* get a random RGB color
|
|
292
|
+
* @returns a random RGB color
|
|
293
|
+
*/
|
|
294
|
+
declare function randomRGBColor(): string;
|
|
295
|
+
/**
|
|
296
|
+
* get a random RGBA color
|
|
297
|
+
* @returns a random RGBA color
|
|
298
|
+
*/
|
|
299
|
+
declare function randomRGBAColor(): string;
|
|
300
|
+
/**
|
|
301
|
+
* get a random hex color
|
|
302
|
+
* @returns a random hex color
|
|
303
|
+
*/
|
|
304
|
+
declare function randomHexColor(): string;
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* enhance object
|
|
308
|
+
* @module proxy
|
|
309
|
+
*/
|
|
310
|
+
declare function enhance<T extends Record<PropertyKey, any>, E extends Record<PropertyKey, any>>(module: T, extra: E): T;
|
|
311
|
+
|
|
256
312
|
interface CreatePadStringOptions {
|
|
257
313
|
length: number;
|
|
258
314
|
char: string;
|
|
@@ -341,19 +397,19 @@ interface CleanObjectOptions {
|
|
|
341
397
|
/**
|
|
342
398
|
* clean empty string
|
|
343
399
|
*
|
|
344
|
-
* @default
|
|
400
|
+
* @default false
|
|
345
401
|
*/
|
|
346
402
|
cleanEmptyString?: boolean;
|
|
347
403
|
/**
|
|
348
404
|
* clean empty array
|
|
349
405
|
*
|
|
350
|
-
* @default
|
|
406
|
+
* @default false
|
|
351
407
|
*/
|
|
352
408
|
cleanEmptyArray?: boolean;
|
|
353
409
|
/**
|
|
354
410
|
* clean empty object
|
|
355
411
|
*
|
|
356
|
-
* @default
|
|
412
|
+
* @default false
|
|
357
413
|
*/
|
|
358
414
|
cleanEmptyObject?: boolean;
|
|
359
415
|
/**
|
|
@@ -395,16 +451,6 @@ interface SortObjectOptions {
|
|
|
395
451
|
*/
|
|
396
452
|
declare function sortObject<T extends Record<string, any>>(obj: T, options?: SortObjectOptions): T;
|
|
397
453
|
|
|
398
|
-
/**
|
|
399
|
-
* @file case utils
|
|
400
|
-
* @module vendor
|
|
401
|
-
*/
|
|
402
|
-
|
|
403
|
-
/**
|
|
404
|
-
* @deprecated use upperFirst instead
|
|
405
|
-
*/
|
|
406
|
-
declare const capitalize: typeof upperFirst;
|
|
407
|
-
|
|
408
454
|
/**
|
|
409
455
|
* Interop default export from a module
|
|
410
456
|
*
|
|
@@ -450,4 +496,21 @@ declare function interopDefault<T>(mod: Awaitable<T>): Promise<InteropModuleDefa
|
|
|
450
496
|
*/
|
|
451
497
|
declare function resolveSubOptions<T extends Record<string, any>, K extends keyof T>(options: T, key: K): Partial<ResolvedOptions<T[K]>>;
|
|
452
498
|
|
|
453
|
-
|
|
499
|
+
interface RamdomNumberOptions {
|
|
500
|
+
/**
|
|
501
|
+
* include max value
|
|
502
|
+
*
|
|
503
|
+
* @default false
|
|
504
|
+
*/
|
|
505
|
+
includeMax?: boolean;
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* random an integer by given range
|
|
509
|
+
*
|
|
510
|
+
* @param min - min value
|
|
511
|
+
* @param max - max value
|
|
512
|
+
* @returns random integer in range
|
|
513
|
+
*/
|
|
514
|
+
declare function randomNumber(min: number, max?: number, options?: RamdomNumberOptions): number;
|
|
515
|
+
|
|
516
|
+
export { type AnyFn, type Arrayable, type Awaitable, type Callable, type CleanObjectOptions, Color, type CreatePadStringOptions, type InteropModuleDefault, type JsonArray, type JsonObject, type JsonPrimitive, type JsonValue, type MayBe, NOOP, type NonEmptyString, type Nullable, type Overwrite, type Prettify, type PrettifyV2, type PrimitiveType, type RamdomNumberOptions, type ResolvedOptions, type SortObjectOptions, type ThrottleDebounceOptions, type Whitespace, at, cAF, chunk, clamp, cleanObject, createPadString, days, debounce, enhance, ensurePrefix, ensureSuffix, escapeHtml, flattenArrayable, getObjectType, hasOwn, hours, interopDefault, intersect, isArray, isArrayEqual, isBigInt, isBoolean, isBrowser, isDeepEqual, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isEmptyStringOrWhitespace, isError, isFunction, isInteger, isIterable, isMap, isNaN, isNativePromise, isNil, isNonEmptyArray, isNonEmptyString, isNull, isNullOrUndefined, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isUndefined, isWhitespaceString, isZero, join, last, mergeArrayable, minutes, noop, omit, once, pick, rAF, randomHexColor, randomNumber, randomRGBAColor, randomRGBColor, randomString, resolveSubOptions, seconds, slash, sortObject, throttle, toArray, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,106 @@
|
|
|
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 index_exports = {};
|
|
21
|
+
__export(index_exports, {
|
|
22
|
+
Color: () => Color,
|
|
23
|
+
NOOP: () => NOOP,
|
|
24
|
+
at: () => at,
|
|
25
|
+
cAF: () => cAF,
|
|
26
|
+
chunk: () => chunk,
|
|
27
|
+
clamp: () => clamp,
|
|
28
|
+
cleanObject: () => cleanObject,
|
|
29
|
+
createPadString: () => createPadString,
|
|
30
|
+
days: () => days,
|
|
31
|
+
debounce: () => debounce,
|
|
32
|
+
enhance: () => enhance,
|
|
33
|
+
ensurePrefix: () => ensurePrefix,
|
|
34
|
+
ensureSuffix: () => ensureSuffix,
|
|
35
|
+
escapeHtml: () => escapeHtml,
|
|
36
|
+
flattenArrayable: () => flattenArrayable,
|
|
37
|
+
getObjectType: () => getObjectType,
|
|
38
|
+
hasOwn: () => hasOwn,
|
|
39
|
+
hours: () => hours,
|
|
40
|
+
interopDefault: () => interopDefault,
|
|
41
|
+
intersect: () => intersect,
|
|
42
|
+
isArray: () => isArray,
|
|
43
|
+
isArrayEqual: () => isArrayEqual,
|
|
44
|
+
isBigInt: () => isBigInt,
|
|
45
|
+
isBoolean: () => isBoolean,
|
|
46
|
+
isBrowser: () => isBrowser,
|
|
47
|
+
isDeepEqual: () => isDeepEqual,
|
|
48
|
+
isEmptyArray: () => isEmptyArray,
|
|
49
|
+
isEmptyMap: () => isEmptyMap,
|
|
50
|
+
isEmptyObject: () => isEmptyObject,
|
|
51
|
+
isEmptySet: () => isEmptySet,
|
|
52
|
+
isEmptyString: () => isEmptyString,
|
|
53
|
+
isEmptyStringOrWhitespace: () => isEmptyStringOrWhitespace,
|
|
54
|
+
isError: () => isError,
|
|
55
|
+
isFunction: () => isFunction,
|
|
56
|
+
isInteger: () => isInteger,
|
|
57
|
+
isIterable: () => isIterable,
|
|
58
|
+
isMap: () => isMap,
|
|
59
|
+
isNaN: () => isNaN,
|
|
60
|
+
isNativePromise: () => isNativePromise,
|
|
61
|
+
isNil: () => isNil,
|
|
62
|
+
isNonEmptyArray: () => isNonEmptyArray,
|
|
63
|
+
isNonEmptyString: () => isNonEmptyString,
|
|
64
|
+
isNull: () => isNull,
|
|
65
|
+
isNullOrUndefined: () => isNullOrUndefined,
|
|
66
|
+
isNumber: () => isNumber,
|
|
67
|
+
isNumbericString: () => isNumbericString,
|
|
68
|
+
isObject: () => isObject,
|
|
69
|
+
isPromise: () => isPromise,
|
|
70
|
+
isRegExp: () => isRegExp,
|
|
71
|
+
isSet: () => isSet,
|
|
72
|
+
isString: () => isString,
|
|
73
|
+
isUndefined: () => isUndefined,
|
|
74
|
+
isWhitespaceString: () => isWhitespaceString,
|
|
75
|
+
isZero: () => isZero,
|
|
76
|
+
join: () => join,
|
|
77
|
+
last: () => last,
|
|
78
|
+
mergeArrayable: () => mergeArrayable,
|
|
79
|
+
minutes: () => minutes,
|
|
80
|
+
noop: () => noop,
|
|
81
|
+
omit: () => omit,
|
|
82
|
+
once: () => once,
|
|
83
|
+
pick: () => pick,
|
|
84
|
+
rAF: () => rAF,
|
|
85
|
+
randomHexColor: () => randomHexColor,
|
|
86
|
+
randomNumber: () => randomNumber,
|
|
87
|
+
randomRGBAColor: () => randomRGBAColor,
|
|
88
|
+
randomRGBColor: () => randomRGBColor,
|
|
89
|
+
randomString: () => randomString,
|
|
90
|
+
resolveSubOptions: () => resolveSubOptions,
|
|
91
|
+
seconds: () => seconds,
|
|
92
|
+
slash: () => slash,
|
|
93
|
+
sortObject: () => sortObject,
|
|
94
|
+
throttle: () => throttle,
|
|
95
|
+
toArray: () => toArray,
|
|
96
|
+
unindent: () => unindent,
|
|
97
|
+
unique: () => unique,
|
|
98
|
+
uniqueBy: () => uniqueBy,
|
|
99
|
+
waitFor: () => waitFor,
|
|
100
|
+
warnOnce: () => warnOnce,
|
|
101
|
+
weeks: () => weeks
|
|
102
|
+
});
|
|
103
|
+
|
|
1
104
|
// src/is/isDeepEqual.ts
|
|
2
105
|
function isDeepEqual(value1, value2) {
|
|
3
106
|
const type1 = getObjectType(value1);
|
|
@@ -5,19 +108,22 @@ function isDeepEqual(value1, value2) {
|
|
|
5
108
|
if (type1 !== type2) {
|
|
6
109
|
return false;
|
|
7
110
|
}
|
|
8
|
-
if (isArray(value1)) {
|
|
111
|
+
if (isArray(value1) && isArray(value2)) {
|
|
9
112
|
if (value1.length !== value2.length) {
|
|
10
113
|
return false;
|
|
11
114
|
}
|
|
12
115
|
return value1.every((item, index) => isDeepEqual(item, value2[index]));
|
|
13
116
|
}
|
|
14
|
-
if (isObject(value1)) {
|
|
117
|
+
if (isObject(value1) && isObject(value2)) {
|
|
15
118
|
const keys = Object.keys(value1);
|
|
16
119
|
if (keys.length !== Object.keys(value2).length) {
|
|
17
120
|
return false;
|
|
18
121
|
}
|
|
19
122
|
return keys.every(
|
|
20
|
-
(key) => isDeepEqual(
|
|
123
|
+
(key) => isDeepEqual(
|
|
124
|
+
value1[key],
|
|
125
|
+
value2[key]
|
|
126
|
+
)
|
|
21
127
|
);
|
|
22
128
|
}
|
|
23
129
|
return Object.is(value1, value2);
|
|
@@ -110,7 +216,10 @@ function isError(value) {
|
|
|
110
216
|
return getObjectType(value) === "Error";
|
|
111
217
|
}
|
|
112
218
|
function hasPromiseApi(value) {
|
|
113
|
-
return
|
|
219
|
+
return (
|
|
220
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
221
|
+
isFunction(value?.then) && isFunction(value?.catch)
|
|
222
|
+
);
|
|
114
223
|
}
|
|
115
224
|
function isNativePromise(value) {
|
|
116
225
|
return getObjectType(value) === "Promise";
|
|
@@ -190,7 +299,7 @@ function clamp(value, min = Number.NEGATIVE_INFINITY, max = Number.POSITIVE_INFI
|
|
|
190
299
|
}
|
|
191
300
|
|
|
192
301
|
// src/misc/waitFor.ts
|
|
193
|
-
function waitFor(ms) {
|
|
302
|
+
async function waitFor(ms) {
|
|
194
303
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
195
304
|
}
|
|
196
305
|
|
|
@@ -341,7 +450,7 @@ function slash(input) {
|
|
|
341
450
|
}
|
|
342
451
|
|
|
343
452
|
// src/number/random.ts
|
|
344
|
-
function randomNumber(min, max = 0) {
|
|
453
|
+
function randomNumber(min, max = 0, options = {}) {
|
|
345
454
|
if (max === 0) {
|
|
346
455
|
max = min;
|
|
347
456
|
min = 0;
|
|
@@ -350,7 +459,9 @@ function randomNumber(min, max = 0) {
|
|
|
350
459
|
;
|
|
351
460
|
[min, max] = [max, min];
|
|
352
461
|
}
|
|
353
|
-
return Math.trunc(
|
|
462
|
+
return Math.trunc(
|
|
463
|
+
Math.random() * (max - min + (options.includeMax ? 1 : 0)) + min
|
|
464
|
+
);
|
|
354
465
|
}
|
|
355
466
|
|
|
356
467
|
// src/string/random.ts
|
|
@@ -395,6 +506,119 @@ function ensureSuffix(input, suffix) {
|
|
|
395
506
|
return input.endsWith(suffix) ? input : `${input}${suffix}`;
|
|
396
507
|
}
|
|
397
508
|
|
|
509
|
+
// src/color/color.ts
|
|
510
|
+
var pad2 = createPadString({ length: 2, char: "0" });
|
|
511
|
+
var RE_VALID_HEX_COLOR = /^#(?:[0-9a-f]{6}|[0-9a-f]{3})$/i;
|
|
512
|
+
function validateHexColor(hex) {
|
|
513
|
+
if (hex.length !== 4 && hex.length !== 7) return false;
|
|
514
|
+
if (!hex.startsWith("#")) return false;
|
|
515
|
+
return RE_VALID_HEX_COLOR.test(hex);
|
|
516
|
+
}
|
|
517
|
+
function normalizeHexString(hex) {
|
|
518
|
+
return hex.length === 6 ? hex : hex.replace(/./g, "$&$&");
|
|
519
|
+
}
|
|
520
|
+
var Color = class _Color {
|
|
521
|
+
constructor(red = 0, green = 0, blue = 0, alpha = 1) {
|
|
522
|
+
this.red = red;
|
|
523
|
+
this.green = green;
|
|
524
|
+
this.blue = blue;
|
|
525
|
+
this.alpha = alpha;
|
|
526
|
+
}
|
|
527
|
+
static fromRGB(red, green, blue) {
|
|
528
|
+
return new _Color(red, green, blue);
|
|
529
|
+
}
|
|
530
|
+
static fromRGBA(red, green, blue, alpha) {
|
|
531
|
+
return new _Color(red, green, blue, alpha);
|
|
532
|
+
}
|
|
533
|
+
static fromHex(hex) {
|
|
534
|
+
if (!validateHexColor(hex)) {
|
|
535
|
+
throw new Error("Invalid hex color");
|
|
536
|
+
}
|
|
537
|
+
const [red, green, blue] = normalizeHexString(hex.slice(1)).match(/.{2}/g)?.map((value) => Number.parseInt(value, 16)) ?? [0, 0, 0];
|
|
538
|
+
return new _Color(red, green, blue);
|
|
539
|
+
}
|
|
540
|
+
get brightness() {
|
|
541
|
+
return (this.red * 299 + this.green * 587 + this.blue * 114) / 1e3;
|
|
542
|
+
}
|
|
543
|
+
get isDark() {
|
|
544
|
+
return this.brightness < 128;
|
|
545
|
+
}
|
|
546
|
+
get isLight() {
|
|
547
|
+
return !this.isDark;
|
|
548
|
+
}
|
|
549
|
+
toHexString(isUpperCase = true) {
|
|
550
|
+
const hexString = `#${pad2(this.red.toString(16))}${pad2(this.green.toString(16))}${pad2(this.blue.toString(16))}`;
|
|
551
|
+
return isUpperCase ? hexString.toUpperCase() : hexString;
|
|
552
|
+
}
|
|
553
|
+
toRGBAString() {
|
|
554
|
+
return `rgba(${this.red}, ${this.green}, ${this.blue}, ${this.alpha})`;
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* add alpha value to {@link Color}
|
|
558
|
+
*
|
|
559
|
+
* @param alpha - alpha value
|
|
560
|
+
* @returns instance of {@link Color}
|
|
561
|
+
*/
|
|
562
|
+
withAlpha(alpha = 1) {
|
|
563
|
+
return new _Color(this.red, this.green, this.blue, alpha);
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* lighten the color by percentage
|
|
567
|
+
*
|
|
568
|
+
* @param percentage - percentage to lighten
|
|
569
|
+
*/
|
|
570
|
+
lighten(percentage = 0) {
|
|
571
|
+
const amount = Math.round(percentage / 100 * 255);
|
|
572
|
+
return new _Color(
|
|
573
|
+
Math.min(this.red + amount, 255),
|
|
574
|
+
Math.min(this.green + amount, 255),
|
|
575
|
+
Math.min(this.blue + amount, 255),
|
|
576
|
+
this.alpha
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* darken the color by percentage
|
|
581
|
+
*
|
|
582
|
+
* @param percentage - percentage to darken
|
|
583
|
+
*/
|
|
584
|
+
darken(percentage = 0) {
|
|
585
|
+
const amount = Math.round(percentage / 100 * 255);
|
|
586
|
+
return new _Color(
|
|
587
|
+
Math.max(this.red - amount, 0),
|
|
588
|
+
Math.max(this.green - amount, 0),
|
|
589
|
+
Math.max(this.blue - amount, 0),
|
|
590
|
+
this.alpha
|
|
591
|
+
);
|
|
592
|
+
}
|
|
593
|
+
};
|
|
594
|
+
|
|
595
|
+
// src/color/random.ts
|
|
596
|
+
var MAX_RGB = 255;
|
|
597
|
+
function randomRGBColor() {
|
|
598
|
+
return `rgb(${randomNumber(MAX_RGB)}, ${randomNumber(MAX_RGB)}, ${randomNumber(MAX_RGB)})`;
|
|
599
|
+
}
|
|
600
|
+
function randomRGBAColor() {
|
|
601
|
+
return `rgba(${randomNumber(MAX_RGB)}, ${randomNumber(MAX_RGB)}, ${randomNumber(MAX_RGB)}, ${Math.random().toFixed(1)})`;
|
|
602
|
+
}
|
|
603
|
+
function randomHexColor() {
|
|
604
|
+
return `#${Math.random().toString(16).slice(2, 8)}`;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
// src/proxy/enhance.ts
|
|
608
|
+
function enhance(module, extra) {
|
|
609
|
+
return new Proxy(module, {
|
|
610
|
+
get(target, key, receiver) {
|
|
611
|
+
if (Reflect.has(extra, key)) {
|
|
612
|
+
return Reflect.get(extra, key, receiver);
|
|
613
|
+
}
|
|
614
|
+
return Reflect.get(target, key, receiver);
|
|
615
|
+
},
|
|
616
|
+
has(target, key) {
|
|
617
|
+
return Reflect.has(extra, key) || Reflect.has(target, key);
|
|
618
|
+
}
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
|
|
398
622
|
// src/object/omit.ts
|
|
399
623
|
function omit(object, ...keys) {
|
|
400
624
|
keys.forEach((key) => delete object[key]);
|
|
@@ -426,11 +650,11 @@ function cleanObject(obj, options = {}) {
|
|
|
426
650
|
const {
|
|
427
651
|
cleanUndefined = true,
|
|
428
652
|
cleanNull = true,
|
|
429
|
-
cleanZero = false,
|
|
430
653
|
cleanNaN = true,
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
654
|
+
cleanZero = false,
|
|
655
|
+
cleanEmptyString = false,
|
|
656
|
+
cleanEmptyArray = false,
|
|
657
|
+
cleanEmptyObject = false,
|
|
434
658
|
recursive = true
|
|
435
659
|
} = options;
|
|
436
660
|
Object.keys(obj).forEach((key) => {
|
|
@@ -494,88 +718,19 @@ function sortObject(obj, options = {}) {
|
|
|
494
718
|
return sortKeys(obj);
|
|
495
719
|
}
|
|
496
720
|
|
|
497
|
-
//
|
|
498
|
-
var
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
const splitters = separators ?? STR_SPLITTERS;
|
|
508
|
-
const parts = [];
|
|
509
|
-
if (!str || typeof str !== "string") {
|
|
510
|
-
return parts;
|
|
511
|
-
}
|
|
512
|
-
let buff = "";
|
|
513
|
-
let previousUpper;
|
|
514
|
-
let previousSplitter;
|
|
515
|
-
for (const char of str) {
|
|
516
|
-
const isSplitter = splitters.includes(char);
|
|
517
|
-
if (isSplitter === true) {
|
|
518
|
-
parts.push(buff);
|
|
519
|
-
buff = "";
|
|
520
|
-
previousUpper = void 0;
|
|
521
|
-
continue;
|
|
522
|
-
}
|
|
523
|
-
const isUpper = isUppercase(char);
|
|
524
|
-
if (previousSplitter === false) {
|
|
525
|
-
if (previousUpper === false && isUpper === true) {
|
|
526
|
-
parts.push(buff);
|
|
527
|
-
buff = char;
|
|
528
|
-
previousUpper = isUpper;
|
|
529
|
-
continue;
|
|
530
|
-
}
|
|
531
|
-
if (previousUpper === true && isUpper === false && buff.length > 1) {
|
|
532
|
-
const lastChar = buff.at(-1);
|
|
533
|
-
parts.push(buff.slice(0, Math.max(0, buff.length - 1)));
|
|
534
|
-
buff = lastChar + char;
|
|
535
|
-
previousUpper = isUpper;
|
|
536
|
-
continue;
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
buff += char;
|
|
540
|
-
previousUpper = isUpper;
|
|
541
|
-
previousSplitter = isSplitter;
|
|
542
|
-
}
|
|
543
|
-
parts.push(buff);
|
|
544
|
-
return parts;
|
|
545
|
-
}
|
|
546
|
-
function upperFirst(str) {
|
|
547
|
-
return str ? str[0].toUpperCase() + str.slice(1) : "";
|
|
548
|
-
}
|
|
549
|
-
function lowerFirst(str) {
|
|
550
|
-
return str ? str[0].toLowerCase() + str.slice(1) : "";
|
|
551
|
-
}
|
|
552
|
-
function pascalCase(str, opts) {
|
|
553
|
-
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => upperFirst(opts?.normalize ? p.toLowerCase() : p)).join("") : "";
|
|
554
|
-
}
|
|
555
|
-
function camelCase(str, opts) {
|
|
556
|
-
return lowerFirst(pascalCase(str || "", opts));
|
|
557
|
-
}
|
|
558
|
-
function kebabCase(str, joiner) {
|
|
559
|
-
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => p.toLowerCase()).join(joiner ?? "-") : "";
|
|
560
|
-
}
|
|
561
|
-
function snakeCase(str) {
|
|
562
|
-
return kebabCase(str || "", "_");
|
|
563
|
-
}
|
|
564
|
-
function flatCase(str) {
|
|
565
|
-
return kebabCase(str || "", "");
|
|
566
|
-
}
|
|
567
|
-
function trainCase(str, opts) {
|
|
568
|
-
return (Array.isArray(str) ? str : splitByCase(str)).filter(Boolean).map((p) => upperFirst(opts?.normalize ? p.toLowerCase() : p)).join("-");
|
|
569
|
-
}
|
|
570
|
-
var titleCaseExceptions = /^(a|an|and|as|at|but|by|for|if|in|is|nor|of|on|or|the|to|with)$/i;
|
|
571
|
-
function titleCase(str, opts) {
|
|
572
|
-
return (Array.isArray(str) ? str : splitByCase(str)).filter(Boolean).map(
|
|
573
|
-
(p) => titleCaseExceptions.test(p) ? p.toLowerCase() : upperFirst(opts?.normalize ? p.toLowerCase() : p)
|
|
574
|
-
).join(" ");
|
|
575
|
-
}
|
|
721
|
+
// src/vendor/index.ts
|
|
722
|
+
var vendor_exports = {};
|
|
723
|
+
|
|
724
|
+
// src/vendor/changeCase.ts
|
|
725
|
+
var changeCase_exports = {};
|
|
726
|
+
__reExport(changeCase_exports, change_case_star);
|
|
727
|
+
import * as change_case_star from "change-case";
|
|
728
|
+
|
|
729
|
+
// src/vendor/index.ts
|
|
730
|
+
__reExport(vendor_exports, changeCase_exports);
|
|
576
731
|
|
|
577
|
-
// src/
|
|
578
|
-
|
|
732
|
+
// src/index.ts
|
|
733
|
+
__reExport(index_exports, vendor_exports);
|
|
579
734
|
|
|
580
735
|
// src/module/interopDefault.ts
|
|
581
736
|
async function interopDefault(mod) {
|
|
@@ -588,21 +743,20 @@ function resolveSubOptions(options, key) {
|
|
|
588
743
|
return typeof options[key] === "boolean" ? {} : options[key] || {};
|
|
589
744
|
}
|
|
590
745
|
export {
|
|
746
|
+
Color,
|
|
591
747
|
NOOP,
|
|
592
748
|
at,
|
|
593
749
|
cAF,
|
|
594
|
-
camelCase,
|
|
595
|
-
capitalize,
|
|
596
750
|
chunk,
|
|
597
751
|
clamp,
|
|
598
752
|
cleanObject,
|
|
599
753
|
createPadString,
|
|
600
754
|
days,
|
|
601
755
|
debounce,
|
|
756
|
+
enhance,
|
|
602
757
|
ensurePrefix,
|
|
603
758
|
ensureSuffix,
|
|
604
759
|
escapeHtml,
|
|
605
|
-
flatCase,
|
|
606
760
|
flattenArrayable,
|
|
607
761
|
getObjectType,
|
|
608
762
|
hasOwn,
|
|
@@ -641,36 +795,31 @@ export {
|
|
|
641
795
|
isSet,
|
|
642
796
|
isString,
|
|
643
797
|
isUndefined,
|
|
644
|
-
isUppercase,
|
|
645
798
|
isWhitespaceString,
|
|
646
799
|
isZero,
|
|
647
800
|
join,
|
|
648
|
-
kebabCase,
|
|
649
801
|
last,
|
|
650
|
-
lowerFirst,
|
|
651
802
|
mergeArrayable,
|
|
652
803
|
minutes,
|
|
653
804
|
noop,
|
|
654
805
|
omit,
|
|
655
806
|
once,
|
|
656
|
-
pascalCase,
|
|
657
807
|
pick,
|
|
658
808
|
rAF,
|
|
809
|
+
randomHexColor,
|
|
810
|
+
randomNumber,
|
|
811
|
+
randomRGBAColor,
|
|
812
|
+
randomRGBColor,
|
|
659
813
|
randomString,
|
|
660
814
|
resolveSubOptions,
|
|
661
815
|
seconds,
|
|
662
816
|
slash,
|
|
663
|
-
snakeCase,
|
|
664
817
|
sortObject,
|
|
665
|
-
splitByCase,
|
|
666
818
|
throttle,
|
|
667
|
-
titleCase,
|
|
668
819
|
toArray,
|
|
669
|
-
trainCase,
|
|
670
820
|
unindent,
|
|
671
821
|
unique,
|
|
672
822
|
uniqueBy,
|
|
673
|
-
upperFirst,
|
|
674
823
|
waitFor,
|
|
675
824
|
warnOnce,
|
|
676
825
|
weeks
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ntnyq/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.2",
|
|
5
5
|
"description": "Common used utils.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"utils"
|
|
@@ -37,18 +37,18 @@
|
|
|
37
37
|
],
|
|
38
38
|
"sideEffects": false,
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"
|
|
40
|
+
"change-case": "^5.4.4"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@ntnyq/eslint-config": "^4.0.0-beta.
|
|
43
|
+
"@ntnyq/eslint-config": "^4.0.0-beta.4",
|
|
44
44
|
"@ntnyq/prettier-config": "^2.0.0-beta.2",
|
|
45
45
|
"@vitest/coverage-v8": "^3.0.5",
|
|
46
|
-
"bumpp": "^10.0.
|
|
47
|
-
"eslint": "^9.20.
|
|
46
|
+
"bumpp": "^10.0.3",
|
|
47
|
+
"eslint": "^9.20.1",
|
|
48
48
|
"husky": "^9.1.7",
|
|
49
49
|
"nano-staged": "^0.8.0",
|
|
50
50
|
"npm-run-all2": "^7.0.2",
|
|
51
|
-
"prettier": "^3.5.
|
|
51
|
+
"prettier": "^3.5.1",
|
|
52
52
|
"tsup": "^8.3.6",
|
|
53
53
|
"typescript": "^5.7.3",
|
|
54
54
|
"vitest": "^3.0.5"
|