Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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