Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@M-ZubairAhmed
Created July 10, 2018 07:19
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 M-ZubairAhmed/b1fd699a1c5d058ab57724e33e07a44b to your computer and use it in GitHub Desktop.
Save M-ZubairAhmed/b1fd699a1c5d058ab57724e33e07a44b to your computer and use it in GitHub Desktop.
Simple node program that normalizes string of react int to be used as ids in translation json file
const readline = require('readline');
var ncp = require('copy-paste');
const inputMessage = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
// Promt to enter the string eg.
// This ain't your username, is it?
inputMessage.question('Enter raw message\n', answer => {
// Converted all non alpha character to underscore
let generatedId = answer.toLowerCase().replace(/[^A-Z0-9]+/gi, '_');
// Removing last underscore if any
if (generatedId.charAt(generatedId.length - 1) === '_') {
generatedId = generatedId.substring(0, generatedId.length - 1);
}
// Removing first underscore if any
if (generatedId.charAt(0) === '_') {
generatedId = generatedId.substring(1);
}
// output eg.
// this_ain_t_your_username_is_it
console.log(generatedId);
// Copy the converted string to clipboard
ncp.copy(generatedId, function() {
inputMessage.close();
process.exit();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment