moderndash 3.12.0 → 4.0.0
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/README.md +2 -13
- package/dist/index.cjs +22 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -26
- package/dist/index.d.ts +30 -26
- package/dist/index.js +22 -41
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -14,9 +14,8 @@
|
|
|
14
14
|
✅ Typescript Strict Mode (no any)
|
|
15
15
|
<br>
|
|
16
16
|
✅ 100% Test Coverage
|
|
17
|
-
✅ Zero dependencies
|
|
17
|
+
✅ Zero runtime dependencies
|
|
18
18
|
✅ Hoverable Docs
|
|
19
|
-
✅ TS Decorators
|
|
20
19
|
</div>
|
|
21
20
|
<p></p>
|
|
22
21
|
|
|
@@ -57,12 +56,7 @@ npm install moderndash
|
|
|
57
56
|
```
|
|
58
57
|
## 📋 Requirements
|
|
59
58
|
|
|
60
|
-
**NodeJS**: >=
|
|
61
|
-
|
|
62
|
-
> `NodeJS 16-18`: Enable the [experimental-global-webcrypto](https://nodejs.dev/en/api/v16/cli#--experimental-global-webcrypto) flag to use crypto functions.
|
|
63
|
-
*Works out of the box with NodeJS 19+*
|
|
64
|
-
|
|
65
|
-
> `TypeScript`: Enable the [experimentalDecorators](https://www.typescriptlang.org/tsconfig#experimentalDecorators) flag to use decorator functions.
|
|
59
|
+
**NodeJS**: >=20.x | **Typescript**: >=5.0
|
|
66
60
|
|
|
67
61
|
## 🚀 Performance
|
|
68
62
|
|
|
@@ -77,11 +71,6 @@ ModernDash does not include any lodash functions that can be easily replaced by
|
|
|
77
71
|
Please refer to [You-Dont-Need-Lodash](https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore) or [youmightnotneed.com/lodash](https://youmightnotneed.com/lodash) for native replacements.
|
|
78
72
|
If you still believe a function is missing, please open an issue.
|
|
79
73
|
|
|
80
|
-
### Why no pipe utility functions?
|
|
81
|
-
The upcoming [pipe operator](https://github.com/tc39/proposal-pipeline-operator) in JavaScript will provide function composition, so the framework focuses on providing other useful utility functions that are not yet available.
|
|
82
|
-
|
|
83
|
-
The pipe operator can already be included via [babel](https://babeljs.io/docs/en/babel-plugin-proposal-pipeline-operator).
|
|
84
|
-
|
|
85
74
|
## 💌 Love & Thanks
|
|
86
75
|
|
|
87
76
|
To [type-fest](https://github.com/sindresorhus/type-fest) for providing some valuable types.
|
package/dist/index.cjs
CHANGED
|
@@ -317,12 +317,10 @@ function randomInt(min, max) {
|
|
|
317
317
|
// src/crypto/randomElem.ts
|
|
318
318
|
function randomElem(array, multi) {
|
|
319
319
|
if (multi === void 0) {
|
|
320
|
-
if (array.length === 0)
|
|
321
|
-
return void 0;
|
|
320
|
+
if (array.length === 0) return void 0;
|
|
322
321
|
return getSingleElement(array);
|
|
323
322
|
}
|
|
324
|
-
if (multi && array.length === 0)
|
|
325
|
-
return [];
|
|
323
|
+
if (multi && array.length === 0) return [];
|
|
326
324
|
const result = new Array(multi);
|
|
327
325
|
for (let i = 0; i < multi; i++) {
|
|
328
326
|
result[i] = getSingleElement(array);
|
|
@@ -348,8 +346,7 @@ function randomFloat(min, max) {
|
|
|
348
346
|
// src/crypto/randomString.ts
|
|
349
347
|
var DEFAULT_CHARSET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
350
348
|
function randomString(length, charSet = DEFAULT_CHARSET) {
|
|
351
|
-
if (charSet.length <= 0)
|
|
352
|
-
return "";
|
|
349
|
+
if (charSet.length <= 0) return "";
|
|
353
350
|
let result = "";
|
|
354
351
|
for (let index = 0; index < length; index++) {
|
|
355
352
|
const randomIndex = randomInt(0, charSet.length - 1);
|
|
@@ -361,9 +358,9 @@ function randomString(length, charSet = DEFAULT_CHARSET) {
|
|
|
361
358
|
// src/decorator/toDecorator.ts
|
|
362
359
|
function toDecorator(func) {
|
|
363
360
|
return function(...args) {
|
|
364
|
-
return function(
|
|
365
|
-
const
|
|
366
|
-
|
|
361
|
+
return function(originalMethod, _context) {
|
|
362
|
+
const funcArgs = [originalMethod, ...args];
|
|
363
|
+
return func(...funcArgs);
|
|
367
364
|
};
|
|
368
365
|
};
|
|
369
366
|
}
|
|
@@ -773,8 +770,7 @@ function splitWords(str) {
|
|
|
773
770
|
|
|
774
771
|
// src/string/capitalize.ts
|
|
775
772
|
function capitalize(str) {
|
|
776
|
-
if (str === "")
|
|
777
|
-
return "";
|
|
773
|
+
if (str === "") return "";
|
|
778
774
|
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
|
|
779
775
|
}
|
|
780
776
|
|
|
@@ -786,12 +782,10 @@ function deburr(str) {
|
|
|
786
782
|
|
|
787
783
|
// src/string/camelCase.ts
|
|
788
784
|
function camelCase(str) {
|
|
789
|
-
if (str === "")
|
|
790
|
-
return "";
|
|
785
|
+
if (str === "") return "";
|
|
791
786
|
str = deburr(str);
|
|
792
787
|
const words = splitWords(str);
|
|
793
|
-
if (words.length === 0)
|
|
794
|
-
return "";
|
|
788
|
+
if (words.length === 0) return "";
|
|
795
789
|
let camelCase2 = words[0].toLowerCase();
|
|
796
790
|
for (let index = 1; index < words.length; index++) {
|
|
797
791
|
const word = words[index];
|
|
@@ -821,8 +815,7 @@ function escapeRegExp(str) {
|
|
|
821
815
|
|
|
822
816
|
// src/string/kebabCase.ts
|
|
823
817
|
function kebabCase(str) {
|
|
824
|
-
if (str === "")
|
|
825
|
-
return "";
|
|
818
|
+
if (str === "") return "";
|
|
826
819
|
str = deburr(str);
|
|
827
820
|
const words = splitWords(str);
|
|
828
821
|
let kebabCase2 = "";
|
|
@@ -834,8 +827,7 @@ function kebabCase(str) {
|
|
|
834
827
|
|
|
835
828
|
// src/string/pascalCase.ts
|
|
836
829
|
function pascalCase(str) {
|
|
837
|
-
if (str === "")
|
|
838
|
-
return "";
|
|
830
|
+
if (str === "") return "";
|
|
839
831
|
str = deburr(str);
|
|
840
832
|
const words = splitWords(str);
|
|
841
833
|
let pascalCase2 = "";
|
|
@@ -855,8 +847,7 @@ function replaceLast(str, searchFor, replaceWith) {
|
|
|
855
847
|
|
|
856
848
|
// src/string/snakeCase.ts
|
|
857
849
|
function snakeCase(str) {
|
|
858
|
-
if (str === "")
|
|
859
|
-
return "";
|
|
850
|
+
if (str === "") return "";
|
|
860
851
|
str = deburr(str);
|
|
861
852
|
const words = splitWords(str);
|
|
862
853
|
let snakeCase2 = "";
|
|
@@ -871,8 +862,7 @@ function snakeCase(str) {
|
|
|
871
862
|
|
|
872
863
|
// src/string/titleCase.ts
|
|
873
864
|
function titleCase(str) {
|
|
874
|
-
if (str === "")
|
|
875
|
-
return "";
|
|
865
|
+
if (str === "") return "";
|
|
876
866
|
str = deburr(str);
|
|
877
867
|
const words = splitWords(str);
|
|
878
868
|
let titleCase2 = "";
|
|
@@ -916,8 +906,7 @@ function trimStart(str, chars) {
|
|
|
916
906
|
// src/string/truncate.ts
|
|
917
907
|
function truncate(str, options) {
|
|
918
908
|
const { length = 30, ellipsis = "...", separator } = options ?? {};
|
|
919
|
-
if (str.length <= length)
|
|
920
|
-
return str;
|
|
909
|
+
if (str.length <= length) return str;
|
|
921
910
|
const end = length - ellipsis.length;
|
|
922
911
|
if (end < 1)
|
|
923
912
|
return ellipsis;
|
|
@@ -961,10 +950,8 @@ function isEmpty(value) {
|
|
|
961
950
|
|
|
962
951
|
// src/validate/isEqual.ts
|
|
963
952
|
function isEqual(a, b) {
|
|
964
|
-
if (Object.is(a, b))
|
|
965
|
-
|
|
966
|
-
if (typeof a !== typeof b)
|
|
967
|
-
return false;
|
|
953
|
+
if (Object.is(a, b)) return true;
|
|
954
|
+
if (typeof a !== typeof b) return false;
|
|
968
955
|
if (Array.isArray(a) && Array.isArray(b))
|
|
969
956
|
return isSameArray(a, b);
|
|
970
957
|
if (a instanceof Date && b instanceof Date)
|
|
@@ -978,8 +965,7 @@ function isEqual(a, b) {
|
|
|
978
965
|
if (a instanceof DataView && b instanceof DataView)
|
|
979
966
|
return dataViewsAreEqual(a, b);
|
|
980
967
|
if (isTypedArray(a) && isTypedArray(b)) {
|
|
981
|
-
if (a.byteLength !== b.byteLength)
|
|
982
|
-
return false;
|
|
968
|
+
if (a.byteLength !== b.byteLength) return false;
|
|
983
969
|
return isSameArray(a, b);
|
|
984
970
|
}
|
|
985
971
|
return false;
|
|
@@ -987,25 +973,20 @@ function isEqual(a, b) {
|
|
|
987
973
|
function isSameObject(a, b) {
|
|
988
974
|
const keys1 = Object.keys(a);
|
|
989
975
|
const keys2 = Object.keys(b);
|
|
990
|
-
if (!isEqual(keys1, keys2))
|
|
991
|
-
return false;
|
|
976
|
+
if (!isEqual(keys1, keys2)) return false;
|
|
992
977
|
for (const key of keys1) {
|
|
993
|
-
if (!isEqual(a[key], b[key]))
|
|
994
|
-
return false;
|
|
978
|
+
if (!isEqual(a[key], b[key])) return false;
|
|
995
979
|
}
|
|
996
980
|
return true;
|
|
997
981
|
}
|
|
998
982
|
function isSameArray(a, b) {
|
|
999
|
-
if (a.length !== b.length)
|
|
1000
|
-
return false;
|
|
983
|
+
if (a.length !== b.length) return false;
|
|
1001
984
|
return a.every((element, index) => isEqual(element, b[index]));
|
|
1002
985
|
}
|
|
1003
986
|
function dataViewsAreEqual(a, b) {
|
|
1004
|
-
if (a.byteLength !== b.byteLength)
|
|
1005
|
-
return false;
|
|
987
|
+
if (a.byteLength !== b.byteLength) return false;
|
|
1006
988
|
for (let offset = 0; offset < a.byteLength; offset++) {
|
|
1007
|
-
if (a.getUint8(offset) !== b.getUint8(offset))
|
|
1008
|
-
return false;
|
|
989
|
+
if (a.getUint8(offset) !== b.getUint8(offset)) return false;
|
|
1009
990
|
}
|
|
1010
991
|
return true;
|
|
1011
992
|
}
|