Skip to content
This repository was archived by the owner on Dec 28, 2022. It is now read-only.

Commit b70269e

Browse files
committed
Variable name fix in case of empty prefix
1 parent a7d4ff6 commit b70269e

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

src/js/helpers.js

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,39 @@
11
/**
2-
* Convert group name, token name and possible prefix into camelCased string, joining everything together
3-
*/
4-
Pulsar.registerFunction("readableVariableName", function (token, tokenGroup, prefix) {
5-
2+
* Convert group name, token name and possible prefix into camelCased string, joining everything together
3+
*/
4+
Pulsar.registerFunction(
5+
"readableVariableName",
6+
function (token, tokenGroup, prefix) {
67
// Create array with all path segments and token name at the end
7-
let segments = [...tokenGroup.path, token.name]
8+
let segments = [...tokenGroup.path, token.name];
89
if (prefix && prefix.length > 0) {
9-
segments.unshift(prefix)
10+
segments.unshift(prefix);
1011
}
1112

1213
// Create "sentence" separated by spaces so we can camelcase it all
13-
let sentence = segments.join(" ")
14+
let sentence = segments.join(" ");
1415

1516
// Return camelcased string from all segments
16-
return sentence.toLowerCase().replace(/[^a-zA-Z0-9]+(.)/g, (m, chr) => chr.toUpperCase());
17-
})
17+
sentence = sentence
18+
.toLowerCase()
19+
.replace(/[^a-zA-Z0-9]+(.)/g, (m, chr) => chr.toUpperCase());
20+
21+
if (/^\d/.test(sentence)) {
22+
sentence = "_" + sentence;
23+
}
24+
return sentence;
25+
}
26+
);
1827

1928
/**
20-
* Behavior configuration of the exporter
21-
* Prefixes: Add prefix for each category of the tokens. For example, all colors can start with "color, if needed"
22-
*/
29+
* Behavior configuration of the exporter
30+
* Prefixes: Add prefix for each category of the tokens. For example, all colors can start with "color, if needed"
31+
*/
2332
Pulsar.registerPayload("behavior", {
24-
colorTokenPrefix: "color",
25-
borderTokenPrefix: "border",
26-
gradientTokenPrefix: "gradient",
27-
measureTokenPrefix: "measure",
28-
shadowTokenPrefix: "shadow",
29-
typographyTokenPrefix: "typography"
30-
})
33+
colorTokenPrefix: "color",
34+
borderTokenPrefix: "border",
35+
gradientTokenPrefix: "gradient",
36+
measureTokenPrefix: "measure",
37+
shadowTokenPrefix: "shadow",
38+
typographyTokenPrefix: "typography",
39+
});

0 commit comments

Comments
 (0)