Skip to content

Instantly share code, notes, and snippets.

@letanure
Created April 12, 2014 20:38
Show Gist options
  • Save letanure/10555668 to your computer and use it in GitHub Desktop.
Save letanure/10555668 to your computer and use it in GitHub Desktop.
text to braille
var brailleTable = {
'1': '⠼⠁',
'2': '⠼⠃',
'3': '⠼⠉',
'4': '⠼⠙',
'5': '⠼⠑',
'6': '⠼⠋',
'7': '⠼⠛',
'8': '⠼⠓',
'9': '⠼⠊',
'0': '⠼⠚',
'A': '⠠⠁',
'B': '⠠⠃',
'C': '⠠⠉',
'D': '⠠⠙',
'E': '⠠⠑',
'F': '⠠⠋',
'G': '⠠⠛',
'H': '⠠⠓',
'I': '⠠⠊',
'J': '⠠⠚',
'K': '⠠⠅',
'L': '⠠⠇',
'M': '⠠⠍',
'N': '⠠⠝',
'O': '⠠⠕',
'P': '⠠⠏',
'Q': '⠠⠟',
'R': '⠠⠗',
'S': '⠠⠎',
'T': '⠠⠞',
'U': '⠠⠥',
'V': '⠠⠧',
'W': '⠠⠺',
'X': '⠠⠭',
'Y': '⠠⠽',
'Z': '⠠⠵',
'a': '⠁',
'b': '⠃',
'c': '⠉',
'd': '⠙',
'e': '⠑',
'f': '⠋',
'g': '⠛',
'h': '⠓',
'i': '⠊',
'j': '⠚',
'k': '⠅',
'l': '⠇',
'm': '⠍',
'n': '⠝',
'o': '⠕',
'p': '⠏',
'q': '⠟',
'r': '⠗',
's': '⠎',
't': '⠞',
'u': '⠥',
'v': '⠧',
'w': '⠺',
'x': '⠭',
'y': '⠽',
'z': '⠵',
'\\.': '⠲',
',': '⠂',
'\\?': '⠦',
';': '⠆',
'!': '⠖',
'<': '⠦',
'>': '⠴',
'\\ ': '⠶',
'-': '⠤',
"'": '⠄',
}
function convertToBraille(text){
var brailleText = '';
for (var i = 0; i < text.length; i++) {
brailleText += brailleTable(text[i])
};
return brailleText;
}
@AnastasiaDunbar
Copy link

AnastasiaDunbar commented Jul 2, 2017

brailleTable(text[i]) should be brailleTable[text[i]]; and why are there backslashes in the brailleTable? It only reads a single character in the for-loop. You could also do text.split("").map(c=>brailleTable[c]).join("");.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment