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.js CHANGED
@@ -680,6 +680,13 @@ function splitWords(str) {
680
680
  return str.match(wordsRegex) ?? [];
681
681
  }
682
682
 
683
+ // src/string/capitalize.ts
684
+ function capitalize(str) {
685
+ if (str === "")
686
+ return "";
687
+ return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
688
+ }
689
+
683
690
  // src/string/deburr.ts
684
691
  var accentControlRegex = /[\u0300-\u036F]/g;
685
692
  function deburr(str) {
@@ -688,20 +695,20 @@ function deburr(str) {
688
695
 
689
696
  // src/string/camelCase.ts
690
697
  function camelCase(str) {
698
+ if (str === "")
699
+ return "";
691
700
  str = deburr(str);
692
701
  const words = splitWords(str);
693
- let camelCase2 = "";
694
- for (const [index, word] of words.entries()) {
695
- camelCase2 += index === 0 ? word.toLowerCase() : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
702
+ if (words.length === 0)
703
+ return "";
704
+ let camelCase2 = words[0].toLowerCase();
705
+ for (let index = 1; index < words.length; index++) {
706
+ const word = words[index];
707
+ camelCase2 += capitalize(word);
696
708
  }
697
709
  return camelCase2;
698
710
  }
699
711
 
700
- // src/string/capitalize.ts
701
- function capitalize(str) {
702
- return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
703
- }
704
-
705
712
  // src/string/escapeHtml.ts
706
713
  var charRegex = /["&'<>]/g;
707
714
  var escapeChars = /* @__PURE__ */ new Map([
@@ -723,6 +730,8 @@ function escapeRegExp(str) {
723
730
 
724
731
  // src/string/kebabCase.ts
725
732
  function kebabCase(str) {
733
+ if (str === "")
734
+ return "";
726
735
  str = deburr(str);
727
736
  const words = splitWords(str);
728
737
  let kebabCase2 = "";
@@ -734,11 +743,13 @@ function kebabCase(str) {
734
743
 
735
744
  // src/string/pascalCase.ts
736
745
  function pascalCase(str) {
746
+ if (str === "")
747
+ return "";
737
748
  str = deburr(str);
738
749
  const words = splitWords(str);
739
750
  let pascalCase2 = "";
740
751
  for (const word of words) {
741
- pascalCase2 += word.charAt(0).toUpperCase() + word.slice(1);
752
+ pascalCase2 += capitalize(word);
742
753
  }
743
754
  return pascalCase2;
744
755
  }
@@ -753,6 +764,8 @@ function replaceLast(str, searchFor, replaceWith) {
753
764
 
754
765
  // src/string/snakeCase.ts
755
766
  function snakeCase(str) {
767
+ if (str === "")
768
+ return "";
756
769
  str = deburr(str);
757
770
  const words = splitWords(str);
758
771
  let snakeCase2 = "";
@@ -767,11 +780,13 @@ function snakeCase(str) {
767
780
 
768
781
  // src/string/titleCase.ts
769
782
  function titleCase(str) {
783
+ if (str === "")
784
+ return "";
770
785
  str = deburr(str);
771
786
  const words = splitWords(str);
772
787
  let titleCase2 = "";
773
788
  for (const word of words) {
774
- titleCase2 += word.charAt(0).toUpperCase() + word.slice(1).toLowerCase() + " ";
789
+ titleCase2 += capitalize(word) + " ";
775
790
  }
776
791
  return titleCase2.trimEnd();
777
792
  }
@@ -820,6 +835,24 @@ function unescapeHtml(str) {
820
835
  return str.replace(htmlEntitiesRegex, (entity) => entityMap.get(entity));
821
836
  }
822
837
 
838
+ // src/string/truncate.ts
839
+ function truncate(str, options) {
840
+ const { length = 30, ellipsis = "...", separator } = options ?? {};
841
+ if (str.length <= length)
842
+ return str;
843
+ const end = length - ellipsis.length;
844
+ if (end < 1)
845
+ return ellipsis;
846
+ let truncated = str.slice(0, end);
847
+ if (separator) {
848
+ const sepIndex = truncated.lastIndexOf(separator);
849
+ if (sepIndex > -1) {
850
+ truncated = truncated.slice(0, sepIndex);
851
+ }
852
+ }
853
+ return truncated + ellipsis;
854
+ }
855
+
823
856
  // src/validate/isEmpty.ts
824
857
  function isEmpty(value) {
825
858
  if (value === null || value === void 0)
@@ -961,6 +994,7 @@ export {
961
994
  trim,
962
995
  trimEnd,
963
996
  trimStart,
997
+ truncate,
964
998
  tryCatch,
965
999
  unescapeHtml,
966
1000
  unique