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

Commit 5677242

Browse files
committed
fix for readableVariableName
1 parent 93771ce commit 5677242

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/js/helpers.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,19 @@ Pulsar.registerFunction(
1818
// Create "sentence" separated by spaces so we can camelcase it all
1919
let sentence = segments.join(" ");
2020

21-
// Return camelcased string from all segments
21+
// camelcase string from all segments
2222
sentence = sentence
2323
.toLowerCase()
24-
.replace(/[^a-zA-Z0-9]+(.)/g, (m, chr) => chr.toUpperCase());
24+
.replace(/[^a-zA-Z0-9]+(.)/g, (m, chr) => chr.toUpperCase())
25+
26+
// only allow letters, digits, underscore and hyphen
27+
sentence = sentence.replace(/[^a-zA-Z0-9_-]/g, '_')
2528

29+
// prepend underscore if it starts with digit
2630
if (/^\d/.test(sentence)) {
2731
sentence = '_' + sentence;
2832
}
33+
2934
return sentence;
3035
}
3136
);

0 commit comments

Comments
 (0)