@tsparticles/cli 1.11.0 → 1.13.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.
@@ -10,6 +10,7 @@ import {
10
10
  } from "../../utils/template-utils";
11
11
  import fs from "fs-extra";
12
12
  import path from "path";
13
+ import { replaceTokensInFile } from "../../utils/file-utils";
13
14
 
14
15
  /**
15
16
  * Updates the bundle file with the correct function name
@@ -17,13 +18,17 @@ import path from "path";
17
18
  * @param name - The name of the project
18
19
  */
19
20
  async function updateBundleFile(destPath: string, name: string): Promise<void> {
20
- const bundlePath = path.resolve(destPath, "src", "bundle.ts"),
21
- bundle = await fs.readFile(bundlePath, "utf-8"),
22
- capitalizedName = capitalize(capitalize(name, "-"), " "),
23
- bundleRegex = /loadTemplatePreset/g,
24
- replacedText = bundle.replace(bundleRegex, `load${capitalizedName}Preset`);
25
-
26
- await fs.writeFile(bundlePath, replacedText);
21
+ const capitalizedName = capitalize(name, "-", " ");
22
+
23
+ await replaceTokensInFile({
24
+ path: path.resolve(destPath, "src", "bundle.ts"),
25
+ tokens: [
26
+ {
27
+ from: /loadTemplatePreset/g,
28
+ to: `load${capitalizedName}Preset`,
29
+ },
30
+ ],
31
+ });
27
32
  }
28
33
 
29
34
  /**
@@ -32,16 +37,22 @@ async function updateBundleFile(destPath: string, name: string): Promise<void> {
32
37
  * @param name - The name of the project
33
38
  */
34
39
  async function updateIndexFile(destPath: string, name: string): Promise<void> {
35
- const indexPath = path.resolve(destPath, "src", "index.ts"),
36
- index = await fs.readFile(indexPath, "utf-8"),
37
- capitalizedName = capitalize(capitalize(name, "-"), " "),
38
- camelizedName = camelize(capitalizedName),
39
- indexFunctionRegex = /loadTemplatePreset/g,
40
- replacedFuncText = index.replace(indexFunctionRegex, `load${capitalizedName}Preset`),
41
- indexNameRegex = /"#template#"/g,
42
- replacedNameText = replacedFuncText.replace(indexNameRegex, `"${camelizedName}"`);
43
-
44
- await fs.writeFile(indexPath, replacedNameText);
40
+ const capitalizedName = capitalize(name, "-", " "),
41
+ camelizedName = camelize(capitalizedName);
42
+
43
+ await replaceTokensInFile({
44
+ path: path.resolve(destPath, "src", "index.ts"),
45
+ tokens: [
46
+ {
47
+ from: /loadTemplatePreset/g,
48
+ to: `load${capitalizedName}Preset`,
49
+ },
50
+ {
51
+ from: /"#template#"/g,
52
+ to: `"${camelizedName}"`,
53
+ },
54
+ ],
55
+ });
45
56
  }
46
57
 
47
58
  /**
@@ -57,14 +68,14 @@ async function updatePresetPackageFile(
57
68
  description: string,
58
69
  repoUrl: string,
59
70
  ): Promise<void> {
60
- const camelizedName = camelize(camelize(name, "-"), " "),
71
+ const camelizedName = camelize(name, "-", " "),
61
72
  dashedName = dash(camelizedName);
62
73
 
63
- updatePackageFile(
74
+ await updatePackageFile(
64
75
  destPath,
65
- `"tsparticles-preset-${dashedName}"`,
76
+ `tsparticles-preset-${dashedName}`,
66
77
  description,
67
- `"tsparticles.preset.${camelizedName}.min.js"`,
78
+ `tsparticles.preset.${camelizedName}.min.js`,
68
79
  repoUrl,
69
80
  );
70
81
  }
@@ -82,14 +93,14 @@ async function updatePresetPackageDistFile(
82
93
  description: string,
83
94
  repoUrl: string,
84
95
  ): Promise<void> {
85
- const camelizedName = camelize(camelize(name, "-"), " "),
96
+ const camelizedName = camelize(name, "-", " "),
86
97
  dashedName = dash(camelizedName);
87
98
 
88
- updatePackageDistFile(
99
+ await updatePackageDistFile(
89
100
  destPath,
90
- `"tsparticles-preset-${dashedName}"`,
101
+ `tsparticles-preset-${dashedName}`,
91
102
  description,
92
- `"tsparticles.preset.${camelizedName}.min.js"`,
103
+ `tsparticles.preset.${camelizedName}.min.js`,
93
104
  repoUrl,
94
105
  );
95
106
  }
@@ -102,47 +113,46 @@ async function updatePresetPackageDistFile(
102
113
  * @param repoUrl - The repository url
103
114
  */
104
115
  async function updateReadmeFile(destPath: string, name: string, description: string, repoUrl: string): Promise<void> {
105
- const readmePath = path.resolve(destPath, "README.md"),
106
- readme = await fs.readFile(readmePath, "utf-8"),
107
- capitalizedName = capitalize(capitalize(name, "-"), " "),
116
+ const capitalizedName = capitalize(name, "-", " "),
108
117
  camelizedName = camelize(capitalizedName),
109
118
  dashedName = dash(camelizedName),
110
- readmeDescriptionRegex = /tsParticles Template Preset/g,
111
- replacedDescriptionText = readme.replace(readmeDescriptionRegex, `tsParticles ${description} Preset`),
112
- readmePackageNameRegex = /tsparticles-preset-template/g,
113
- replacedPackageNameText = replacedDescriptionText.replace(
114
- readmePackageNameRegex,
115
- `tsparticles-preset-${dashedName}`,
116
- ),
117
- readmeFileNameRegex = /tsparticles\.preset\.template(\.bundle)?\.min\.js/g,
118
- replacedFileNameText = replacedPackageNameText.replace(
119
- readmeFileNameRegex,
120
- `tsparticles.preset.${camelizedName}$1.min.js`,
121
- ),
122
- readmeFunctionNameRegex = /loadTemplatePreset/g,
123
- replacedFunctionNameText = replacedFileNameText.replace(
124
- readmeFunctionNameRegex,
125
- `load${capitalizedName}Preset`,
126
- ),
127
- readmeMiniDescriptionRegex =
128
- /\[tsParticles]\(https:\/\/github.com\/matteobruni\/tsparticles\) preset template\./g,
129
- replacedMiniDescriptionText = replacedFunctionNameText.replace(
130
- readmeMiniDescriptionRegex,
131
- `[tsParticles](https://github.com/matteobruni/tsparticles) preset ${name}.`,
132
- ),
133
- readmeUsageRegex = /preset: "template"/g,
134
- replacedUsageText = replacedMiniDescriptionText.replace(readmeUsageRegex, `preset: "${camelizedName}`),
135
- sampleImageRegex =
136
- /!\[demo]\(https:\/\/raw.githubusercontent.com\/tsparticles\/preset-template\/main\/images\/sample.png\)/g,
137
119
  repoPath = repoUrl.includes("github.com")
138
120
  ? repoUrl.substring(repoUrl.indexOf("github.com/") + 11, repoUrl.indexOf(".git"))
139
- : "tsparticles/preset-template",
140
- replacedText = replacedUsageText.replace(
141
- sampleImageRegex,
142
- `![demo](https://raw.githubusercontent.com/${repoPath}/main/images/sample.png)`,
143
- );
144
-
145
- await fs.writeFile(readmePath, replacedText);
121
+ : "tsparticles/preset-template";
122
+
123
+ await replaceTokensInFile({
124
+ path: path.resolve(destPath, "README.md"),
125
+ tokens: [
126
+ {
127
+ from: /tsParticles Template Preset/g,
128
+ to: `tsParticles ${description} Preset`,
129
+ },
130
+ {
131
+ from: /tsparticles-preset-template/g,
132
+ to: `tsparticles-preset-${dashedName}`,
133
+ },
134
+ {
135
+ from: /tsparticles\.preset\.template(\.bundle)?\.min\.js/g,
136
+ to: `tsparticles.preset.${camelizedName}$1.min.js`,
137
+ },
138
+ {
139
+ from: /loadTemplatePreset/g,
140
+ to: `load${capitalizedName}Preset`,
141
+ },
142
+ {
143
+ from: /\[tsParticles]\(https:\/\/github.com\/matteobruni\/tsparticles\) preset template\./g,
144
+ to: `[tsParticles](https://github.com/matteobruni/tsparticles) preset ${name}.`,
145
+ },
146
+ {
147
+ from: /preset: "template"/g,
148
+ to: `preset: "${camelizedName}`,
149
+ },
150
+ {
151
+ from: /!\[demo]\(https:\/\/raw.githubusercontent.com\/tsparticles\/preset-template\/main\/images\/sample.png\)/g,
152
+ to: `![demo](https://raw.githubusercontent.com/${repoPath}/main/images/sample.png)`,
153
+ },
154
+ ],
155
+ });
146
156
  }
147
157
 
148
158
  /**
@@ -152,12 +162,7 @@ async function updateReadmeFile(destPath: string, name: string, description: str
152
162
  * @param description - The description of the project
153
163
  */
154
164
  async function updatePresetWebpackFile(destPath: string, name: string, description: string): Promise<void> {
155
- await updateWebpackFile(
156
- destPath,
157
- camelize(capitalize(capitalize(name, "-"), " ")),
158
- `tsParticles ${description} Preset`,
159
- "loadParticlesPreset",
160
- );
165
+ await updateWebpackFile(destPath, camelize(capitalize(name, "-", " ")), description, "loadParticlesPreset");
161
166
  }
162
167
 
163
168
  /**
@@ -1,9 +1,8 @@
1
+ import { getDestinationDir, getRepositoryUrl } from "../../utils/file-utils";
1
2
  import prompts, { type PromptObject } from "prompts";
2
3
  import { Command } from "commander";
3
4
  import { capitalize } from "../../utils/string-utils";
4
5
  import { createPresetTemplate } from "./create-preset";
5
- import { execSync } from "child_process";
6
- import fs from "fs-extra";
7
6
  import path from "path";
8
7
 
9
8
  const presetCommand = new Command("preset");
@@ -11,27 +10,8 @@ const presetCommand = new Command("preset");
11
10
  presetCommand.description("Create a new tsParticles preset");
12
11
  presetCommand.argument("<destination>", "Destination folder");
13
12
  presetCommand.action(async (destination: string) => {
14
- let repoUrl: string;
15
-
16
- const destPath = path.resolve(path.join(process.cwd(), destination)),
17
- destExists = await fs.pathExists(destPath);
18
-
19
- if (destExists) {
20
- const destContents = await fs.readdir(destPath),
21
- destContentsNoGit = destContents.filter(t => t !== ".git" && t !== ".gitignore");
22
-
23
- if (destContentsNoGit.length) {
24
- throw new Error("Destination folder already exists and is not empty");
25
- }
26
- }
27
-
28
- await fs.ensureDir(destPath);
29
-
30
- try {
31
- repoUrl = execSync("git config --get remote.origin.url").toString();
32
- } catch {
33
- repoUrl = "";
34
- }
13
+ const destPath = await getDestinationDir(destination),
14
+ repoUrl = getRepositoryUrl();
35
15
 
36
16
  const initialName = destPath.split(path.sep).pop(),
37
17
  questions: PromptObject[] = [
@@ -59,7 +39,7 @@ presetCommand.action(async (destination: string) => {
59
39
 
60
40
  const { name, description, repositoryUrl } = await prompts(questions);
61
41
 
62
- createPresetTemplate(name.trim(), description.trim(), repositoryUrl.trim(), destPath);
42
+ await createPresetTemplate(name.trim(), description.trim(), repositoryUrl.trim(), destPath);
63
43
  });
64
44
 
65
45
  export { presetCommand };
@@ -10,6 +10,7 @@ import {
10
10
  } from "../../utils/template-utils";
11
11
  import fs from "fs-extra";
12
12
  import path from "path";
13
+ import { replaceTokensInFile } from "../../utils/file-utils";
13
14
 
14
15
  /**
15
16
  * Updates the index file with the correct function name
@@ -17,16 +18,22 @@ import path from "path";
17
18
  * @param name - The name of the project
18
19
  */
19
20
  async function updateIndexFile(destPath: string, name: string): Promise<void> {
20
- const indexPath = path.resolve(destPath, "src", "index.ts"),
21
- index = await fs.readFile(indexPath, "utf-8"),
22
- capitalizedName = capitalize(capitalize(name, "-"), " "),
23
- camelizedName = camelize(capitalizedName),
24
- indexFunctionRegex = /loadTemplateShape/g,
25
- replacedFuncText = index.replace(indexFunctionRegex, `load${capitalizedName}Shape`),
26
- indexNameRegex = /"#template#"/g,
27
- replacedNameText = replacedFuncText.replace(indexNameRegex, `"${camelizedName}"`);
21
+ const capitalizedName = capitalize(name, "-", " "),
22
+ camelizedName = camelize(capitalizedName);
28
23
 
29
- await fs.writeFile(indexPath, replacedNameText);
24
+ await replaceTokensInFile({
25
+ path: path.resolve(destPath, "src", "index.ts"),
26
+ tokens: [
27
+ {
28
+ from: /loadTemplateShape/g,
29
+ to: `load${capitalizedName}Shape`,
30
+ },
31
+ {
32
+ from: /"#template#"/g,
33
+ to: `"${camelizedName}"`,
34
+ },
35
+ ],
36
+ });
30
37
  }
31
38
 
32
39
  /**
@@ -45,11 +52,11 @@ async function updateShapePackageFile(
45
52
  const camelizedName = camelize(camelize(name, "-"), " "),
46
53
  dashedName = dash(camelizedName);
47
54
 
48
- updatePackageFile(
55
+ await updatePackageFile(
49
56
  destPath,
50
- `"tsparticles-shape-${dashedName}"`,
57
+ `tsparticles-shape-${dashedName}`,
51
58
  description,
52
- `"tsparticles.shape.${camelizedName}.min.js"`,
59
+ `tsparticles.shape.${camelizedName}.min.js`,
53
60
  repoUrl,
54
61
  );
55
62
  }
@@ -70,11 +77,11 @@ async function updateShapePackageDistFile(
70
77
  const camelizedName = camelize(camelize(name, "-"), " "),
71
78
  dashedName = dash(camelizedName);
72
79
 
73
- updatePackageDistFile(
80
+ await updatePackageDistFile(
74
81
  destPath,
75
- `"tsparticles-shape-${dashedName}"`,
82
+ `tsparticles-shape-${dashedName}`,
76
83
  description,
77
- `"tsparticles.shape.${camelizedName}.min.js"`,
84
+ `tsparticles.shape.${camelizedName}.min.js`,
78
85
  repoUrl,
79
86
  );
80
87
  }
@@ -87,44 +94,46 @@ async function updateShapePackageDistFile(
87
94
  * @param repoUrl - The repository url
88
95
  */
89
96
  async function updateReadmeFile(destPath: string, name: string, description: string, repoUrl: string): Promise<void> {
90
- const readmePath = path.resolve(destPath, "README.md"),
91
- readme = await fs.readFile(readmePath, "utf-8"),
92
- capitalizedName = capitalize(capitalize(name, "-"), " "),
97
+ const capitalizedName = capitalize(name, "-", " "),
93
98
  camelizedName = camelize(capitalizedName),
94
99
  dashedName = dash(camelizedName),
95
- readmeDescriptionRegex = /tsParticles Template Shape/g,
96
- replacedDescriptionText = readme.replace(readmeDescriptionRegex, `tsParticles ${description} Shape`),
97
- readmePackageNameRegex = /tsparticles-shape-template/g,
98
- replacedPackageNameText = replacedDescriptionText.replace(
99
- readmePackageNameRegex,
100
- `tsparticles-shape-${dashedName}`,
101
- ),
102
- readmeFileNameRegex = /tsparticles\.shape\.template(\.bundle)?\.min\.js/g,
103
- replacedFileNameText = replacedPackageNameText.replace(
104
- readmeFileNameRegex,
105
- `tsparticles.shape.${camelizedName}$1.min.js`,
106
- ),
107
- readmeFunctionNameRegex = /loadTemplateShape/g,
108
- replacedFunctionNameText = replacedFileNameText.replace(readmeFunctionNameRegex, `load${capitalizedName}Shape`),
109
- readmeMiniDescriptionRegex =
110
- /\[tsParticles]\(https:\/\/github.com\/matteobruni\/tsparticles\) additional template shape\./g,
111
- replacedMiniDescriptionText = replacedFunctionNameText.replace(
112
- readmeMiniDescriptionRegex,
113
- `[tsParticles](https://github.com/matteobruni/tsparticles) additional ${name} shape.`,
114
- ),
115
- readmeUsageRegex = /shape\.type: "template"/g,
116
- replacedUsageText = replacedMiniDescriptionText.replace(readmeUsageRegex, `shape.type: "${camelizedName}`),
117
- sampleImageRegex =
118
- /!\[demo]\(https:\/\/raw.githubusercontent.com\/tsparticles\/shape-template\/main\/images\/sample.png\)/g,
119
100
  repoPath = repoUrl.includes("github.com")
120
101
  ? repoUrl.substring(repoUrl.indexOf("github.com/") + 11, repoUrl.indexOf(".git"))
121
- : "tsparticles/shape-template",
122
- replacedText = replacedUsageText.replace(
123
- sampleImageRegex,
124
- `![demo](https://raw.githubusercontent.com/${repoPath}/main/images/sample.png)`,
125
- );
102
+ : "tsparticles/shape-template";
126
103
 
127
- await fs.writeFile(readmePath, replacedText);
104
+ await replaceTokensInFile({
105
+ path: path.resolve(destPath, "README.md"),
106
+ tokens: [
107
+ {
108
+ from: /tsParticles Template Shape/g,
109
+ to: `tsParticles ${description} Shape`,
110
+ },
111
+ {
112
+ from: /tsparticles-shape-template/g,
113
+ to: `tsparticles-shape-${dashedName}`,
114
+ },
115
+ {
116
+ from: /tsparticles\.shape\.template(\.bundle)?\.min\.js/g,
117
+ to: `tsparticles.shape.${camelizedName}$1.min.js`,
118
+ },
119
+ {
120
+ from: /loadTemplateShape/g,
121
+ to: `load${capitalizedName}Shape`,
122
+ },
123
+ {
124
+ from: /\[tsParticles]\(https:\/\/github.com\/matteobruni\/tsparticles\) additional template shape\./g,
125
+ to: `[tsParticles](https://github.com/matteobruni/tsparticles) additional ${name} shape.`,
126
+ },
127
+ {
128
+ from: /shape\.type: "template"/g,
129
+ to: `shape.type: "${camelizedName}`,
130
+ },
131
+ {
132
+ from: /!\[demo]\(https:\/\/raw.githubusercontent.com\/tsparticles\/shape-template\/main\/images\/sample.png\)/g,
133
+ to: `![demo](https://raw.githubusercontent.com/${repoPath}/main/images/sample.png)`,
134
+ },
135
+ ],
136
+ });
128
137
  }
129
138
 
130
139
  /**
@@ -134,12 +143,7 @@ async function updateReadmeFile(destPath: string, name: string, description: str
134
143
  * @param description - The description of the project
135
144
  */
136
145
  async function updateShapeWebpackFile(destPath: string, name: string, description: string): Promise<void> {
137
- await updateWebpackFile(
138
- destPath,
139
- camelize(capitalize(capitalize(name, "-"), " ")),
140
- `tsParticles ${description} Shape`,
141
- "loadParticlesShape",
142
- );
146
+ await updateWebpackFile(destPath, camelize(capitalize(name, "-", " ")), description, "loadParticlesShape");
143
147
  }
144
148
 
145
149
  /**
@@ -1,9 +1,8 @@
1
+ import { getDestinationDir, getRepositoryUrl } from "../../utils/file-utils";
1
2
  import prompts, { type PromptObject } from "prompts";
2
3
  import { Command } from "commander";
3
4
  import { capitalize } from "../../utils/string-utils";
4
5
  import { createShapeTemplate } from "./create-shape";
5
- import { execSync } from "child_process";
6
- import fs from "fs-extra";
7
6
  import path from "path";
8
7
 
9
8
  const shapeCommand = new Command("shape");
@@ -11,27 +10,8 @@ const shapeCommand = new Command("shape");
11
10
  shapeCommand.description("Create a new tsParticles shape");
12
11
  shapeCommand.argument("<destination>", "Destination folder");
13
12
  shapeCommand.action(async (destination: string) => {
14
- let repoUrl: string;
15
-
16
- const destPath = path.resolve(path.join(process.cwd(), destination)),
17
- destExists = await fs.pathExists(destPath);
18
-
19
- if (destExists) {
20
- const destContents = await fs.readdir(destPath),
21
- destContentsNoGit = destContents.filter(t => t !== ".git" && t !== ".gitignore");
22
-
23
- if (destContentsNoGit.length) {
24
- throw new Error("Destination folder already exists and is not empty");
25
- }
26
- }
27
-
28
- await fs.ensureDir(destPath);
29
-
30
- try {
31
- repoUrl = execSync("git config --get remote.origin.url").toString();
32
- } catch {
33
- repoUrl = "";
34
- }
13
+ const destPath = await getDestinationDir(destination),
14
+ repoUrl = getRepositoryUrl();
35
15
 
36
16
  const initialName = destPath.split(path.sep).pop(),
37
17
  questions: PromptObject[] = [
@@ -59,7 +39,7 @@ shapeCommand.action(async (destination: string) => {
59
39
 
60
40
  const { name, description, repositoryUrl } = await prompts(questions);
61
41
 
62
- createShapeTemplate(name.trim(), description.trim(), repositoryUrl.trim(), destPath);
42
+ await createShapeTemplate(name.trim(), description.trim(), repositoryUrl.trim(), destPath);
63
43
  });
64
44
 
65
45
  export { shapeCommand };
@@ -0,0 +1,75 @@
1
+ import { execSync } from "child_process";
2
+ import fs from "fs-extra";
3
+ import path from "path";
4
+
5
+ export type ReplaceTokensOptions = {
6
+ path: string;
7
+ tokens: ReplaceTokensData[];
8
+ };
9
+
10
+ export type ReplaceTokensData = {
11
+ from: string | RegExp;
12
+ to: string;
13
+ };
14
+
15
+ /**
16
+ *
17
+ * @param options -
18
+ */
19
+ export async function replaceTokensInFiles(options: ReplaceTokensOptions[]): Promise<void> {
20
+ for (const item of options) {
21
+ const filePath = path.resolve(item.path);
22
+
23
+ let data = await fs.readFile(filePath, "utf-8");
24
+
25
+ for (const token of item.tokens) {
26
+ const regex = new RegExp(token.from, "g");
27
+
28
+ data = data.replace(regex, token.to);
29
+ }
30
+
31
+ await fs.writeFile(filePath, data);
32
+ }
33
+ }
34
+
35
+ /**
36
+ *
37
+ * @param options -
38
+ */
39
+ export async function replaceTokensInFile(options: ReplaceTokensOptions): Promise<void> {
40
+ await replaceTokensInFiles([options]);
41
+ }
42
+
43
+ /**
44
+ *
45
+ * @param destination -
46
+ * @returns the destination directory path
47
+ */
48
+ export async function getDestinationDir(destination: string): Promise<string> {
49
+ const destPath = path.resolve(path.join(process.cwd(), destination)),
50
+ destExists = await fs.pathExists(destPath);
51
+
52
+ if (destExists) {
53
+ const destContents = await fs.readdir(destPath),
54
+ destContentsNoGit = destContents.filter(t => t !== ".git" && t !== ".gitignore");
55
+
56
+ if (destContentsNoGit.length) {
57
+ throw new Error("Destination folder already exists and is not empty");
58
+ }
59
+ }
60
+
61
+ await fs.ensureDir(destPath);
62
+
63
+ return destPath;
64
+ }
65
+
66
+ /**
67
+ * @returns the repository URL
68
+ */
69
+ export function getRepositoryUrl(): string {
70
+ try {
71
+ return execSync("git config --get remote.origin.url").toString();
72
+ } catch {
73
+ return "";
74
+ }
75
+ }
@@ -1,23 +1,30 @@
1
1
  /**
2
2
  * This function is used to capitalize a string.
3
3
  * @param str - the string to capitalize (e.g. "my-string" -\> "MyString")
4
- * @param split - the character used to split the string, if not provided the string will be considered a single word
4
+ * @param splits - the characters used to split the string, if not provided the string will be considered a single word
5
5
  * @returns the capitalized string
6
6
  */
7
- export function capitalize(str: string, split?: string): string {
8
- const words = split ? str.split(split) : [str];
7
+ export function capitalize(str: string, ...splits: string[]): string {
8
+ let res = str.replace(/./, c => c.toUpperCase());
9
9
 
10
- return words.map(w => w.replace(/./, c => c.toUpperCase())).join("");
10
+ for (const split of splits) {
11
+ res = res
12
+ .split(split)
13
+ .map(w => w.replace(/./, c => c.toUpperCase()))
14
+ .join("");
15
+ }
16
+
17
+ return res;
11
18
  }
12
19
 
13
20
  /**
14
21
  * This function is used to camelcase a string.
15
22
  * @param str - the string to camelcase (e.g. "my-string" -\> "myString")
16
- * @param split - the character used to split the string, if not provided the string will be considered a single word
23
+ * @param splits - the characters used to split the string, if not provided the string will be considered a single word
17
24
  * @returns the camelized string
18
25
  */
19
- export function camelize(str: string, split?: string): string {
20
- return capitalize(str, split).replace(/./, c => c.toLowerCase());
26
+ export function camelize(str: string, ...splits: string[]): string {
27
+ return capitalize(str, ...splits).replace(/./, c => c.toLowerCase());
21
28
  }
22
29
 
23
30
  /**