Skip to content

Instantly share code, notes, and snippets.

@paulmillr
Created June 9, 2012 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulmillr/2901194 to your computer and use it in GitHub Desktop.
Save paulmillr/2901194 to your computer and use it in GitHub Desktop.
Add dashes to CoffeeScript source. toString ⇒ to-string. Issue #2370
fs = require 'fs'
# Usage: coffee replace-to-dashes.coffee src/**/*
replaceFile = (path) ->
fs.readFile path, (error, data) ->
return console.log error if error?
result = data
.toString()
.replace /([a-z])([A-Z])([a-z])/g, ($0, $1, $2, $3) ->
$1 + '-' + $2.toLowerCase() + $3
console.log 'Replacing', path
fs.writeFile path, result
replaceFiles = (paths) ->
paths.forEach replaceFile
replaceFiles process.argv[2..]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment