firefish/packages/client/src/scripts/detect-language.ts

12 lines
340 B
TypeScript
Raw Normal View History

2023-10-10 23:28:06 +09:00
import * as mfm from "mfm-js";
2023-11-27 18:17:53 +09:00
import { detect } from "tinyld";
2023-10-10 23:28:06 +09:00
export default function detectLanguage(text: string): string {
const nodes = mfm.parse(text);
const filtered = mfm.extract(nodes, (node) => {
return node.type === "text" || node.type === "quote";
});
const purified = mfm.toString(filtered);
return detect(purified);
}