moderndash 3.9.1 → 3.10.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/dist/index.cjs CHANGED
@@ -82,6 +82,7 @@ __export(src_exports, {
82
82
  trim: () => trim,
83
83
  trimEnd: () => trimEnd,
84
84
  trimStart: () => trimStart,
85
+ truncate: () => truncate,
85
86
  tryCatch: () => tryCatch,
86
87
  unescapeHtml: () => unescapeHtml,
87
88
  unique: () => unique
@@ -770,6 +771,13 @@ function splitWords(str) {
770
771
  return str.match(wordsRegex) ?? [];
771
772
  }
772
773
 
774
+ // src/string/capitalize.ts
775
+ function capitalize(str) {
776
+ if (str === "")
777
+ return "";
778
+ return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
779
+ }
780
+
773
781
  // src/string/deburr.ts
774
782
  var accentControlRegex = /[\u0300-\u036F]/g;
775
783
  function deburr(str) {
@@ -778,20 +786,20 @@ function deburr(str) {
778
786
 
779
787
  // src/string/camelCase.ts
780
788
  function camelCase(str) {
789
+ if (str === "")
790
+ return "";
781
791
  str = deburr(str);
782
792
  const words = splitWords(str);
783
- let camelCase2 = "";
784
- for (const [index, word] of words.entries()) {
785
- camelCase2 += index === 0 ? word.toLowerCase() : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
793
+ if (words.length === 0)
794
+ return "";
795
+ let camelCase2 = words[0].toLowerCase();
796
+ for (let index = 1; index < words.length; index++) {
797
+ const word = words[index];
798
+ camelCase2 += capitalize(word);
786
799
  }
787
800
  return camelCase2;
788
801
  }
789
802
 
790
- // src/string/capitalize.ts
791
- function capitalize(str) {
792
- return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
793
- }
794
-
795
803
  // src/string/escapeHtml.ts
796
804
  var charRegex = /["&'<>]/g;
797
805
  var escapeChars = /* @__PURE__ */ new Map([
@@ -813,6 +821,8 @@ function escapeRegExp(str) {
813
821
 
814
822
  // src/string/kebabCase.ts
815
823
  function kebabCase(str) {
824
+ if (str === "")
825
+ return "";
816
826
  str = deburr(str);
817
827
  const words = splitWords(str);
818
828
  let kebabCase2 = "";
@@ -824,11 +834,13 @@ function kebabCase(str) {
824
834
 
825
835
  // src/string/pascalCase.ts
826
836
  function pascalCase(str) {
837
+ if (str === "")
838
+ return "";
827
839
  str = deburr(str);
828
840
  const words = splitWords(str);
829
841
  let pascalCase2 = "";
830
842
  for (const word of words) {
831
- pascalCase2 += word.charAt(0).toUpperCase() + word.slice(1);
843
+ pascalCase2 += capitalize(word);
832
844
  }
833
845
  return pascalCase2;
834
846
  }
@@ -843,6 +855,8 @@ function replaceLast(str, searchFor, replaceWith) {
843
855
 
844
856
  // src/string/snakeCase.ts
845
857
  function snakeCase(str) {
858
+ if (str === "")
859
+ return "";
846
860
  str = deburr(str);
847
861
  const words = splitWords(str);
848
862
  let snakeCase2 = "";
@@ -857,11 +871,13 @@ function snakeCase(str) {
857
871
 
858
872
  // src/string/titleCase.ts
859
873
  function titleCase(str) {
874
+ if (str === "")
875
+ return "";
860
876
  str = deburr(str);
861
877
  const words = splitWords(str);
862
878
  let titleCase2 = "";
863
879
  for (const word of words) {
864
- titleCase2 += word.charAt(0).toUpperCase() + word.slice(1).toLowerCase() + " ";
880
+ titleCase2 += capitalize(word) + " ";
865
881
  }
866
882
  return titleCase2.trimEnd();
867
883
  }
@@ -910,6 +926,24 @@ function unescapeHtml(str) {
910
926
  return str.replace(htmlEntitiesRegex, (entity) => entityMap.get(entity));
911
927
  }
912
928
 
929
+ // src/string/truncate.ts
930
+ function truncate(str, options) {
931
+ const { length = 30, ellipsis = "...", separator } = options ?? {};
932
+ if (str.length <= length)
933
+ return str;
934
+ const end = length - ellipsis.length;
935
+ if (end < 1)
936
+ return ellipsis;
937
+ let truncated = str.slice(0, end);
938
+ if (separator) {
939
+ const sepIndex = truncated.lastIndexOf(separator);
940
+ if (sepIndex > -1) {
941
+ truncated = truncated.slice(0, sepIndex);
942
+ }
943
+ }
944
+ return truncated + ellipsis;
945
+ }
946
+
913
947
  // src/validate/isEmpty.ts
914
948
  function isEmpty(value) {
915
949
  if (value === null || value === void 0)
@@ -1052,6 +1086,7 @@ function isUrl(str) {
1052
1086
  trim,
1053
1087
  trimEnd,
1054
1088
  trimStart,
1089
+ truncate,
1055
1090
  tryCatch,
1056
1091
  unescapeHtml,
1057
1092
  unique