mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-11-14 19:46:29 +08:00
35 lines
862 B
JavaScript
35 lines
862 B
JavaScript
|
const fs = require("fs");
|
||
|
const V = require("jsonschema").Validator;
|
||
|
const JSONValidator = new V();
|
||
|
|
||
|
function escapeRegExp(str) {
|
||
|
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||
|
}
|
||
|
|
||
|
function fixQuoteLengths() {
|
||
|
return new Promise((resolve, reject) => {
|
||
|
const quotesFiles = fs.readdirSync("../static/quotes/");
|
||
|
quotesFiles.forEach((quotefilename) => {
|
||
|
quotefilename = quotefilename.split(".")[0];
|
||
|
let quoteData = JSON.parse(
|
||
|
fs.readFileSync(`../static/quotes/${quotefilename}.json`, {
|
||
|
encoding: "utf8",
|
||
|
flag: "r",
|
||
|
})
|
||
|
);
|
||
|
|
||
|
quoteData.quotes.forEach((quote) => {
|
||
|
quote.length = quote.text.length;
|
||
|
});
|
||
|
|
||
|
fs.writeFileSync(
|
||
|
`../static/quotes/${quotefilename}.json`,
|
||
|
JSON.stringify(quoteData, null, 2)
|
||
|
);
|
||
|
});
|
||
|
resolve();
|
||
|
});
|
||
|
}
|
||
|
|
||
|
fixQuoteLengths();
|