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.
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.
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();});
}
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"