Two short, copy-pasteable gists built on the bijoy2unicode npm package.
1. Bijoy → Unicode in a few lines
import { convertBijoyToUnicode } from "bijoy2unicode";
console.log(convertBijoyToUnicode("Avgvi †mvbvi evsjv"));
// আমার সোনার বাংলা
Don't copy a hand-rolled mapping table: the package already handles reph, conjuncts and other SutonnyMJ quirks.
Gist: https://gist.github.com/JehadurRE/60c4fc89abe9e50e9746d12be9417832
2. Check before you convert
import { convertBijoyToUnicode, shouldConvertAsBijoy } from "bijoy2unicode";
function safeConvert(text: string, fontIsBijoy?: boolean): string {
return shouldConvertAsBijoy(text, fontIsBijoy) ? convertBijoyToUnicode(text) : text;
}
safeConvert("Date of Birth"); // unchanged
safeConvert("আমার সোনার বাংলা"); // unchanged (already Unicode)
Gist: https://gist.github.com/JehadurRE/1492d905a0692671d2278e515987a05c
The limit worth knowing
A string-level check answers "is there Bijoy in here?", not "which part is Bijoy?". If one string mixes English and Bijoy, converting it will also mangle the English. Documents solve this with fonts: in a .docx, convertDocx looks at each run's effective font and only converts runs set in a Bijoy font. I wrote about that here: English in Calibri survived.
Try the converter in your browser: https://bijoy2unicode.jehadurre.me · Source (MIT): https://github.com/JehadurRE/Bijoy2Unicode
Top comments (0)