Last active
December 14, 2015 20:19
-
-
Save jugglinmike/5143417 to your computer and use it in GitHub Desktop.
A script to expand acronyms in text to their phonetic equivalents
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
// phonetic.js | |
// A script to expand acronyms in text to their phonetic equivalents | |
var defaultInput = "I am the illest MC that you ever SAW"; | |
var sounds = { | |
A: "ay", | |
B: "bee", | |
C: "see", | |
D: "dee", | |
E: "ee", | |
F: "eff", | |
G: "jee", | |
H: "aych", | |
I: "I", | |
J: "jay", | |
K: "kay", | |
L: "el", | |
M: "em", | |
N: "en", | |
O: "O", | |
P: "pee", | |
Q: "cue", | |
R: "ar", | |
S: "ess", | |
T: "tee", | |
U: "you", | |
V: "vee", | |
W: "double you", | |
X: "ex", | |
Y: "why", | |
Z: "zee" | |
}; | |
var input = process.argv.slice(2).join(" ") || defaultInput; | |
var expanded; | |
expanded = input.replace(/\b[A-Z]{2,}\b/g, function(letters) { | |
return letters.split("").map(function(letter) { | |
return sounds[letter]; | |
}).join(" "); | |
}); | |
console.log(expanded); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment