Skip to content

Instantly share code, notes, and snippets.

@jtrim
Created November 28, 2012 18:54
Show Gist options
  • Select an option

  • Save jtrim/4163244 to your computer and use it in GitHub Desktop.

Select an option

Save jtrim/4163244 to your computer and use it in GitHub Desktop.
Takes a string as the only argument and "dasherizes" it
# Dasherizes a string
#
# Usage:
#
# _.dasherize("Foo_Bar") #=> 'foo-bar'
# _.dasherize("FooBar") #=> 'foo-bar'
# _.dasherize("foo_bar") #=> 'foo-bar'
# _.dasherize("foo-bar_Baz") #=> 'foo-bar-baz'
#
dasherize: (string) ->
string.replace /([_A-Z])+/g, (m) ->
m.replace(/_/, '-').toLowerCase()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment