e.g.
I want to write a camelToSnake()
camelToSnake = (phrase) ->
return phrase.replace(/([A-Z])/g, /-\L$1/)
is there such options
e.g.
I want to write a camelToSnake()
camelToSnake = (phrase) ->
return phrase.replace(/([A-Z])/g, /-\L$1/)
is there such options
You can use this code:
var s = 'camelToSnake';
var r = s.replace(/([A-Za-z])/g, function ($0, $1) { c=$1.charAt(0);
return (c==c.toUpperCase())?c.toLowerCase():c.toUpperCase(); } );
//=> CAMELtOsNAKE