MCPcopy Create free account
hub / github.com/Vishal-raj-1/Awesome-JavaScript-Projects / textScript

Function textScript

assets/js/scriptDetection/Script.js:28–42  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

26loadData();
27
28function textScript(text) {
29 let scripts = countBy(text, (char) => {
30 let script = characterScript(char.codePointAt(0));
31 return script ? script.name : "none";
32 }).filter(({ name }) => name != "none");
33
34 let total = scripts.reduce((n, { count }) => n + count, 0);
35 if (total == 0) return "No scripts found";
36
37 return scripts
38 .map(({ name, count }) => {
39 return `${Math.round((count * 100) / total)}% ${name}`;
40 })
41 .join(",");
42}
43
44function countBy(items, groupName) {
45 let counts = [];

Callers 1

loadDataFunction · 0.85

Calls 2

countByFunction · 0.85
characterScriptFunction · 0.85

Tested by

no test coverage detected