generator-bitloops 0.3.10 → 0.3.11
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/package.json +1 -1
- package/setup/index.js +28 -4
package/package.json
CHANGED
package/setup/index.js
CHANGED
|
@@ -8,11 +8,35 @@ import { fileURLToPath } from 'url';
|
|
|
8
8
|
const __filename = fileURLToPath(import.meta.url);
|
|
9
9
|
const __dirname = path.dirname(__filename);
|
|
10
10
|
|
|
11
|
+
function isKebabCase(str) {
|
|
12
|
+
// Check if the string is empty
|
|
13
|
+
if (!str || str.trim().length === 0) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Regular expression to check if a string is kebab-case,
|
|
18
|
+
// ensuring it starts with a lowercase letter or digit, allowing for lowercase letters and digits in the middle or end,
|
|
19
|
+
// and ensuring each new word starts with a lowercase letter or digit
|
|
20
|
+
const kebabCaseRegex = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
21
|
+
|
|
22
|
+
return kebabCaseRegex.test(str);
|
|
23
|
+
}
|
|
24
|
+
|
|
11
25
|
function toKebabCase(str) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
26
|
+
if (isKebabCase(str)) {
|
|
27
|
+
return str;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const words = str
|
|
31
|
+
.trim()
|
|
32
|
+
// Split by non-alphanumeric characters and the transition from lowercase to uppercase
|
|
33
|
+
.split(/(?=[A-Z])|[^a-zA-Z0-9]+/)
|
|
34
|
+
.filter((word) => word.length > 0);
|
|
35
|
+
|
|
36
|
+
return words
|
|
37
|
+
.map((word) => word.toLowerCase())
|
|
38
|
+
.filter((word) => word.length > 0) // Remove empty words
|
|
39
|
+
.join('-');
|
|
16
40
|
}
|
|
17
41
|
|
|
18
42
|
export default class extends Generator {
|