Perf over function

This commit is contained in:
Lim Chee Aun 2024-05-29 10:23:46 +08:00
parent d5584f8dd4
commit f9a73777e7

View file

@ -161,6 +161,11 @@ const SIZE_CLASS = {
};
const detectLang = mem((text) => {
// Ref: https://github.com/komodojp/tinyld/blob/develop/docs/benchmark.md
// 500 should be enough for now, also the default max chars for Mastodon
if (text?.length > 500) {
return null;
}
const langs = detectAll(text);
const lang = langs[0];
if (lang?.lang && lang?.accuracy > 0.5) {