Created
October 15, 2019 12:27
-
-
Save macleginn/b0348decf69c2e5a8ea43ea1e37ef34a to your computer and use it in GitHub Desktop.
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
// A JS version of Python's "get" method for dicts. | |
function get(dict: object, key: any, plug: any) { | |
if (dict.hasOwnProperty(key)) | |
return dict[key]; | |
else | |
return plug; | |
} | |
function convertToUnicode(input: string): string { | |
const aleph = "ꜣ", | |
ayin = "ꜥ", | |
yodsmall = "i͗", | |
yodcap = "I͗", | |
kdotsmall = "ḳ", | |
kdotcap = "Ḳ", | |
saccentsmall = "ś", | |
saccentcap = "Ś", | |
equal = "⸗"; | |
const charMap = { | |
'!': 'H', | |
'#': 'Ḫ', | |
'$': 'H̱', | |
'%': 'S', | |
'*': 'Ṯ', | |
'+': 'Ḏ', | |
'=': equal, | |
'@': 'Ḥ', | |
'A': aleph, | |
'&': 'T', | |
'C': saccentcap, | |
'D': 'ḏ', | |
'H': 'ḥ', | |
'I': yodcap, | |
'O': 'Q', | |
'Q': kdotcap, | |
'S': 'š', | |
'T': 'ṯ', | |
'V': 'h̭', | |
'X': 'ẖ', | |
'^': 'Š', | |
'_': 'D', | |
'a': ayin, | |
'c': saccentsmall, | |
'i': yodsmall, | |
'o': 'q', | |
'q': kdotsmall, | |
'v': 'ṱ', | |
'x': 'ḫ' | |
}; | |
return input.split('') | |
.map(c => get(charMap, c, c)) | |
.join(''); | |
} | |
function test1() { | |
const input = `@tp di nsw Wsir nb +dw, nTr aA, nb AbDw, | |
di.f prt-xrw (m) t Hnqt, kAw Apdw, Ss mnxt, | |
xt nbt nfrt wabt anxt nTr im, | |
n kA n imAxy %-n-wsrt, mAa-xrw`; | |
const reference = `Ḥtp di͗ nsw Wsi͗r nb Ḏdw, nṯr ꜥꜣ, nb ꜣbḏw, | |
di͗.f prt-ḫrw (m) t ḥnḳt, kꜣw ꜣpdw, šs mnḫt, | |
ḫt nbt nfrt wꜥbt ꜥnḫt nṯr i͗m, | |
n kꜣ n i͗mꜣḫy S-n-wsrt, mꜣꜥ-ḫrw`; | |
const output = convertToUnicode(input); | |
console.assert(output === reference); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment