pashto-grammar/scripts/misc-query.js

91 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-03-06 10:40:31 +00:00
const fs = require("fs");
const fetch = require("node-fetch");
const path = require("path");
const verbsPath = path.join(".", "src", "words");
const pChars = [
"آ",
'ځ',
'څ',
'ښ',
'ئ',
'ي',
'پ',
'ټ',
'ڼ',
'ظ',
'ط',
'ژ',
'ډ',
'ض',
'ص',
'ث',
'ق',
'ف',
'غ',
'ع',
'ه',
'خ',
'ح',
'ج',
'چ',
'ش',
'س',
'ی',
'ب',
'ل',
'ا',
'ت',
'ن',
'م',
'ک',
'ګ',
'ۍ',
'ې',
'ز',
'ر',
'ذ',
'د',
'ړ',
'و',
'ږ',
];
2021-03-06 10:40:31 +00:00
2022-04-26 08:08:32 +00:00
fetch(process.env.LINGDOCS_DICTIONARY_URL + ".json").then(res => res.json()).then(data => {
const { entries } = data;
const filtered = shuffle(entries.filter(e => (
2022-04-26 08:08:32 +00:00
e.c?.includes("loc. adv.")
)));
2022-02-27 12:27:36 +00:00
const content = `module.exports = [
${filtered.reduce((text, entry) => (
text + `{ ts: ${entry.ts}, e: \`${entry.e.replace(/"/g, '\\"')}\` }, // ${entry.p} - ${entry.f}
`), "")}
2021-03-06 10:40:31 +00:00
];`;
2022-02-27 12:27:36 +00:00
// const content = `export const WORDS = [
// ${filtered.map((entry) => (entry.p.replace("آ", "ا"))).reduce((text, p) => (
// text + `"${p}",\n`
// ), "")}
// ];`;
fs.writeFileSync(path.join(verbsPath, "wordle-words.ts"), content);
2021-03-06 10:40:31 +00:00
});
function shuffle(array) {
let currentIndex = array.length, randomIndex;
// While there remain elements to shuffle...
while (currentIndex != 0) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex--;
// And swap it with the current element.
[array[currentIndex], array[randomIndex]] = [
array[randomIndex], array[currentIndex]];
}
return array;
}