Skip to content

Instantly share code, notes, and snippets.

@SSARCandy
Created January 28, 2016 11:15
Show Gist options
  • Select an option

  • Save SSARCandy/421d3c3caf4cf9353549 to your computer and use it in GitHub Desktop.

Select an option

Save SSARCandy/421d3c3caf4cf9353549 to your computer and use it in GitHub Desktop.
Converting snake_case to camelCase
/**
* Converting snake_case to camelCase
* usage: node snakeToCamel.js <src> <dst>
*
* 2015/01/28 by SSARCandy
*/
const fs = require('fs');
function snakeToCamel(s) {
return s.replace(/(_\w)/g, function(m) {
return m[1].toUpperCase();
});
}
function convert(savPath, srcPath) {
fs.readFile(srcPath, 'utf8', function(err, data) {
if (err) throw err;
var fileWithCamel = snakeToCamel(data);
fs.writeFile(savPath, fileWithCamel, function(err) {
if (err) throw err;
console.log('complete');
process.exit(0);
});
});
}
if (process.argv.length < 4) {
console.error('Argument too few.');
throw '[USAGE] node snakeToCamel.js <src> <dst>';
}
var src = process.argv[2];
var dst = process.argv[3];
convert(dst, src);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment