moderndash 3.1.0 → 3.3.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 +5 -3
- package/dist/index.cjs +84 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +63 -14
- package/dist/index.js +81 -23
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -58,9 +58,9 @@ npm install moderndash
|
|
|
58
58
|
**NodeJS**: >=16.15 | **Typescript**: >=4.8
|
|
59
59
|
|
|
60
60
|
> `NodeJS 16-18`: Enable the [experimental-global-webcrypto](https://nodejs.dev/en/api/v16/cli#--experimental-global-webcrypto) flag to use crypto functions.
|
|
61
|
-
|
|
61
|
+
*Works out of the box with NodeJS 19+*
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
> `TypeScript`: Enable the [experimentalDecorators](https://www.typescriptlang.org/tsconfig#experimentalDecorators) flag to use decorator functions.
|
|
64
64
|
|
|
65
65
|
## 🚀 Performance
|
|
66
66
|
|
|
@@ -85,4 +85,6 @@ To [type-fest](https://github.com/sindresorhus/type-fest) for providing some val
|
|
|
85
85
|
|
|
86
86
|
## 🧰 Contribute
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
- Star the repo if you like it
|
|
89
|
+
|
|
90
|
+
- Check the [contributing](https://github.com/Maggi64/moderndash/blob/main/CONTRIBUTING.md) section!
|
package/dist/index.cjs
CHANGED
|
@@ -77,6 +77,9 @@ __export(src_exports, {
|
|
|
77
77
|
times: () => times,
|
|
78
78
|
titleCase: () => titleCase,
|
|
79
79
|
toDecorator: () => toDecorator,
|
|
80
|
+
trim: () => trim,
|
|
81
|
+
trimEnd: () => trimEnd,
|
|
82
|
+
trimStart: () => trimStart,
|
|
80
83
|
tryCatch: () => tryCatch,
|
|
81
84
|
unescapeHtml: () => unescapeHtml,
|
|
82
85
|
unique: () => unique
|
|
@@ -731,12 +734,25 @@ async function tryCatch(promise) {
|
|
|
731
734
|
}
|
|
732
735
|
|
|
733
736
|
// src/string/splitWords.ts
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
)
|
|
738
|
-
|
|
739
|
-
|
|
737
|
+
function splitWords(str, forceFallback = false) {
|
|
738
|
+
return lookbehindWordBoundary && !forceFallback ? str.split(lookbehindWordBoundary).filter(Boolean) : splitWordsFallback(str);
|
|
739
|
+
}
|
|
740
|
+
var wordBoundaryFallback = /[^\dA-Za-z]|(?=[A-Z][a-z])/;
|
|
741
|
+
var lookbehindReplacement = /([a-z])([A-Z])/g;
|
|
742
|
+
var lookbehindWordBoundary = tryLookbehindRegex();
|
|
743
|
+
function tryLookbehindRegex() {
|
|
744
|
+
try {
|
|
745
|
+
return new RegExp(
|
|
746
|
+
"[^\\dA-Za-z]|(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])"
|
|
747
|
+
// lookahead for an uppercase letter followed by a lowercase letter
|
|
748
|
+
);
|
|
749
|
+
} catch {
|
|
750
|
+
return void 0;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
function splitWordsFallback(str) {
|
|
754
|
+
const modifiedStr = str.replace(lookbehindReplacement, (match, p1, p2) => p1 + "\0" + p2);
|
|
755
|
+
return modifiedStr.split(wordBoundaryFallback).filter(Boolean).map((word) => word.replace(/\u0000/g, ""));
|
|
740
756
|
}
|
|
741
757
|
|
|
742
758
|
// src/string/deburr.ts
|
|
@@ -827,6 +843,37 @@ function titleCase(str) {
|
|
|
827
843
|
return titleCase2.trimEnd();
|
|
828
844
|
}
|
|
829
845
|
|
|
846
|
+
// src/string/trim.ts
|
|
847
|
+
function trim(str, chars) {
|
|
848
|
+
let startIndex = 0;
|
|
849
|
+
while (startIndex < str.length && chars.includes(str[startIndex])) {
|
|
850
|
+
startIndex++;
|
|
851
|
+
}
|
|
852
|
+
let endIndex = str.length - 1;
|
|
853
|
+
while (endIndex >= startIndex && chars.includes(str[endIndex])) {
|
|
854
|
+
endIndex--;
|
|
855
|
+
}
|
|
856
|
+
return str.slice(startIndex, endIndex + 1);
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
// src/string/trimEnd.ts
|
|
860
|
+
function trimEnd(str, chars) {
|
|
861
|
+
let lastIndex = str.length - 1;
|
|
862
|
+
while (lastIndex >= 0 && chars.includes(str[lastIndex])) {
|
|
863
|
+
lastIndex--;
|
|
864
|
+
}
|
|
865
|
+
return str.slice(0, lastIndex + 1);
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
// src/string/trimStart.ts
|
|
869
|
+
function trimStart(str, chars) {
|
|
870
|
+
let startIndex = 0;
|
|
871
|
+
while (startIndex < str.length && chars.includes(str[startIndex])) {
|
|
872
|
+
startIndex++;
|
|
873
|
+
}
|
|
874
|
+
return str.slice(startIndex);
|
|
875
|
+
}
|
|
876
|
+
|
|
830
877
|
// src/string/unescapeHtml.ts
|
|
831
878
|
var htmlEntitiesRegex = /&(?:amp|lt|gt|quot|#39);/g;
|
|
832
879
|
var entityMap = /* @__PURE__ */ new Map([
|
|
@@ -842,18 +889,16 @@ function unescapeHtml(str) {
|
|
|
842
889
|
|
|
843
890
|
// src/validate/isEmpty.ts
|
|
844
891
|
function isEmpty(value) {
|
|
845
|
-
if (value === null || value === void 0)
|
|
892
|
+
if (value === null || value === void 0)
|
|
846
893
|
return true;
|
|
847
|
-
|
|
848
|
-
if (typeof value === "string" || Array.isArray(value)) {
|
|
894
|
+
if (typeof value === "string" || Array.isArray(value))
|
|
849
895
|
return value.length === 0;
|
|
850
|
-
|
|
851
|
-
if (value instanceof Map || value instanceof Set) {
|
|
896
|
+
if (value instanceof Map || value instanceof Set)
|
|
852
897
|
return value.size === 0;
|
|
853
|
-
|
|
854
|
-
|
|
898
|
+
if (ArrayBuffer.isView(value))
|
|
899
|
+
return value.byteLength === 0;
|
|
900
|
+
if (typeof value === "object")
|
|
855
901
|
return Object.keys(value).length === 0;
|
|
856
|
-
}
|
|
857
902
|
return false;
|
|
858
903
|
}
|
|
859
904
|
|
|
@@ -863,17 +908,22 @@ function isEqual(a, b) {
|
|
|
863
908
|
return true;
|
|
864
909
|
if (typeof a !== typeof b)
|
|
865
910
|
return false;
|
|
866
|
-
if (Array.isArray(a) && Array.isArray(b))
|
|
911
|
+
if (Array.isArray(a) && Array.isArray(b))
|
|
867
912
|
return isSameArray(a, b);
|
|
868
|
-
|
|
869
|
-
if (a instanceof Date && b instanceof Date) {
|
|
913
|
+
if (a instanceof Date && b instanceof Date)
|
|
870
914
|
return a.getTime() === b.getTime();
|
|
871
|
-
|
|
872
|
-
if (a instanceof RegExp && b instanceof RegExp) {
|
|
915
|
+
if (a instanceof RegExp && b instanceof RegExp)
|
|
873
916
|
return a.toString() === b.toString();
|
|
874
|
-
|
|
875
|
-
if (isPlainObject(a) && isPlainObject(b)) {
|
|
917
|
+
if (isPlainObject(a) && isPlainObject(b))
|
|
876
918
|
return isSameObject(a, b);
|
|
919
|
+
if (a instanceof ArrayBuffer && b instanceof ArrayBuffer)
|
|
920
|
+
return dataViewsAreEqual(new DataView(a), new DataView(b));
|
|
921
|
+
if (a instanceof DataView && b instanceof DataView)
|
|
922
|
+
return dataViewsAreEqual(a, b);
|
|
923
|
+
if (isTypedArray(a) && isTypedArray(b)) {
|
|
924
|
+
if (a.byteLength !== b.byteLength)
|
|
925
|
+
return false;
|
|
926
|
+
return isSameArray(a, b);
|
|
877
927
|
}
|
|
878
928
|
return false;
|
|
879
929
|
}
|
|
@@ -891,12 +941,20 @@ function isSameObject(a, b) {
|
|
|
891
941
|
function isSameArray(a, b) {
|
|
892
942
|
if (a.length !== b.length)
|
|
893
943
|
return false;
|
|
894
|
-
|
|
895
|
-
|
|
944
|
+
return a.every((element, index) => isEqual(element, b[index]));
|
|
945
|
+
}
|
|
946
|
+
function dataViewsAreEqual(a, b) {
|
|
947
|
+
if (a.byteLength !== b.byteLength)
|
|
948
|
+
return false;
|
|
949
|
+
for (let offset = 0; offset < a.byteLength; offset++) {
|
|
950
|
+
if (a.getUint8(offset) !== b.getUint8(offset))
|
|
896
951
|
return false;
|
|
897
952
|
}
|
|
898
953
|
return true;
|
|
899
954
|
}
|
|
955
|
+
function isTypedArray(value) {
|
|
956
|
+
return ArrayBuffer.isView(value) && !(value instanceof DataView);
|
|
957
|
+
}
|
|
900
958
|
|
|
901
959
|
// src/validate/isUrl.ts
|
|
902
960
|
function isUrl(str) {
|
|
@@ -966,6 +1024,9 @@ function isUrl(str) {
|
|
|
966
1024
|
times,
|
|
967
1025
|
titleCase,
|
|
968
1026
|
toDecorator,
|
|
1027
|
+
trim,
|
|
1028
|
+
trimEnd,
|
|
1029
|
+
trimStart,
|
|
969
1030
|
tryCatch,
|
|
970
1031
|
unescapeHtml,
|
|
971
1032
|
unique
|