nato Encode/decode NATO phonetic alphabet
Flags
--decode boolean default: false
Examples
Spell a license key for phone support
Usage
"xK9-mQ2z" | nato Read a booking confirmation code to a customer over the phone
Usage
"CONF-7B3X" | nato Communicate a serial number clearly to a colleague
Usage
"SN-482-FGH" | nato View source
(input, opts = {})=>{
const alpha = {
A: "Alfa",
B: "Bravo",
C: "Charlie",
D: "Delta",
E: "Echo",
F: "Foxtrot",
G: "Golf",
H: "Hotel",
I: "India",
J: "Juliett",
K: "Kilo",
L: "Lima",
M: "Mike",
N: "November",
O: "Oscar",
P: "Papa",
Q: "Quebec",
R: "Romeo",
S: "Sierra",
T: "Tango",
U: "Uniform",
V: "Victor",
W: "Whiskey",
X: "X-ray",
Y: "Yankee",
Z: "Zulu"
};
const digits = {
0: "Zero",
1: "One",
2: "Two",
3: "Three",
4: "Four",
5: "Five",
6: "Six",
7: "Seven",
8: "Eight",
9: "Niner"
};
if (opts.decode) {
const rev = {};
for (const [k, v] of Object.entries(alpha))rev[v.toLowerCase()] = k.toLowerCase();
for (const [k, v] of Object.entries(digits))rev[v.toLowerCase()] = k;
return input.split("\n").map((line)=>line.split(/\s+/).map((w)=>rev[w.toLowerCase()] ?? w).join("")).join("\n");
}
return input.split("\n").map((line)=>[
...line
].map((c)=>{
const u = c.toUpperCase();
return alpha[u] || digits[c] || c;
}).join(" ")).join("\n");
}