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/README.md CHANGED
@@ -43,7 +43,7 @@ npx jsr add @nandomb/caseparser
43
43
  | --- | --- |
44
44
  | ESM (`import`) | Node.js 12.22+, Deno, Bun, bundlers |
45
45
  | CommonJS (`require`) | Node.js 8+, Bun |
46
- | TypeScript | 4.1+ (any `moduleResolution`: `node`, `node16`/`nodenext`, `bundler`). The `toX` type inference needs 4.5+ for keys longer than ~20 characters |
46
+ | TypeScript | 4.5+ for the `toX` functions, 4.1+ for the deprecated `<from>To<To>` functions (any `moduleResolution`: `node`, `node16`/`nodenext`, `bundler`) |
47
47
  | Browsers | Any ES2015 browser (via bundler) |
48
48
  | Edge | Cloudflare Workers |
49
49
 
@@ -65,21 +65,36 @@ toSnake({ firstName: 'John', addresses: [{ postalCode: '61105' }] });
65
65
 
66
66
  Objects are converted deeply, including objects inside arrays. The input is never mutated: a new object is returned.
67
67
 
68
- There is one function per target case, and the input can be in any case (see [From any case](#from-any-case)):
68
+ There is one function per target case, and the input can be in any case (see [From any case](#from-any-case)). Converting `'helloWorld'`:
69
+
70
+ | Function | Result | Also known as |
71
+ | --- | --- | --- |
72
+ | `toCamel` | `helloWorld` | lowerCamelCase |
73
+ | `toPascal` | `HelloWorld` | UpperCamelCase |
74
+ | `toSnake` | `hello_world` | |
75
+ | `toKebab` | `hello-world` | dash-case, param-case |
76
+ | `toUpperSnake` | `HELLO_WORLD` | CONSTANT_CASE, SCREAMING_SNAKE_CASE |
77
+ | `toUpperKebab` | `HELLO-WORLD` | COBOL-CASE, SCREAMING-KEBAB-CASE |
78
+ | `toTrain` | `Hello-World` | Header-Case |
79
+ | `toDot` | `hello.World` | dot.notation |
80
+ | `toTitle` | `Hello World` | Capital Case |
81
+ | `toSentence` | `Hello world` | |
82
+ | `toPascalSnake` | `Hello_World` | Ada_Case, Title_Snake_Case |
83
+ | `toPath` | `hello/World` | |
84
+ | `toSpace` | `hello World` | |
85
+ | `toLower` | `hello world` | no case |
86
+ | `toUpper` | `HELLO WORLD` | |
87
+
88
+ `toSpace`, `toPath` and `toDot` keep the original case of each word (`toPath('UserProfile')` → `'User/Profile'`); all the others lowercase the words first. To change the case of a whole string, use `toLowerCase()` or `toUpperCase()` on the result:
69
89
 
70
90
  ```ts
71
- toCamel('helloWorld'); // 'helloWorld'
72
- toPascal('helloWorld'); // 'HelloWorld'
73
- toSnake('helloWorld'); // 'hello_world'
74
- toDash('helloWorld'); // 'hello-world'
75
- toUpperSnake('helloWorld'); // 'HELLO_WORLD'
76
- toUpperDash('helloWorld'); // 'HELLO-WORLD'
77
- toTrain('helloWorld'); // 'Hello-World'
78
- toDot('helloWorld'); // 'hello.world'
79
- toTitle('helloWorld'); // 'Hello World'
80
- toSentence('helloWorld'); // 'Hello world'
91
+ toPath('helloWorld'); // 'hello/World'
92
+ toPath('helloWorld').toLowerCase(); // 'hello/world'
93
+ toPath('helloWorld').toUpperCase(); // 'HELLO/WORLD'
81
94
  ```
82
95
 
96
+ Don't chain `toX` functions for this (`toUpper(toPath(...))`): each one splits its input into words again, so `/` and `.` would be treated as separators or symbols.
97
+
83
98
  ### Typical use: API responses
84
99
 
85
100
  ```ts
@@ -123,9 +138,33 @@ toCamel({ user_id: 1, 'Last-Name': 'Doe', XMLHttpRequest: true });
123
138
 
124
139
  Words are split on `_`, `-`, `.` and spaces, and before an uppercase letter that starts a new word.
125
140
 
141
+ ### Symbols
142
+
143
+ Symbols (ASCII punctuation such as `$`, `@`, `#` or `%`) are removed by default. Pass a second argument to keep them: `true` keeps all of them, and an array keeps only the listed ones:
144
+
145
+ ```ts
146
+ toCamel({ $ref: 1, '@type': 'user' }); // { ref: 1, type: 'user' }
147
+ toCamel({ $ref: 1, '@type': 'user' }, true); // { $ref: 1, '@type': 'user' }
148
+ toCamel({ $ref: 1, '@type': 'user' }, ['$']); // { $ref: 1, type: 'user' }
149
+
150
+ toCamel('$Hello-world', true); // '$helloWorld'
151
+ toPascal('$id', true); // '$Id'
152
+ ```
153
+
154
+ A symbol always starts a new word, so the words are the same whether symbols are kept or not. A kept symbol sticks to the start of the next word, or to the end of the previous one when no word follows:
155
+
156
+ ```ts
157
+ toSnake('$$hello$World$$hi'); // 'hello_world_hi'
158
+ toSnake('$$hello$World$$hi', true); // '$$hello_$world_$$hi'
159
+ toSnake('user@name', true); // 'user_@name'
160
+ toSnake('total%_count', true); // 'total%_count'
161
+ ```
162
+
163
+ The inferred types follow the same rules. `_`, `-` and `.` are separators, not symbols, so `_links` always becomes `links`.
164
+
126
165
  ## Conversion Types
127
166
 
128
- > **Deprecated:** the `<from>To<To>` functions below are deprecated in favor of the `toX` functions ([How to use](#how-to-use)) and will be removed in the next major version. They keep working until then. See [Migrating to `toX`](#migrating-to-tox).
167
+ > **Deprecated:** the `<from>To<To>` functions below are deprecated in favor of the `toX` functions ([How to use](#how-to-use)) and will be removed in the next major version, which will also require TypeScript 4.7+. They keep working until then. See [Migrating to `toX`](#migrating-to-tox).
129
168
 
130
169
  Every function is named `<from>To<To>`, e.g. `snakeToCamel`. The case names are:
131
170
 
@@ -157,9 +196,9 @@ All 90 functions:
157
196
 
158
197
  ## Migrating to `toX`
159
198
 
160
- Replace each `<from>To<To>` function with the `toX` function for its target case, whatever the source case: `camelToSnake`, `dashToSnake`, `titleToSnake`... all become `toSnake`.
199
+ Replace each `<from>To<To>` function with the `toX` function for its target case, whatever the source case: `camelToSnake`, `dashToSnake`, `titleToSnake`... all become `toSnake`. The dash cases were renamed: `<from>ToDash` becomes `toKebab`, and `<from>ToUpperDash` becomes `toUpperKebab`.
161
200
 
162
- For well-formed keys (`firstName`, `first_name`) the result is the same. It differs when a key has consecutive uppercase letters or doesn't match the source case:
201
+ For well-formed keys (`firstName`, `first_name`) the result is the same. It differs when a key has consecutive uppercase letters or doesn't match the source case, and `toDot` keeps the original case of each word:
163
202
 
164
203
  | Call | `<from>To<To>` result | `toX` result |
165
204
  | --- | --- | --- |
@@ -167,6 +206,7 @@ For well-formed keys (`firstName`, `first_name`) the result is the same. It diff
167
206
  | `camelToSnake('XMLHttpRequest')` / `toSnake('XMLHttpRequest')` | `'_x_m_l_http_request'` | `'xml_http_request'` |
168
207
  | `camelToSnake('HelloWorld')` / `toSnake('HelloWorld')` | `'_hello_world'` | `'hello_world'` |
169
208
  | `snakeToCamel('user_ID')` / `toCamel('user_ID')` | `'userID'` | `'userId'` |
209
+ | `camelToDot('helloWorld')` / `toDot('helloWorld')` | `'hello.world'` | `'hello.World'` |
170
210
 
171
211
  If your code reads keys like `user_i_d` produced by the old functions, update those reads when migrating. The inferred types follow the new results, so TypeScript points out every place to change.
172
212
 
@@ -175,10 +215,10 @@ If your code reads keys like `user_i_d` produced by the old functions, update th
175
215
  - **Only keys are converted, never values.** In `{ userName: 'johnDoe' }`, `userName` becomes `user_name` but `'johnDoe'` is kept. Strings inside arrays are kept too.
176
216
  - **Only plain objects are traversed.** `Date`, `Map`, `Set` and class instances are returned as they are (same reference), without converting their contents.
177
217
  - **Acronyms are kept together, but not restored:** `toSnake('userID')` → `'user_id'`, and back `toCamel('user_id')` → `'userId'`.
178
- - **Words are lowercased** before converting, so `toCamel('X-API-Key')` → `'xApiKey'` and `toCamel('First Name')` → `'firstName'`.
218
+ - **Words are lowercased** before converting (except by `toSpace`, `toPath` and `toDot`), so `toCamel('X-API-Key')` → `'xApiKey'` and `toCamel('First Name')` → `'firstName'`.
179
219
  - **Title Case capitalizes every word**, including short ones: `toTitle('termsOfUse')` → `'Terms Of Use'`.
180
220
  - **Digits stay attached to the previous word:** `toSnake('html5Parser')` → `'html5_parser'`, `toSnake('user1Name')` → `'user1_name'`.
181
- - **Type inference has a key length limit.** TypeScript limits how deeply a type can recurse, and keys are converted character by character at the type level. With TypeScript 4.5+, the `toX` functions infer keys up to ~120 characters; with TypeScript 4.1 to 4.4, only up to ~20 characters. Longer keys fail to compile with `Type instantiation is excessively deep and possibly infinite`. The runtime conversion has no limit.
221
+ - **Type inference has a key length limit.** TypeScript limits how deeply a type can recurse, and keys are converted character by character at the type level. The `toX` functions infer keys up to ~120 characters; longer keys fail to compile with `Type instantiation is excessively deep and possibly infinite`. The runtime conversion has no limit.
182
222
 
183
223
  ## Security
184
224
 
package/dist/index.cjs CHANGED
@@ -258,7 +258,7 @@ function converter(input, type) {
258
258
  * camelToDash({ firstName: 'John' }); // { 'first-name': 'John' }
259
259
  * ```
260
260
  *
261
- * @deprecated Use `toDash` instead, which converts from any case. It keeps acronyms together,
261
+ * @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
262
262
  * so results differ for keys like `userID` (see the migration notes in the README).
263
263
  */
264
264
  function camelToDash(input) {
@@ -318,7 +318,7 @@ function camelToUpperSnake(input) {
318
318
  * camelToUpperDash({ firstName: 'John' }); // { 'FIRST-NAME': 'John' }
319
319
  * ```
320
320
  *
321
- * @deprecated Use `toUpperDash` instead, which converts from any case. It keeps acronyms together,
321
+ * @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
322
322
  * so results differ for keys like `userID` (see the migration notes in the README).
323
323
  */
324
324
  function camelToUpperDash(input) {
@@ -455,7 +455,7 @@ function dashToUpperSnake(input) {
455
455
  * dashToUpperDash({ 'first-name': 'John' }); // { 'FIRST-NAME': 'John' }
456
456
  * ```
457
457
  *
458
- * @deprecated Use `toUpperDash` instead, which converts from any case. It keeps acronyms together,
458
+ * @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
459
459
  * so results differ for keys like `userID` (see the migration notes in the README).
460
460
  */
461
461
  function dashToUpperDash(input) {
@@ -562,7 +562,7 @@ function pascalToSnake(input) {
562
562
  * pascalToDash({ FirstName: 'John' }); // { 'first-name': 'John' }
563
563
  * ```
564
564
  *
565
- * @deprecated Use `toDash` instead, which converts from any case. It keeps acronyms together,
565
+ * @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
566
566
  * so results differ for keys like `userID` (see the migration notes in the README).
567
567
  */
568
568
  function pascalToDash(input) {
@@ -592,7 +592,7 @@ function pascalToUpperSnake(input) {
592
592
  * pascalToUpperDash({ FirstName: 'John' }); // { 'FIRST-NAME': 'John' }
593
593
  * ```
594
594
  *
595
- * @deprecated Use `toUpperDash` instead, which converts from any case. It keeps acronyms together,
595
+ * @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
596
596
  * so results differ for keys like `userID` (see the migration notes in the README).
597
597
  */
598
598
  function pascalToUpperDash(input) {
@@ -684,7 +684,7 @@ function snakeToCamel(input) {
684
684
  * snakeToDash({ first_name: 'John' }); // { 'first-name': 'John' }
685
685
  * ```
686
686
  *
687
- * @deprecated Use `toDash` instead, which converts from any case. It keeps acronyms together,
687
+ * @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
688
688
  * so results differ for keys like `userID` (see the migration notes in the README).
689
689
  */
690
690
  function snakeToDash(input) {
@@ -729,7 +729,7 @@ function snakeToUpperSnake(input) {
729
729
  * snakeToUpperDash({ first_name: 'John' }); // { 'FIRST-NAME': 'John' }
730
730
  * ```
731
731
  *
732
- * @deprecated Use `toUpperDash` instead, which converts from any case. It keeps acronyms together,
732
+ * @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
733
733
  * so results differ for keys like `userID` (see the migration notes in the README).
734
734
  */
735
735
  function snakeToUpperDash(input) {
@@ -851,7 +851,7 @@ function trainToSnake(input) {
851
851
  * trainToDash({ 'First-Name': 'John' }); // { 'first-name': 'John' }
852
852
  * ```
853
853
  *
854
- * @deprecated Use `toDash` instead, which converts from any case. It keeps acronyms together,
854
+ * @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
855
855
  * so results differ for keys like `userID` (see the migration notes in the README).
856
856
  */
857
857
  function trainToDash(input) {
@@ -881,7 +881,7 @@ function trainToUpperSnake(input) {
881
881
  * trainToUpperDash({ 'First-Name': 'John' }); // { 'FIRST-NAME': 'John' }
882
882
  * ```
883
883
  *
884
- * @deprecated Use `toUpperDash` instead, which converts from any case. It keeps acronyms together,
884
+ * @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
885
885
  * so results differ for keys like `userID` (see the migration notes in the README).
886
886
  */
887
887
  function trainToUpperDash(input) {
@@ -988,7 +988,7 @@ function dotToSnake(input) {
988
988
  * dotToDash({ 'first.name': 'John' }); // { 'first-name': 'John' }
989
989
  * ```
990
990
  *
991
- * @deprecated Use `toDash` instead, which converts from any case. It keeps acronyms together,
991
+ * @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
992
992
  * so results differ for keys like `userID` (see the migration notes in the README).
993
993
  */
994
994
  function dotToDash(input) {
@@ -1018,7 +1018,7 @@ function dotToUpperSnake(input) {
1018
1018
  * dotToUpperDash({ 'first.name': 'John' }); // { 'FIRST-NAME': 'John' }
1019
1019
  * ```
1020
1020
  *
1021
- * @deprecated Use `toUpperDash` instead, which converts from any case. It keeps acronyms together,
1021
+ * @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
1022
1022
  * so results differ for keys like `userID` (see the migration notes in the README).
1023
1023
  */
1024
1024
  function dotToUpperDash(input) {
@@ -1125,7 +1125,7 @@ function titleToSnake(input) {
1125
1125
  * titleToDash({ 'First Name': 'John' }); // { 'first-name': 'John' }
1126
1126
  * ```
1127
1127
  *
1128
- * @deprecated Use `toDash` instead, which converts from any case. It keeps acronyms together,
1128
+ * @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
1129
1129
  * so results differ for keys like `userID` (see the migration notes in the README).
1130
1130
  */
1131
1131
  function titleToDash(input) {
@@ -1155,7 +1155,7 @@ function titleToUpperSnake(input) {
1155
1155
  * titleToUpperDash({ 'First Name': 'John' }); // { 'FIRST-NAME': 'John' }
1156
1156
  * ```
1157
1157
  *
1158
- * @deprecated Use `toUpperDash` instead, which converts from any case. It keeps acronyms together,
1158
+ * @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
1159
1159
  * so results differ for keys like `userID` (see the migration notes in the README).
1160
1160
  */
1161
1161
  function titleToUpperDash(input) {
@@ -1262,7 +1262,7 @@ function sentenceToSnake(input) {
1262
1262
  * sentenceToDash({ 'First name': 'John' }); // { 'first-name': 'John' }
1263
1263
  * ```
1264
1264
  *
1265
- * @deprecated Use `toDash` instead, which converts from any case. It keeps acronyms together,
1265
+ * @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
1266
1266
  * so results differ for keys like `userID` (see the migration notes in the README).
1267
1267
  */
1268
1268
  function sentenceToDash(input) {
@@ -1292,7 +1292,7 @@ function sentenceToUpperSnake(input) {
1292
1292
  * sentenceToUpperDash({ 'First name': 'John' }); // { 'FIRST-NAME': 'John' }
1293
1293
  * ```
1294
1294
  *
1295
- * @deprecated Use `toUpperDash` instead, which converts from any case. It keeps acronyms together,
1295
+ * @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
1296
1296
  * so results differ for keys like `userID` (see the migration notes in the README).
1297
1297
  */
1298
1298
  function sentenceToUpperDash(input) {
@@ -1384,7 +1384,7 @@ function upperDashToSnake(input) {
1384
1384
  * upperDashToDash({ 'FIRST-NAME': 'John' }); // { 'first-name': 'John' }
1385
1385
  * ```
1386
1386
  *
1387
- * @deprecated Use `toDash` instead, which converts from any case. It keeps acronyms together,
1387
+ * @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
1388
1388
  * so results differ for keys like `userID` (see the migration notes in the README).
1389
1389
  */
1390
1390
  function upperDashToDash(input) {
@@ -1521,7 +1521,7 @@ function upperSnakeToSnake(input) {
1521
1521
  * upperSnakeToDash({ FIRST_NAME: 'John' }); // { 'first-name': 'John' }
1522
1522
  * ```
1523
1523
  *
1524
- * @deprecated Use `toDash` instead, which converts from any case. It keeps acronyms together,
1524
+ * @deprecated Use `toKebab` instead, which converts from any case. It keeps acronyms together,
1525
1525
  * so results differ for keys like `userID` (see the migration notes in the README).
1526
1526
  */
1527
1527
  function upperSnakeToDash(input) {
@@ -1551,7 +1551,7 @@ function upperSnakeToPascal(input) {
1551
1551
  * upperSnakeToUpperDash({ FIRST_NAME: 'John' }); // { 'FIRST-NAME': 'John' }
1552
1552
  * ```
1553
1553
  *
1554
- * @deprecated Use `toUpperDash` instead, which converts from any case. It keeps acronyms together,
1554
+ * @deprecated Use `toUpperKebab` instead, which converts from any case. It keeps acronyms together,
1555
1555
  * so results differ for keys like `userID` (see the migration notes in the README).
1556
1556
  */
1557
1557
  function upperSnakeToUpperDash(input) {
@@ -1619,20 +1619,28 @@ function upperSnakeToSentence(input) {
1619
1619
  }
1620
1620
  //#endregion
1621
1621
  //#region src/anyCase/words.ts
1622
+ const SYMBOLS = "!\"#$%&'()*+,/:;<=>?@[\\]^`{|}~";
1622
1623
  const isSeparator = (c) => c === "_" || c === "-" || c === "." || c === " ";
1624
+ const isSymbol = (c) => SYMBOLS.indexOf(c) !== -1;
1623
1625
  const isUpper = (c) => c !== c.toLowerCase();
1624
1626
  const isLower = (c) => c !== c.toUpperCase();
1627
+ const isKept = (c, keep) => keep === true || typeof keep !== "boolean" && keep !== void 0 && keep !== null && keep.indexOf(c) !== -1;
1625
1628
  /**
1626
1629
  * Splits a string in any case into lowercase words: on `_`, `-`, `.` and spaces,
1627
1630
  * before an uppercase letter that follows a lowercase letter or a digit (`helloWorld`),
1628
1631
  * and before the last letter of an acronym (`XMLHttp`). Mirrors the `Words` type.
1632
+ *
1633
+ * Symbols (ASCII punctuation) also start a new word. They are removed, unless `keep` is
1634
+ * `true` or lists them: a kept symbol sticks to the start of the next word (`hello$World`
1635
+ * → `hello`, `$world`), or to the end of the previous one when no word follows (`total%`).
1636
+ * Words keep their original case when `lowercase` is `false`.
1629
1637
  */
1630
- function words(str) {
1638
+ function words(str, keep = false, lowercase = true) {
1631
1639
  const result = [];
1632
1640
  let word = "";
1633
1641
  let prev = "";
1634
1642
  const push = () => {
1635
- if (word) result.push(word.toLowerCase());
1643
+ if (word) result.push(lowercase ? word.toLowerCase() : word);
1636
1644
  word = "";
1637
1645
  };
1638
1646
  for (let i = 0; i < str.length; i++) {
@@ -1642,24 +1650,48 @@ function words(str) {
1642
1650
  prev = "";
1643
1651
  continue;
1644
1652
  }
1653
+ if (isSymbol(c)) {
1654
+ let kept = "";
1655
+ let j = i;
1656
+ for (; j < str.length && isSymbol(str[j]); j++) if (isKept(str[j], keep)) kept += str[j];
1657
+ const next = str.charAt(j);
1658
+ if (next && !isSeparator(next)) {
1659
+ push();
1660
+ prev = "";
1661
+ }
1662
+ word += kept;
1663
+ i = j - 1;
1664
+ continue;
1665
+ }
1645
1666
  const next = str.charAt(i + 1);
1646
- if (isUpper(c) && word && (!isUpper(prev) || next && isLower(next))) push();
1667
+ if (isUpper(c) && prev && (!isUpper(prev) || next && isLower(next))) push();
1647
1668
  word += c;
1648
1669
  prev = c;
1649
1670
  }
1650
1671
  push();
1651
1672
  return result;
1652
1673
  }
1653
- const ToCamel = (str) => words(str).map((w, i) => i ? Capitalize(w) : w).join("");
1654
- const ToPascal = (str) => words(str).map(Capitalize).join("");
1655
- const ToSnake = (str) => words(str).join("_");
1656
- const ToDash = (str) => words(str).join("-");
1657
- const ToUpperSnake = (str) => words(str).join("_").toUpperCase();
1658
- const ToUpperDash = (str) => words(str).join("-").toUpperCase();
1659
- const ToTrain = (str) => words(str).map(Capitalize).join("-");
1660
- const ToDot = (str) => words(str).join(".");
1661
- const ToTitle = (str) => words(str).map(Capitalize).join(" ");
1662
- const ToSentence = (str) => Capitalize(words(str).join(" "));
1674
+ /** Uppercases the first character that is not a symbol: `'$id'` → `'$Id'`. */
1675
+ function capitalize(word) {
1676
+ let i = 0;
1677
+ while (i < word.length && isSymbol(word[i])) i++;
1678
+ return word.slice(0, i) + word.charAt(i).toUpperCase() + word.slice(i + 1);
1679
+ }
1680
+ const ToCamel = (str, keep) => words(str, keep).map((w, i) => i ? capitalize(w) : w).join("");
1681
+ const ToPascal = (str, keep) => words(str, keep).map(capitalize).join("");
1682
+ const ToSnake = (str, keep) => words(str, keep).join("_");
1683
+ const ToKebab = (str, keep) => words(str, keep).join("-");
1684
+ const ToUpperSnake = (str, keep) => words(str, keep).join("_").toUpperCase();
1685
+ const ToUpperKebab = (str, keep) => words(str, keep).join("-").toUpperCase();
1686
+ const ToTrain = (str, keep) => words(str, keep).map(capitalize).join("-");
1687
+ const ToDot = (str, keep) => words(str, keep, false).join(".");
1688
+ const ToTitle = (str, keep) => words(str, keep).map(capitalize).join(" ");
1689
+ const ToSentence = (str, keep) => capitalize(words(str, keep).join(" "));
1690
+ const ToPascalSnake = (str, keep) => words(str, keep).map(capitalize).join("_");
1691
+ const ToPath = (str, keep) => words(str, keep, false).join("/");
1692
+ const ToSpace = (str, keep) => words(str, keep, false).join(" ");
1693
+ const ToLower = (str, keep) => words(str, keep).join(" ");
1694
+ const ToUpper = (str, keep) => words(str, keep).join(" ").toUpperCase();
1663
1695
  //#endregion
1664
1696
  //#region src/anyCase/anyCase.ts
1665
1697
  /**
@@ -1669,10 +1701,14 @@ const ToSentence = (str) => Capitalize(words(str).join(" "));
1669
1701
  * ```ts
1670
1702
  * toCamel('hello_world'); // 'helloWorld'
1671
1703
  * toCamel({ first_name: 'John', userID: 1 }); // { firstName: 'John', userId: 1 }
1704
+ * toCamel('$hello-world', true); // '$helloWorld'
1672
1705
  * ```
1706
+ *
1707
+ * @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
1708
+ * Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
1673
1709
  */
1674
- function toCamel(input) {
1675
- return convert(input, ToCamel);
1710
+ function toCamel(input, keepSymbols) {
1711
+ return convert(input, (key) => ToCamel(key, keepSymbols));
1676
1712
  }
1677
1713
  /**
1678
1714
  * Converts a string, or the keys of an object/array (deeply), from any case to PascalCase.
@@ -1681,10 +1717,14 @@ function toCamel(input) {
1681
1717
  * ```ts
1682
1718
  * toPascal('hello-world'); // 'HelloWorld'
1683
1719
  * toPascal({ 'first-name': 'John', userID: 1 }); // { FirstName: 'John', UserId: 1 }
1720
+ * toPascal('$hello-world', true); // '$HelloWorld'
1684
1721
  * ```
1722
+ *
1723
+ * @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
1724
+ * Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
1685
1725
  */
1686
- function toPascal(input) {
1687
- return convert(input, ToPascal);
1726
+ function toPascal(input, keepSymbols) {
1727
+ return convert(input, (key) => ToPascal(key, keepSymbols));
1688
1728
  }
1689
1729
  /**
1690
1730
  * Converts a string, or the keys of an object/array (deeply), from any case to snake_case.
@@ -1693,22 +1733,30 @@ function toPascal(input) {
1693
1733
  * ```ts
1694
1734
  * toSnake('helloWorld'); // 'hello_world'
1695
1735
  * toSnake({ firstName: 'John', userID: 1 }); // { first_name: 'John', user_id: 1 }
1736
+ * toSnake('$hello-world', true); // '$hello_world'
1696
1737
  * ```
1738
+ *
1739
+ * @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
1740
+ * Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
1697
1741
  */
1698
- function toSnake(input) {
1699
- return convert(input, ToSnake);
1742
+ function toSnake(input, keepSymbols) {
1743
+ return convert(input, (key) => ToSnake(key, keepSymbols));
1700
1744
  }
1701
1745
  /**
1702
- * Converts a string, or the keys of an object/array (deeply), from any case to dash-case.
1746
+ * Converts a string, or the keys of an object/array (deeply), from any case to kebab-case.
1703
1747
  *
1704
1748
  * @example
1705
1749
  * ```ts
1706
- * toDash('HELLO_WORLD'); // 'hello-world'
1707
- * toDash({ FIRST_NAME: 'John', userID: 1 }); // { 'first-name': 'John', 'user-id': 1 }
1750
+ * toKebab('HELLO_WORLD'); // 'hello-world'
1751
+ * toKebab({ FIRST_NAME: 'John', userID: 1 }); // { 'first-name': 'John', 'user-id': 1 }
1752
+ * toKebab('$hello-world', true); // '$hello-world'
1708
1753
  * ```
1754
+ *
1755
+ * @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
1756
+ * Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
1709
1757
  */
1710
- function toDash(input) {
1711
- return convert(input, ToDash);
1758
+ function toKebab(input, keepSymbols) {
1759
+ return convert(input, (key) => ToKebab(key, keepSymbols));
1712
1760
  }
1713
1761
  /**
1714
1762
  * Converts a string, or the keys of an object/array (deeply), from any case to UPPER_SNAKE_CASE.
@@ -1717,22 +1765,30 @@ function toDash(input) {
1717
1765
  * ```ts
1718
1766
  * toUpperSnake('hello-world'); // 'HELLO_WORLD'
1719
1767
  * toUpperSnake({ 'first-name': 'John', userID: 1 }); // { FIRST_NAME: 'John', USER_ID: 1 }
1768
+ * toUpperSnake('$hello-world', true); // '$HELLO_WORLD'
1720
1769
  * ```
1770
+ *
1771
+ * @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
1772
+ * Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
1721
1773
  */
1722
- function toUpperSnake(input) {
1723
- return convert(input, ToUpperSnake);
1774
+ function toUpperSnake(input, keepSymbols) {
1775
+ return convert(input, (key) => ToUpperSnake(key, keepSymbols));
1724
1776
  }
1725
1777
  /**
1726
- * Converts a string, or the keys of an object/array (deeply), from any case to UPPER-DASH-CASE.
1778
+ * Converts a string, or the keys of an object/array (deeply), from any case to UPPER-KEBAB-CASE.
1727
1779
  *
1728
1780
  * @example
1729
1781
  * ```ts
1730
- * toUpperDash('helloWorld'); // 'HELLO-WORLD'
1731
- * toUpperDash({ firstName: 'John', userID: 1 }); // { 'FIRST-NAME': 'John', 'USER-ID': 1 }
1782
+ * toUpperKebab('helloWorld'); // 'HELLO-WORLD'
1783
+ * toUpperKebab({ firstName: 'John', userID: 1 }); // { 'FIRST-NAME': 'John', 'USER-ID': 1 }
1784
+ * toUpperKebab('$hello-world', true); // '$HELLO-WORLD'
1732
1785
  * ```
1786
+ *
1787
+ * @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
1788
+ * Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
1733
1789
  */
1734
- function toUpperDash(input) {
1735
- return convert(input, ToUpperDash);
1790
+ function toUpperKebab(input, keepSymbols) {
1791
+ return convert(input, (key) => ToUpperKebab(key, keepSymbols));
1736
1792
  }
1737
1793
  /**
1738
1794
  * Converts a string, or the keys of an object/array (deeply), from any case to Train-Case.
@@ -1741,22 +1797,30 @@ function toUpperDash(input) {
1741
1797
  * ```ts
1742
1798
  * toTrain('hello_world'); // 'Hello-World'
1743
1799
  * toTrain({ first_name: 'John', userID: 1 }); // { 'First-Name': 'John', 'User-Id': 1 }
1800
+ * toTrain('$hello-world', true); // '$Hello-World'
1744
1801
  * ```
1802
+ *
1803
+ * @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
1804
+ * Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
1745
1805
  */
1746
- function toTrain(input) {
1747
- return convert(input, ToTrain);
1806
+ function toTrain(input, keepSymbols) {
1807
+ return convert(input, (key) => ToTrain(key, keepSymbols));
1748
1808
  }
1749
1809
  /**
1750
- * Converts a string, or the keys of an object/array (deeply), from any case to dot.case.
1810
+ * Converts a string, or the keys of an object/array (deeply), from any case to dot.case, keeping the original case of each word.
1751
1811
  *
1752
1812
  * @example
1753
1813
  * ```ts
1754
- * toDot('HelloWorld'); // 'hello.world'
1755
- * toDot({ FirstName: 'John', userID: 1 }); // { 'first.name': 'John', 'user.id': 1 }
1814
+ * toDot('HelloWorld'); // 'Hello.World'
1815
+ * toDot({ FirstName: 'John', userID: 1 }); // { 'First.Name': 'John', 'user.ID': 1 }
1816
+ * toDot('$hello-world', true); // '$hello.world'
1756
1817
  * ```
1818
+ *
1819
+ * @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
1820
+ * Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
1757
1821
  */
1758
- function toDot(input) {
1759
- return convert(input, ToDot);
1822
+ function toDot(input, keepSymbols) {
1823
+ return convert(input, (key) => ToDot(key, keepSymbols));
1760
1824
  }
1761
1825
  /**
1762
1826
  * Converts a string, or the keys of an object/array (deeply), from any case to Title Case.
@@ -1765,10 +1829,14 @@ function toDot(input) {
1765
1829
  * ```ts
1766
1830
  * toTitle('hello_world'); // 'Hello World'
1767
1831
  * toTitle({ first_name: 'John', userID: 1 }); // { 'First Name': 'John', 'User Id': 1 }
1832
+ * toTitle('$hello-world', true); // '$Hello World'
1768
1833
  * ```
1834
+ *
1835
+ * @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
1836
+ * Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
1769
1837
  */
1770
- function toTitle(input) {
1771
- return convert(input, ToTitle);
1838
+ function toTitle(input, keepSymbols) {
1839
+ return convert(input, (key) => ToTitle(key, keepSymbols));
1772
1840
  }
1773
1841
  /**
1774
1842
  * Converts a string, or the keys of an object/array (deeply), from any case to Sentence case.
@@ -1777,10 +1845,94 @@ function toTitle(input) {
1777
1845
  * ```ts
1778
1846
  * toSentence('helloWorld'); // 'Hello world'
1779
1847
  * toSentence({ firstName: 'John', userID: 1 }); // { 'First name': 'John', 'User id': 1 }
1848
+ * toSentence('$hello-world', true); // '$Hello world'
1780
1849
  * ```
1850
+ *
1851
+ * @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
1852
+ * Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
1853
+ */
1854
+ function toSentence(input, keepSymbols) {
1855
+ return convert(input, (key) => ToSentence(key, keepSymbols));
1856
+ }
1857
+ /**
1858
+ * Converts a string, or the keys of an object/array (deeply), from any case to Pascal_Snake_Case (also known as Ada_Case).
1859
+ *
1860
+ * @example
1861
+ * ```ts
1862
+ * toPascalSnake('helloWorld'); // 'Hello_World'
1863
+ * toPascalSnake({ first_name: 'John', userID: 1 }); // { First_Name: 'John', User_Id: 1 }
1864
+ * toPascalSnake('$hello-world', true); // '$Hello_World'
1865
+ * ```
1866
+ *
1867
+ * @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
1868
+ * Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
1869
+ */
1870
+ function toPascalSnake(input, keepSymbols) {
1871
+ return convert(input, (key) => ToPascalSnake(key, keepSymbols));
1872
+ }
1873
+ /**
1874
+ * Converts a string, or the keys of an object/array (deeply), from any case to path/case, keeping the original case of each word.
1875
+ *
1876
+ * @example
1877
+ * ```ts
1878
+ * toPath('helloWorld'); // 'hello/World'
1879
+ * toPath({ first_name: 'John', userID: 1 }); // { 'first/name': 'John', 'user/ID': 1 }
1880
+ * toPath('$hello-world', true); // '$hello/world'
1881
+ * ```
1882
+ *
1883
+ * @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
1884
+ * Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
1885
+ */
1886
+ function toPath(input, keepSymbols) {
1887
+ return convert(input, (key) => ToPath(key, keepSymbols));
1888
+ }
1889
+ /**
1890
+ * Converts a string, or the keys of an object/array (deeply), from any case to space case, keeping the original case of each word.
1891
+ *
1892
+ * @example
1893
+ * ```ts
1894
+ * toSpace('helloWorld'); // 'hello World'
1895
+ * toSpace({ first_name: 'John', userID: 1 }); // { 'first name': 'John', 'user ID': 1 }
1896
+ * toSpace('$hello-world', true); // '$hello world'
1897
+ * ```
1898
+ *
1899
+ * @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
1900
+ * Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
1901
+ */
1902
+ function toSpace(input, keepSymbols) {
1903
+ return convert(input, (key) => ToSpace(key, keepSymbols));
1904
+ }
1905
+ /**
1906
+ * Converts a string, or the keys of an object/array (deeply), from any case to lower case (space separated).
1907
+ *
1908
+ * @example
1909
+ * ```ts
1910
+ * toLower('helloWorld'); // 'hello world'
1911
+ * toLower({ first_name: 'John', userID: 1 }); // { 'first name': 'John', 'user id': 1 }
1912
+ * toLower('$hello-world', true); // '$hello world'
1913
+ * ```
1914
+ *
1915
+ * @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
1916
+ * Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
1917
+ */
1918
+ function toLower(input, keepSymbols) {
1919
+ return convert(input, (key) => ToLower(key, keepSymbols));
1920
+ }
1921
+ /**
1922
+ * Converts a string, or the keys of an object/array (deeply), from any case to UPPER CASE (space separated).
1923
+ *
1924
+ * @example
1925
+ * ```ts
1926
+ * toUpper('helloWorld'); // 'HELLO WORLD'
1927
+ * toUpper({ first_name: 'John', userID: 1 }); // { 'FIRST NAME': 'John', 'USER ID': 1 }
1928
+ * toUpper('$hello-world', true); // '$HELLO WORLD'
1929
+ * ```
1930
+ *
1931
+ * @param keepSymbols Symbols (ASCII punctuation, like `$` or `@`) are removed by default.
1932
+ * Pass `true` to keep all of them, or an array to keep only some (e.g. `['$']`).
1781
1933
  */
1782
- function toSentence(input) {
1783
- return convert(input, ToSentence);
1934
+ function toUpper(input, keepSymbols) {
1935
+ return convert(input, (key) => ToUpper(key, keepSymbols));
1784
1936
  }
1785
1937
  //#endregion
1786
1938
  exports.camelToDash = camelToDash;
@@ -1847,14 +1999,19 @@ exports.titleToTrain = titleToTrain;
1847
1999
  exports.titleToUpperDash = titleToUpperDash;
1848
2000
  exports.titleToUpperSnake = titleToUpperSnake;
1849
2001
  exports.toCamel = toCamel;
1850
- exports.toDash = toDash;
1851
2002
  exports.toDot = toDot;
2003
+ exports.toKebab = toKebab;
2004
+ exports.toLower = toLower;
1852
2005
  exports.toPascal = toPascal;
2006
+ exports.toPascalSnake = toPascalSnake;
2007
+ exports.toPath = toPath;
1853
2008
  exports.toSentence = toSentence;
1854
2009
  exports.toSnake = toSnake;
2010
+ exports.toSpace = toSpace;
1855
2011
  exports.toTitle = toTitle;
1856
2012
  exports.toTrain = toTrain;
1857
- exports.toUpperDash = toUpperDash;
2013
+ exports.toUpper = toUpper;
2014
+ exports.toUpperKebab = toUpperKebab;
1858
2015
  exports.toUpperSnake = toUpperSnake;
1859
2016
  exports.trainToCamel = trainToCamel;
1860
2017
  exports.trainToDash = trainToDash;