@kubb/plugin-ts 5.3.0 → 5.3.2

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
@@ -19,15 +19,23 @@ var __exportAll = (all, no_symbols) => {
19
19
  return target;
20
20
  };
21
21
  // ../../internals/utils/src/casing.ts
22
+ const wordStart = /(?<=[a-z\d])(?=[A-Z])|(?<=[A-Z]{2})(?=[A-Z][a-z]{2})/;
23
+ /**
24
+ * Splits `text` into words on separators (whitespace, hyphens, underscores, dots, slashes, colons)
25
+ * and on {@link wordStart}. A segment without lowercase letters, such as `COOL` or `2D`, is one word,
26
+ * so snake case leaves a name that is already in it unchanged.
27
+ */
28
+ function words(text) {
29
+ return text.split(/[\s\-_./\\:]+/).filter(Boolean).flatMap((segment) => segment === segment.toUpperCase() ? segment : segment.split(wordStart));
30
+ }
22
31
  /**
23
32
  * Shared implementation for camelCase and PascalCase conversion.
24
- * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
25
- * and capitalizes each word according to `pascal`.
33
+ * Capitalizes each word from {@link words} according to `pascal`.
26
34
  *
27
35
  * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
28
36
  */
29
37
  function convert(text, pascal) {
30
- return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
38
+ return words(text).flatMap((word) => word.split(/(?<=\d)(?=[a-z])|(?<=[A-Z])(?=[A-Z][a-z])/)).map((word, i) => {
31
39
  if (word.length > 1 && word === word.toUpperCase()) return word;
32
40
  return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
33
41
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
@@ -77,7 +85,7 @@ function pascalCase(text, { prefix = "", suffix = "" } = {}) {
77
85
  * `snakeCase('Hello-World') // 'hello_world'`
78
86
  */
79
87
  function snakeCase(text, { prefix = "", suffix = "" } = {}) {
80
- return `${prefix} ${text} ${suffix}`.trim().replace(/([a-z])([A-Z])/g, "$1_$2").replace(/[\s\-.]+/g, "_").replace(/[^a-zA-Z0-9_]/g, "").toLowerCase().split("_").filter(Boolean).join("_");
88
+ return words(`${prefix} ${text} ${suffix}`).map((word) => word.replace(/[^a-zA-Z0-9]/g, "").toLowerCase()).filter(Boolean).join("_");
81
89
  }
82
90
  /**
83
91
  * Converts `text` to SCREAMING_SNAKE_CASE.
@@ -1914,7 +1922,7 @@ var compatibility = {
1914
1922
  "node": ">=22.22"
1915
1923
  };
1916
1924
  // package.json
1917
- var version = "5.3.0";
1925
+ var version = "5.3.2";
1918
1926
  // src/resolvers/resolverTs.ts
1919
1927
  /**
1920
1928
  * Default resolver used by `@kubb/plugin-ts`. Decides the names and file paths