caseparser 4.3.0 → 5.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/dist/index.js CHANGED
@@ -257,7 +257,7 @@ function converter(input, type) {
257
257
  * camelToDash({ firstName: 'John' }); // { 'first-name': 'John' }
258
258
  * ```
259
259
  *
260
- * @deprecated Use `toDash` instead, which converts from any case. It keeps acronyms together,
260
+ * @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
261
261
  * so results differ for keys like `userID` (see the migration notes in the README).
262
262
  */
263
263
  function camelToDash(input) {
@@ -317,7 +317,7 @@ function camelToUpperSnake(input) {
317
317
  * camelToUpperDash({ firstName: 'John' }); // { 'FIRST-NAME': 'John' }
318
318
  * ```
319
319
  *
320
- * @deprecated Use `toUpperDash` instead, which converts from any case. It keeps acronyms together,
320
+ * @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
321
321
  * so results differ for keys like `userID` (see the migration notes in the README).
322
322
  */
323
323
  function camelToUpperDash(input) {
@@ -454,7 +454,7 @@ function dashToUpperSnake(input) {
454
454
  * dashToUpperDash({ 'first-name': 'John' }); // { 'FIRST-NAME': 'John' }
455
455
  * ```
456
456
  *
457
- * @deprecated Use `toUpperDash` instead, which converts from any case. It keeps acronyms together,
457
+ * @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
458
458
  * so results differ for keys like `userID` (see the migration notes in the README).
459
459
  */
460
460
  function dashToUpperDash(input) {
@@ -561,7 +561,7 @@ function pascalToSnake(input) {
561
561
  * pascalToDash({ FirstName: 'John' }); // { 'first-name': 'John' }
562
562
  * ```
563
563
  *
564
- * @deprecated Use `toDash` instead, which converts from any case. It keeps acronyms together,
564
+ * @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
565
565
  * so results differ for keys like `userID` (see the migration notes in the README).
566
566
  */
567
567
  function pascalToDash(input) {
@@ -591,7 +591,7 @@ function pascalToUpperSnake(input) {
591
591
  * pascalToUpperDash({ FirstName: 'John' }); // { 'FIRST-NAME': 'John' }
592
592
  * ```
593
593
  *
594
- * @deprecated Use `toUpperDash` instead, which converts from any case. It keeps acronyms together,
594
+ * @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
595
595
  * so results differ for keys like `userID` (see the migration notes in the README).
596
596
  */
597
597
  function pascalToUpperDash(input) {
@@ -683,7 +683,7 @@ function snakeToCamel(input) {
683
683
  * snakeToDash({ first_name: 'John' }); // { 'first-name': 'John' }
684
684
  * ```
685
685
  *
686
- * @deprecated Use `toDash` instead, which converts from any case. It keeps acronyms together,
686
+ * @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
687
687
  * so results differ for keys like `userID` (see the migration notes in the README).
688
688
  */
689
689
  function snakeToDash(input) {
@@ -728,7 +728,7 @@ function snakeToUpperSnake(input) {
728
728
  * snakeToUpperDash({ first_name: 'John' }); // { 'FIRST-NAME': 'John' }
729
729
  * ```
730
730
  *
731
- * @deprecated Use `toUpperDash` instead, which converts from any case. It keeps acronyms together,
731
+ * @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
732
732
  * so results differ for keys like `userID` (see the migration notes in the README).
733
733
  */
734
734
  function snakeToUpperDash(input) {
@@ -850,7 +850,7 @@ function trainToSnake(input) {
850
850
  * trainToDash({ 'First-Name': 'John' }); // { 'first-name': 'John' }
851
851
  * ```
852
852
  *
853
- * @deprecated Use `toDash` instead, which converts from any case. It keeps acronyms together,
853
+ * @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
854
854
  * so results differ for keys like `userID` (see the migration notes in the README).
855
855
  */
856
856
  function trainToDash(input) {
@@ -880,7 +880,7 @@ function trainToUpperSnake(input) {
880
880
  * trainToUpperDash({ 'First-Name': 'John' }); // { 'FIRST-NAME': 'John' }
881
881
  * ```
882
882
  *
883
- * @deprecated Use `toUpperDash` instead, which converts from any case. It keeps acronyms together,
883
+ * @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
884
884
  * so results differ for keys like `userID` (see the migration notes in the README).
885
885
  */
886
886
  function trainToUpperDash(input) {
@@ -987,7 +987,7 @@ function dotToSnake(input) {
987
987
  * dotToDash({ 'first.name': 'John' }); // { 'first-name': 'John' }
988
988
  * ```
989
989
  *
990
- * @deprecated Use `toDash` instead, which converts from any case. It keeps acronyms together,
990
+ * @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
991
991
  * so results differ for keys like `userID` (see the migration notes in the README).
992
992
  */
993
993
  function dotToDash(input) {
@@ -1017,7 +1017,7 @@ function dotToUpperSnake(input) {
1017
1017
  * dotToUpperDash({ 'first.name': 'John' }); // { 'FIRST-NAME': 'John' }
1018
1018
  * ```
1019
1019
  *
1020
- * @deprecated Use `toUpperDash` instead, which converts from any case. It keeps acronyms together,
1020
+ * @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
1021
1021
  * so results differ for keys like `userID` (see the migration notes in the README).
1022
1022
  */
1023
1023
  function dotToUpperDash(input) {
@@ -1124,7 +1124,7 @@ function titleToSnake(input) {
1124
1124
  * titleToDash({ 'First Name': 'John' }); // { 'first-name': 'John' }
1125
1125
  * ```
1126
1126
  *
1127
- * @deprecated Use `toDash` instead, which converts from any case. It keeps acronyms together,
1127
+ * @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
1128
1128
  * so results differ for keys like `userID` (see the migration notes in the README).
1129
1129
  */
1130
1130
  function titleToDash(input) {
@@ -1154,7 +1154,7 @@ function titleToUpperSnake(input) {
1154
1154
  * titleToUpperDash({ 'First Name': 'John' }); // { 'FIRST-NAME': 'John' }
1155
1155
  * ```
1156
1156
  *
1157
- * @deprecated Use `toUpperDash` instead, which converts from any case. It keeps acronyms together,
1157
+ * @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
1158
1158
  * so results differ for keys like `userID` (see the migration notes in the README).
1159
1159
  */
1160
1160
  function titleToUpperDash(input) {
@@ -1261,7 +1261,7 @@ function sentenceToSnake(input) {
1261
1261
  * sentenceToDash({ 'First name': 'John' }); // { 'first-name': 'John' }
1262
1262
  * ```
1263
1263
  *
1264
- * @deprecated Use `toDash` instead, which converts from any case. It keeps acronyms together,
1264
+ * @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
1265
1265
  * so results differ for keys like `userID` (see the migration notes in the README).
1266
1266
  */
1267
1267
  function sentenceToDash(input) {
@@ -1291,7 +1291,7 @@ function sentenceToUpperSnake(input) {
1291
1291
  * sentenceToUpperDash({ 'First name': 'John' }); // { 'FIRST-NAME': 'John' }
1292
1292
  * ```
1293
1293
  *
1294
- * @deprecated Use `toUpperDash` instead, which converts from any case. It keeps acronyms together,
1294
+ * @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
1295
1295
  * so results differ for keys like `userID` (see the migration notes in the README).
1296
1296
  */
1297
1297
  function sentenceToUpperDash(input) {
@@ -1383,7 +1383,7 @@ function upperDashToSnake(input) {
1383
1383
  * upperDashToDash({ 'FIRST-NAME': 'John' }); // { 'first-name': 'John' }
1384
1384
  * ```
1385
1385
  *
1386
- * @deprecated Use `toDash` instead, which converts from any case. It keeps acronyms together,
1386
+ * @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
1387
1387
  * so results differ for keys like `userID` (see the migration notes in the README).
1388
1388
  */
1389
1389
  function upperDashToDash(input) {
@@ -1520,7 +1520,7 @@ function upperSnakeToSnake(input) {
1520
1520
  * upperSnakeToDash({ FIRST_NAME: 'John' }); // { 'first-name': 'John' }
1521
1521
  * ```
1522
1522
  *
1523
- * @deprecated Use `toDash` instead, which converts from any case. It keeps acronyms together,
1523
+ * @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
1524
1524
  * so results differ for keys like `userID` (see the migration notes in the README).
1525
1525
  */
1526
1526
  function upperSnakeToDash(input) {
@@ -1550,7 +1550,7 @@ function upperSnakeToPascal(input) {
1550
1550
  * upperSnakeToUpperDash({ FIRST_NAME: 'John' }); // { 'FIRST-NAME': 'John' }
1551
1551
  * ```
1552
1552
  *
1553
- * @deprecated Use `toUpperDash` instead, which converts from any case. It keeps acronyms together,
1553
+ * @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
1554
1554
  * so results differ for keys like `userID` (see the migration notes in the README).
1555
1555
  */
1556
1556
  function upperSnakeToUpperDash(input) {
@@ -1618,20 +1618,28 @@ function upperSnakeToSentence(input) {
1618
1618
  }
1619
1619
  //#endregion
1620
1620
  //#region src/anyCase/words.ts
1621
+ const SYMBOLS = "!\"#$%&'()*+,/:;<=>?@[\\]^`{|}~";
1621
1622
  const isSeparator = (c) => c === "_" || c === "-" || c === "." || c === " ";
1623
+ const isSymbol = (c) => SYMBOLS.indexOf(c) !== -1;
1622
1624
  const isUpper = (c) => c !== c.toLowerCase();
1623
1625
  const isLower = (c) => c !== c.toUpperCase();
1626
+ const isKept = (c, keep) => keep === true || typeof keep !== "boolean" && keep !== void 0 && keep !== null && keep.indexOf(c) !== -1;
1624
1627
  /**
1625
1628
  * Splits a string in any case into lowercase words: on `_`, `-`, `.` and spaces,
1626
1629
  * before an uppercase letter that follows a lowercase letter or a digit (`helloWorld`),
1627
1630
  * and before the last letter of an acronym (`XMLHttp`). Mirrors the `Words` type.
1631
+ *
1632
+ * Symbols (ASCII punctuation) also start a new word. They are removed, unless `keep` is
1633
+ * `true` or lists them: a kept symbol sticks to the start of the next word (`hello$World`
1634
+ * → `hello`, `$world`), or to the end of the previous one when no word follows (`total%`).
1635
+ * Words keep their original case when `lowercase` is `false`.
1628
1636
  */
1629
- function words(str) {
1637
+ function words(str, keep = false, lowercase = true) {
1630
1638
  const result = [];
1631
1639
  let word = "";
1632
1640
  let prev = "";
1633
1641
  const push = () => {
1634
- if (word) result.push(word.toLowerCase());
1642
+ if (word) result.push(lowercase ? word.toLowerCase() : word);
1635
1643
  word = "";
1636
1644
  };
1637
1645
  for (let i = 0; i < str.length; i++) {
@@ -1641,24 +1649,48 @@ function words(str) {
1641
1649
  prev = "";
1642
1650
  continue;
1643
1651
  }
1652
+ if (isSymbol(c)) {
1653
+ let kept = "";
1654
+ let j = i;
1655
+ for (; j < str.length && isSymbol(str[j]); j++) if (isKept(str[j], keep)) kept += str[j];
1656
+ const next = str.charAt(j);
1657
+ if (next && !isSeparator(next)) {
1658
+ push();
1659
+ prev = "";
1660
+ }
1661
+ word += kept;
1662
+ i = j - 1;
1663
+ continue;
1664
+ }
1644
1665
  const next = str.charAt(i + 1);
1645
- if (isUpper(c) && word && (!isUpper(prev) || next && isLower(next))) push();
1666
+ if (isUpper(c) && prev && (!isUpper(prev) || next && isLower(next))) push();
1646
1667
  word += c;
1647
1668
  prev = c;
1648
1669
  }
1649
1670
  push();
1650
1671
  return result;
1651
1672
  }
1652
- const ToCamel = (str) => words(str).map((w, i) => i ? Capitalize(w) : w).join("");
1653
- const ToPascal = (str) => words(str).map(Capitalize).join("");
1654
- const ToSnake = (str) => words(str).join("_");
1655
- const ToDash = (str) => words(str).join("-");
1656
- const ToUpperSnake = (str) => words(str).join("_").toUpperCase();
1657
- const ToUpperDash = (str) => words(str).join("-").toUpperCase();
1658
- const ToTrain = (str) => words(str).map(Capitalize).join("-");
1659
- const ToDot = (str) => words(str).join(".");
1660
- const ToTitle = (str) => words(str).map(Capitalize).join(" ");
1661
- const ToSentence = (str) => Capitalize(words(str).join(" "));
1673
+ /** Uppercases the first character that is not a symbol: `'$id'` → `'$Id'`. */
1674
+ function capitalize(word) {
1675
+ let i = 0;
1676
+ while (i < word.length && isSymbol(word[i])) i++;
1677
+ return word.slice(0, i) + word.charAt(i).toUpperCase() + word.slice(i + 1);
1678
+ }
1679
+ const ToCamel = (str, keep) => words(str, keep).map((w, i) => i ? capitalize(w) : w).join("");
1680
+ const ToPascal = (str, keep) => words(str, keep).map(capitalize).join("");
1681
+ const ToSnake = (str, keep) => words(str, keep).join("_");
1682
+ const ToKebab = (str, keep) => words(str, keep).join("-");
1683
+ const ToUpperSnake = (str, keep) => words(str, keep).join("_").toUpperCase();
1684
+ const ToUpperKebab = (str, keep) => words(str, keep).join("-").toUpperCase();
1685
+ const ToTrain = (str, keep) => words(str, keep).map(capitalize).join("-");
1686
+ const ToDot = (str, keep) => words(str, keep, false).join(".");
1687
+ const ToTitle = (str, keep) => words(str, keep).map(capitalize).join(" ");
1688
+ const ToSentence = (str, keep) => capitalize(words(str, keep).join(" "));
1689
+ const ToPascalSnake = (str, keep) => words(str, keep).map(capitalize).join("_");
1690
+ const ToPath = (str, keep) => words(str, keep, false).join("/");
1691
+ const ToSpace = (str, keep) => words(str, keep, false).join(" ");
1692
+ const ToLower = (str, keep) => words(str, keep).join(" ");
1693
+ const ToUpper = (str, keep) => words(str, keep).join(" ").toUpperCase();
1662
1694
  //#endregion
1663
1695
  //#region src/anyCase/anyCase.ts
1664
1696
  /**
@@ -1668,10 +1700,14 @@ const ToSentence = (str) => Capitalize(words(str).join(" "));
1668
1700
  * ```ts
1669
1701
  * toCamel('hello_world'); // 'helloWorld'
1670
1702
  * toCamel({ first_name: 'John', userID: 1 }); // { firstName: 'John', userId: 1 }
1703
+ * toCamel('$hello-world', true); // '$helloWorld'
1671
1704
  * ```
1705
+ *
1706
+ * @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
1707
+ * Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
1672
1708
  */
1673
- function toCamel(input) {
1674
- return convert(input, ToCamel);
1709
+ function toCamel(input, keepSymbols) {
1710
+ return convert(input, (key) => ToCamel(key, keepSymbols));
1675
1711
  }
1676
1712
  /**
1677
1713
  * Converts a string, or the keys of an object/array (deeply), from any case to PascalCase.
@@ -1680,10 +1716,14 @@ function toCamel(input) {
1680
1716
  * ```ts
1681
1717
  * toPascal('hello-world'); // 'HelloWorld'
1682
1718
  * toPascal({ 'first-name': 'John', userID: 1 }); // { FirstName: 'John', UserId: 1 }
1719
+ * toPascal('$hello-world', true); // '$HelloWorld'
1683
1720
  * ```
1721
+ *
1722
+ * @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
1723
+ * Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
1684
1724
  */
1685
- function toPascal(input) {
1686
- return convert(input, ToPascal);
1725
+ function toPascal(input, keepSymbols) {
1726
+ return convert(input, (key) => ToPascal(key, keepSymbols));
1687
1727
  }
1688
1728
  /**
1689
1729
  * Converts a string, or the keys of an object/array (deeply), from any case to snake_case.
@@ -1692,22 +1732,30 @@ function toPascal(input) {
1692
1732
  * ```ts
1693
1733
  * toSnake('helloWorld'); // 'hello_world'
1694
1734
  * toSnake({ firstName: 'John', userID: 1 }); // { first_name: 'John', user_id: 1 }
1735
+ * toSnake('$hello-world', true); // '$hello_world'
1695
1736
  * ```
1737
+ *
1738
+ * @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
1739
+ * Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
1696
1740
  */
1697
- function toSnake(input) {
1698
- return convert(input, ToSnake);
1741
+ function toSnake(input, keepSymbols) {
1742
+ return convert(input, (key) => ToSnake(key, keepSymbols));
1699
1743
  }
1700
1744
  /**
1701
- * Converts a string, or the keys of an object/array (deeply), from any case to dash-case.
1745
+ * Converts a string, or the keys of an object/array (deeply), from any case to kebab-case.
1702
1746
  *
1703
1747
  * @example
1704
1748
  * ```ts
1705
- * toDash('HELLO_WORLD'); // 'hello-world'
1706
- * toDash({ FIRST_NAME: 'John', userID: 1 }); // { 'first-name': 'John', 'user-id': 1 }
1749
+ * toKebab('HELLO_WORLD'); // 'hello-world'
1750
+ * toKebab({ FIRST_NAME: 'John', userID: 1 }); // { 'first-name': 'John', 'user-id': 1 }
1751
+ * toKebab('$hello-world', true); // '$hello-world'
1707
1752
  * ```
1753
+ *
1754
+ * @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
1755
+ * Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
1708
1756
  */
1709
- function toDash(input) {
1710
- return convert(input, ToDash);
1757
+ function toKebab(input, keepSymbols) {
1758
+ return convert(input, (key) => ToKebab(key, keepSymbols));
1711
1759
  }
1712
1760
  /**
1713
1761
  * Converts a string, or the keys of an object/array (deeply), from any case to UPPER_SNAKE_CASE.
@@ -1716,22 +1764,30 @@ function toDash(input) {
1716
1764
  * ```ts
1717
1765
  * toUpperSnake('hello-world'); // 'HELLO_WORLD'
1718
1766
  * toUpperSnake({ 'first-name': 'John', userID: 1 }); // { FIRST_NAME: 'John', USER_ID: 1 }
1767
+ * toUpperSnake('$hello-world', true); // '$HELLO_WORLD'
1719
1768
  * ```
1769
+ *
1770
+ * @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
1771
+ * Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
1720
1772
  */
1721
- function toUpperSnake(input) {
1722
- return convert(input, ToUpperSnake);
1773
+ function toUpperSnake(input, keepSymbols) {
1774
+ return convert(input, (key) => ToUpperSnake(key, keepSymbols));
1723
1775
  }
1724
1776
  /**
1725
- * Converts a string, or the keys of an object/array (deeply), from any case to UPPER-DASH-CASE.
1777
+ * Converts a string, or the keys of an object/array (deeply), from any case to UPPER-KEBAB-CASE.
1726
1778
  *
1727
1779
  * @example
1728
1780
  * ```ts
1729
- * toUpperDash('helloWorld'); // 'HELLO-WORLD'
1730
- * toUpperDash({ firstName: 'John', userID: 1 }); // { 'FIRST-NAME': 'John', 'USER-ID': 1 }
1781
+ * toUpperKebab('helloWorld'); // 'HELLO-WORLD'
1782
+ * toUpperKebab({ firstName: 'John', userID: 1 }); // { 'FIRST-NAME': 'John', 'USER-ID': 1 }
1783
+ * toUpperKebab('$hello-world', true); // '$HELLO-WORLD'
1731
1784
  * ```
1785
+ *
1786
+ * @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
1787
+ * Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
1732
1788
  */
1733
- function toUpperDash(input) {
1734
- return convert(input, ToUpperDash);
1789
+ function toUpperKebab(input, keepSymbols) {
1790
+ return convert(input, (key) => ToUpperKebab(key, keepSymbols));
1735
1791
  }
1736
1792
  /**
1737
1793
  * Converts a string, or the keys of an object/array (deeply), from any case to Train-Case.
@@ -1740,22 +1796,30 @@ function toUpperDash(input) {
1740
1796
  * ```ts
1741
1797
  * toTrain('hello_world'); // 'Hello-World'
1742
1798
  * toTrain({ first_name: 'John', userID: 1 }); // { 'First-Name': 'John', 'User-Id': 1 }
1799
+ * toTrain('$hello-world', true); // '$Hello-World'
1743
1800
  * ```
1801
+ *
1802
+ * @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
1803
+ * Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
1744
1804
  */
1745
- function toTrain(input) {
1746
- return convert(input, ToTrain);
1805
+ function toTrain(input, keepSymbols) {
1806
+ return convert(input, (key) => ToTrain(key, keepSymbols));
1747
1807
  }
1748
1808
  /**
1749
- * Converts a string, or the keys of an object/array (deeply), from any case to dot.case.
1809
+ * Converts a string, or the keys of an object/array (deeply), from any case to dot.case, keeping the original case of each word.
1750
1810
  *
1751
1811
  * @example
1752
1812
  * ```ts
1753
- * toDot('HelloWorld'); // 'hello.world'
1754
- * toDot({ FirstName: 'John', userID: 1 }); // { 'first.name': 'John', 'user.id': 1 }
1813
+ * toDot('HelloWorld'); // 'Hello.World'
1814
+ * toDot({ FirstName: 'John', userID: 1 }); // { 'First.Name': 'John', 'user.ID': 1 }
1815
+ * toDot('$hello-world', true); // '$hello.world'
1755
1816
  * ```
1817
+ *
1818
+ * @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
1819
+ * Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
1756
1820
  */
1757
- function toDot(input) {
1758
- return convert(input, ToDot);
1821
+ function toDot(input, keepSymbols) {
1822
+ return convert(input, (key) => ToDot(key, keepSymbols));
1759
1823
  }
1760
1824
  /**
1761
1825
  * Converts a string, or the keys of an object/array (deeply), from any case to Title Case.
@@ -1764,10 +1828,14 @@ function toDot(input) {
1764
1828
  * ```ts
1765
1829
  * toTitle('hello_world'); // 'Hello World'
1766
1830
  * toTitle({ first_name: 'John', userID: 1 }); // { 'First Name': 'John', 'User Id': 1 }
1831
+ * toTitle('$hello-world', true); // '$Hello World'
1767
1832
  * ```
1833
+ *
1834
+ * @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
1835
+ * Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
1768
1836
  */
1769
- function toTitle(input) {
1770
- return convert(input, ToTitle);
1837
+ function toTitle(input, keepSymbols) {
1838
+ return convert(input, (key) => ToTitle(key, keepSymbols));
1771
1839
  }
1772
1840
  /**
1773
1841
  * Converts a string, or the keys of an object/array (deeply), from any case to Sentence case.
@@ -1776,10 +1844,94 @@ function toTitle(input) {
1776
1844
  * ```ts
1777
1845
  * toSentence('helloWorld'); // 'Hello world'
1778
1846
  * toSentence({ firstName: 'John', userID: 1 }); // { 'First name': 'John', 'User id': 1 }
1847
+ * toSentence('$hello-world', true); // '$Hello world'
1779
1848
  * ```
1849
+ *
1850
+ * @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
1851
+ * Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
1852
+ */
1853
+ function toSentence(input, keepSymbols) {
1854
+ return convert(input, (key) => ToSentence(key, keepSymbols));
1855
+ }
1856
+ /**
1857
+ * Converts a string, or the keys of an object/array (deeply), from any case to Pascal_Snake_Case (also known as Ada_Case).
1858
+ *
1859
+ * @example
1860
+ * ```ts
1861
+ * toPascalSnake('helloWorld'); // 'Hello_World'
1862
+ * toPascalSnake({ first_name: 'John', userID: 1 }); // { First_Name: 'John', User_Id: 1 }
1863
+ * toPascalSnake('$hello-world', true); // '$Hello_World'
1864
+ * ```
1865
+ *
1866
+ * @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
1867
+ * Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
1868
+ */
1869
+ function toPascalSnake(input, keepSymbols) {
1870
+ return convert(input, (key) => ToPascalSnake(key, keepSymbols));
1871
+ }
1872
+ /**
1873
+ * Converts a string, or the keys of an object/array (deeply), from any case to path/case, keeping the original case of each word.
1874
+ *
1875
+ * @example
1876
+ * ```ts
1877
+ * toPath('helloWorld'); // 'hello/World'
1878
+ * toPath({ first_name: 'John', userID: 1 }); // { 'first/name': 'John', 'user/ID': 1 }
1879
+ * toPath('$hello-world', true); // '$hello/world'
1880
+ * ```
1881
+ *
1882
+ * @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
1883
+ * Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
1884
+ */
1885
+ function toPath(input, keepSymbols) {
1886
+ return convert(input, (key) => ToPath(key, keepSymbols));
1887
+ }
1888
+ /**
1889
+ * Converts a string, or the keys of an object/array (deeply), from any case to space case, keeping the original case of each word.
1890
+ *
1891
+ * @example
1892
+ * ```ts
1893
+ * toSpace('helloWorld'); // 'hello World'
1894
+ * toSpace({ first_name: 'John', userID: 1 }); // { 'first name': 'John', 'user ID': 1 }
1895
+ * toSpace('$hello-world', true); // '$hello world'
1896
+ * ```
1897
+ *
1898
+ * @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
1899
+ * Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
1900
+ */
1901
+ function toSpace(input, keepSymbols) {
1902
+ return convert(input, (key) => ToSpace(key, keepSymbols));
1903
+ }
1904
+ /**
1905
+ * Converts a string, or the keys of an object/array (deeply), from any case to lower case (space separated).
1906
+ *
1907
+ * @example
1908
+ * ```ts
1909
+ * toLower('helloWorld'); // 'hello world'
1910
+ * toLower({ first_name: 'John', userID: 1 }); // { 'first name': 'John', 'user id': 1 }
1911
+ * toLower('$hello-world', true); // '$hello world'
1912
+ * ```
1913
+ *
1914
+ * @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
1915
+ * Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
1916
+ */
1917
+ function toLower(input, keepSymbols) {
1918
+ return convert(input, (key) => ToLower(key, keepSymbols));
1919
+ }
1920
+ /**
1921
+ * Converts a string, or the keys of an object/array (deeply), from any case to UPPER CASE (space separated).
1922
+ *
1923
+ * @example
1924
+ * ```ts
1925
+ * toUpper('helloWorld'); // 'HELLO WORLD'
1926
+ * toUpper({ first_name: 'John', userID: 1 }); // { 'FIRST NAME': 'John', 'USER ID': 1 }
1927
+ * toUpper('$hello-world', true); // '$HELLO WORLD'
1928
+ * ```
1929
+ *
1930
+ * @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
1931
+ * Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
1780
1932
  */
1781
- function toSentence(input) {
1782
- return convert(input, ToSentence);
1933
+ function toUpper(input, keepSymbols) {
1934
+ return convert(input, (key) => ToUpper(key, keepSymbols));
1783
1935
  }
1784
1936
  //#endregion
1785
- export { camelToDash, camelToDot, camelToPascal, camelToSentence, camelToSnake, camelToTitle, camelToTrain, camelToUpperDash, camelToUpperSnake, dashToCamel, dashToDot, dashToPascal, dashToSentence, dashToSnake, dashToTitle, dashToTrain, dashToUpperDash, dashToUpperSnake, dotToCamel, dotToDash, dotToPascal, dotToSentence, dotToSnake, dotToTitle, dotToTrain, dotToUpperDash, dotToUpperSnake, pascalToCamel, pascalToDash, pascalToDot, pascalToSentence, pascalToSnake, pascalToTitle, pascalToTrain, pascalToUpperDash, pascalToUpperSnake, sentenceToCamel, sentenceToDash, sentenceToDot, sentenceToPascal, sentenceToSnake, sentenceToTitle, sentenceToTrain, sentenceToUpperDash, sentenceToUpperSnake, snakeToCamel, snakeToDash, snakeToDot, snakeToPascal, snakeToSentence, snakeToTitle, snakeToTrain, snakeToUpperDash, snakeToUpperSnake, titleToCamel, titleToDash, titleToDot, titleToPascal, titleToSentence, titleToSnake, titleToTrain, titleToUpperDash, titleToUpperSnake, toCamel, toDash, toDot, toPascal, toSentence, toSnake, toTitle, toTrain, toUpperDash, toUpperSnake, trainToCamel, trainToDash, trainToDot, trainToPascal, trainToSentence, trainToSnake, trainToTitle, trainToUpperDash, trainToUpperSnake, upperDashToCamel, upperDashToDash, upperDashToDot, upperDashToPascal, upperDashToSentence, upperDashToSnake, upperDashToTitle, upperDashToTrain, upperDashToUpperSnake, upperSnakeToCamel, upperSnakeToDash, upperSnakeToDot, upperSnakeToPascal, upperSnakeToSentence, upperSnakeToSnake, upperSnakeToTitle, upperSnakeToTrain, upperSnakeToUpperDash };
1937
+ export { camelToDash, camelToDot, camelToPascal, camelToSentence, camelToSnake, camelToTitle, camelToTrain, camelToUpperDash, camelToUpperSnake, dashToCamel, dashToDot, dashToPascal, dashToSentence, dashToSnake, dashToTitle, dashToTrain, dashToUpperDash, dashToUpperSnake, dotToCamel, dotToDash, dotToPascal, dotToSentence, dotToSnake, dotToTitle, dotToTrain, dotToUpperDash, dotToUpperSnake, pascalToCamel, pascalToDash, pascalToDot, pascalToSentence, pascalToSnake, pascalToTitle, pascalToTrain, pascalToUpperDash, pascalToUpperSnake, sentenceToCamel, sentenceToDash, sentenceToDot, sentenceToPascal, sentenceToSnake, sentenceToTitle, sentenceToTrain, sentenceToUpperDash, sentenceToUpperSnake, snakeToCamel, snakeToDash, snakeToDot, snakeToPascal, snakeToSentence, snakeToTitle, snakeToTrain, snakeToUpperDash, snakeToUpperSnake, titleToCamel, titleToDash, titleToDot, titleToPascal, titleToSentence, titleToSnake, titleToTrain, titleToUpperDash, titleToUpperSnake, toCamel, toDot, toKebab, toLower, toPascal, toPascalSnake, toPath, toSentence, toSnake, toSpace, toTitle, toTrain, toUpper, toUpperKebab, toUpperSnake, trainToCamel, trainToDash, trainToDot, trainToPascal, trainToSentence, trainToSnake, trainToTitle, trainToUpperDash, trainToUpperSnake, upperDashToCamel, upperDashToDash, upperDashToDot, upperDashToPascal, upperDashToSentence, upperDashToSnake, upperDashToTitle, upperDashToTrain, upperDashToUpperSnake, upperSnakeToCamel, upperSnakeToDash, upperSnakeToDot, upperSnakeToPascal, upperSnakeToSentence, upperSnakeToSnake, upperSnakeToTitle, upperSnakeToTrain, upperSnakeToUpperDash };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "caseparser",
3
- "version": "4.3.0",
3
+ "version": "5.0.0",
4
4
  "description": "Convert Strings/Arrays/Objects from a type of case to another one.",
5
5
  "author": "Fernando Machado Bernardino <fernandombernardino@gmail.com>",
6
6
  "homepage": "https://github.com/NandoMB/caseparser#readme",
@@ -68,6 +68,9 @@
68
68
  "camel case",
69
69
  "snake case",
70
70
  "dash case",
71
+ "kebab case",
72
+ "constant case",
73
+ "header case",
71
74
  "pascal case",
72
75
  "upper snake case",
73
76
  "upper dash case",
@@ -78,6 +81,7 @@
78
81
  "camelCase",
79
82
  "snake_case",
80
83
  "dash-case",
84
+ "kebab-case",
81
85
  "PascalCase",
82
86
  "UPPER_SNAKE_CASE",
83
87
  "UPPER-DASH-CASE",