Created
July 10, 2018 07:19
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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