mirror of
https://github.com/seigler/natospell
synced 2025-07-26 00:26:09 +00:00
⚡ add proper support for numerals and symbols, fixes #3
This commit is contained in:
parent
ea1b020651
commit
674be89341
1 changed files with 83 additions and 9 deletions
92
main.js
92
main.js
|
@ -1,19 +1,21 @@
|
|||
(function () {
|
||||
"use strict";
|
||||
var words, inputElement, outputElement;
|
||||
var symbols, inputElement, outputElement;
|
||||
|
||||
function translate(input) {
|
||||
var i, length, output, key, a = 'a'.charCodeAt(0), z = 'z'.charCodeAt(0);
|
||||
var i, length, output, key;
|
||||
input = input.toLowerCase();
|
||||
output = "";
|
||||
length = input.length;
|
||||
for (i = 0; i < length; i += 1) {
|
||||
key = input.charCodeAt(i) - a;
|
||||
if (key >= 0 && key <= 26) {
|
||||
if (i > 0) {
|
||||
output += " ";
|
||||
}
|
||||
output += words[key];
|
||||
key = input.charAt(i);
|
||||
if (i > 0) {
|
||||
output += " ";
|
||||
}
|
||||
if (symbols.hasOwnProperty(key)) {
|
||||
output += symbols[key];
|
||||
} else {
|
||||
output += key;
|
||||
}
|
||||
}
|
||||
return output;
|
||||
|
@ -24,7 +26,79 @@
|
|||
}
|
||||
|
||||
function init() {
|
||||
words = [ "Alfa", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot", "Golf", "Hotel", "India", "Juliett", "Kilo", "Lima", "Mike", "November", "Oscar", "Papa", "Quebec", "Romeo", "Sierra", "Tango", "Uniform", "Victor", "Whiskey", "X-ray", "Yankee", "Zulu" ];
|
||||
symbols = {
|
||||
'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',
|
||||
'0': 'Zero',
|
||||
'1': 'One',
|
||||
'2': 'Two',
|
||||
'3': 'Three',
|
||||
'4': 'Four',
|
||||
'5': 'Five',
|
||||
'6': 'Six',
|
||||
'7': 'Seven',
|
||||
'8': 'Eight',
|
||||
'9': 'Nine',
|
||||
' ': 'Space',
|
||||
'.': 'Dot',
|
||||
',': 'Comma',
|
||||
';': 'Semicolon',
|
||||
':': 'Colon',
|
||||
'?': 'Question-Mark',
|
||||
'!': 'Exclamation-Mark',
|
||||
'@': 'At-Sign',
|
||||
'&': 'Ampersand',
|
||||
'"': 'Double-Quotation-Mark',
|
||||
'': 'Apostrophe',
|
||||
'-': 'Dash',
|
||||
'/': 'Forward-Slash',
|
||||
'\\': 'Backslash',
|
||||
'(': 'Left-Parenthesis',
|
||||
')': 'Right-Parenthesis',
|
||||
'[': 'Left-Square-Bracket',
|
||||
']': 'Right-Square-Bracket',
|
||||
'{': 'Left-Curly-Bracket',
|
||||
'}': 'Right-Curly-Bracket',
|
||||
'<': 'Left-Angle-Bracket',
|
||||
'>': 'Right-Angle-Bracket',
|
||||
'|': 'Pipe',
|
||||
'°': 'Degree-Symbol',
|
||||
'*': 'Asterisk',
|
||||
'+': 'Plus-Sign',
|
||||
'=': 'Equal-Sign',
|
||||
'#': 'Number-Sign',
|
||||
'§': 'Section-Sign',
|
||||
'$': 'Dollar-Sign',
|
||||
'€': 'Euro-Sign',
|
||||
'~': 'Tilde',
|
||||
'_': 'Underscore',
|
||||
'%': 'Percent-Sign',
|
||||
'^': 'Caret'
|
||||
};
|
||||
inputElement = document.getElementById("inputElement");
|
||||
outputElement = document.getElementById("outputElement");
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue