-
-
Notifications
You must be signed in to change notification settings - Fork 622
/
Copy pathplugins.ts
48 lines (43 loc) · 1.36 KB
/
plugins.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
*
* Callable function with the initial plugins
*
* @returns {Function} An function that returns an array
* that consists of terser-webpack-plugin
*/
export default function(): string[] {
return ["new TerserPlugin()"];
}
/**
*
* Replaces the string with a substring at the given index
* https://gist.github.com/efenacigiray/9367920
*
* @param {String} str - string to be modified
* @param {Number} index - index to replace from
* @param {String} replace - string to replace starting from index
*
* @returns {String} string - The newly mutated string
*
*/
export const replaceAt = (str: string, index: number, replace: string): string => {
return str.substring(0, index) + replace + str.substring(index + 1);
};
/**
*
* Generate a webpack standard webpack plugin name from the plugin name from the Answer
*
* @param {String} rawPluginName - plugin name from answer
*
* @returns {String} string - the webpack standard plugin name
*
*/
export const generatePluginName = (rawPluginName: string): string => {
let myPluginNameArray: string[];
myPluginNameArray = rawPluginName.split("-");
const pluginArrLength: number = myPluginNameArray.length;
for (let i = 0; i < pluginArrLength && pluginArrLength > 1; i++) {
myPluginNameArray[i] = replaceAt(myPluginNameArray[i], 0, myPluginNameArray[i].charAt(0).toUpperCase());
}
return myPluginNameArray.join("");
};