Anyone have a regex in javascript for converting:
someCamelCase into some-file-case
or
SomeCamelCase into some-file-case
??
If so, that would be very helpful.
Thanks.
You can make a simple regexp to capture a lowercase letter contiguous to an uppercase one, insert a dash between both and make the result all lowercase.
For example:
function fileCase(str) {
return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
}
fileCase('SomeCamelCase'); // "some-camel-case"
fileCase('someCamelCase'); // "some-camel-case"
Here. try this one.
"SomeCamelCase".replace(/[A-Z]/g, function(m){return '_' + m.toLowerCase();});
or as a function
function camelToHiphen(str){
return str.replace(/[A-Z]/g, function(m){return '_' + m.toLowerCase();});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With