Skip to content

Instantly share code, notes, and snippets.

@andreiglingeanu
Created December 24, 2019 09:50
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 andreiglingeanu/a6a28da8b5e4f8c1c28aa3f7bd5872db to your computer and use it in GitHub Desktop.
Save andreiglingeanu/a6a28da8b5e4f8c1c28aa3f7bd5872db to your computer and use it in GitHub Desktop.
// Make all variables dashed-case
// USAGE:
// ack -l -- '--\b' | xargs node replace-vars.js
const { readFileSync, writeFileSync } = require('fs')
const [_, __, ...files] = process.argv
console.log(files)
const camelCaseToDash = myStr =>
myStr.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()
files
.filter(f => f !== 'LICENSE')
.map(file => {
const contents = readFileSync(file).toString()
const newContents = contents.replace(
/--(\w+)/g,
(match, p1) => `--${camelCaseToDash(p1)}`
)
writeFileSync(file, newContents)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment