-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
I tried to use your library using a regexp find and function replace, but spent 20 minutes getting my head round the options and console logging stuff to see what I needed to do. Eventually I gave up and I ended up writing a glob and doing it myself.
This was my use case - converting tags (with ml- prefix) from snake-case to PascalCase:
const Fs = require('fs')
const glob = require('glob')
// options
const options = { encoding:'utf8' }
// start
glob('./src/**/*.vue', function (er, files) {
// debug
console.log(`Processing ${files.length} files...`)
// process files
files.forEach(file => {
// variables
let count = 0
const text = Fs.readFileSync(file, options)
// replacement
const output = text.replace(/<\/?ml-[\w-]+/g, function (match, pos, all) {
count += 1
return match
.replace(/-\w/g, m => m.slice(1).toUpperCase())
.replace('ml', 'Ml')
})
// if replacements were made
if (count) {
Fs.writeFileSync(file, output, options)
console.log(count, file)
}
})
})With your lib I just didn't know what the replace function's arguments were, so specifically documenting an example would make it less ambiguous.
Thanks
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels