Reputation: 6368
e.g.
I want to write a camelToSnake()
camelToSnake = (phrase) ->
return phrase.replace(/([A-Z])/g, /-\L$1/)
is there such options
Upvotes: 2
Views: 212
Reputation: 785108
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
Upvotes: 1