Skip to content

Instantly share code, notes, and snippets.

@tlux
Last active December 17, 2015 09:59
Show Gist options
  • Select an option

  • Save tlux/5591468 to your computer and use it in GitHub Desktop.

Select an option

Save tlux/5591468 to your computer and use it in GitHub Desktop.
underscore.coffee
String::camelize = ->
pieces = @split(/[\W_-]/)
$.map(pieces, (piece) -> piece.capitalize()).join("")
String::capitalize = ->
@charAt(0).toUpperCase() + @slice(1)
String::dasherize = ->
@replace("_", "-")
String::underscore = ->
@replace(/[\W]/g, "").replace /[A-Z]/g, (match) ->
"_#{match.toLowerCase()}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment