Add underscore, camelize and dasherize to underscore

This commit is contained in:
Corey Johnson
2013-02-12 17:36:03 -08:00
parent 7ff0450379
commit 52d4723711
2 changed files with 43 additions and 0 deletions

View File

@@ -69,6 +69,25 @@ _.mixin
else
"#{count} #{plural}"
camelize: (string) ->
string.replace /[_-]+(\w)/g, (m) -> m[1].toUpperCase()
dasherize: (string) ->
string = string[0].toLowerCase() + string[1..]
string.replace /([A-Z])|(_)/g, (m, letter, underscore) ->
if letter
"-" + letter.toLowerCase()
else
"-"
underscore: (string) ->
string = string[0].toLowerCase() + string[1..]
string.replace /([A-Z])|(-)/g, (m, letter, dash) ->
if letter
"_" + letter.toLowerCase()
else
"_"
losslessInvert: (hash) ->
inverted = {}
for key, value of hash