Skip to content

Instantly share code, notes, and snippets.

@Yaffle
Created March 28, 2018 14:26
Show Gist options
  • Save Yaffle/af5498d9e4fa5674fe5f4164a70fa506 to your computer and use it in GitHub Desktop.
Save Yaffle/af5498d9e4fa5674fe5f4164a70fa506 to your computer and use it in GitHub Desktop.
function replaceSimpleDigit(code) {
if (code >= 0x0660 && code <= 0x669) {
return {code: code - 0x0660 + 48, name: "arab"};
}
if (code >= 0x06F0 && code <= 0x6f9) {
return {code: code - 0x06F0 + 48, name: "arabext"};
}
if (code >= 0x0966 && code <= 0x96f) {
return {code: code - 0x0966 + 48, name: "deva"};
}
if (code >= 0x09E6 && code <= 0x9ef) {
return {code: code - 0x09E6 + 48, name: "beng"};
}
if (code >= 0x0A66 && code <= 0xa6f) {
return {code: code - 0x0A66 + 48, name: "guru"};
}
if (code >= 0x0AE6 && code <= 0xaef) {
return {code: code - 0x0AE6 + 48, name: "gujr"};
}
if (code >= 0x0B66 && code <= 0xb6f) {
return {code: code - 0x0B66 + 48, name: "orya"};
}
if (code >= 0x0BE6 && code <= 0xbef) {
return {code: code - 0x0BE6 + 48, name: "tamldec"};
}
if (code >= 0x0C66 && code <= 0xc6f) {
return {code: code - 0x0C66 + 48, name: "telu"};
}
if (code >= 0x0CE6 && code <= 0xcef) {
return {code: code - 0x0CE6 + 48, name: "knda"};
}
if (code >= 0x0D66 && code <= 0xd6f) {
return {code: code - 0x0D66 + 48, name: "mlym"};
}
if (code >= 0x0E50 && code <= 0xe59) {
return {code: code - 0x0E50 + 48, name: "thai"};
}
if (code >= 0x0ED0 && code <= 0xed9) {
return {code: code - 0x0ED0 + 48, name: "laoo"};
}
if (code >= 0x0F20 && code <= 0xf29) {
return {code: code - 0x0F20 + 48, name: "tibt"};
}
if (code >= 0x1040 && code <= 0x1049) {
return {code: code - 0x1040 + 48, name: "mymr"};
}
if (code >= 0x17E0 && code <= 0x17e9) {
return {code: code - 0x17E0 + 48, name: "khmr"};
}
if (code >= 0x1810 && code <= 0x1819) {
return {code: code - 0x1810 + 48, name: "mong"};
}
if (code >= 0x1946 && code <= 0x194f) {
return {code: code - 0x1946 + 48, name: "limb"};
}
if (code >= 0x1B50 && code <= 0x1b59) {
return {code: code - 0x1B50 + 48, name: "bali"};
}
if (code >= 0xFF10 && code <= 0xff19) {
return {code: code - 0xFF10 + 48, name: "fullwide"};
}
return undefined;
}
function convertInput(string) {
return string.replace(/[\s\S]/g, function (s) {
var digit = replaceSimpleDigit(s.charCodeAt(0));
if (digit != undefined) {
// TODO: remove
console.log({fs: digit.name});
return String.fromCharCode(digit.code);
}
return s;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment