diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2023-12-19 00:33:38 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-19 05:33:38 +0000 |
commit | 1ced9aafc00c10992bab8bd3f1b6b1397f05b7b9 (patch) | |
tree | 305bb2b3bfc7fc3b051ee1cd3d1c35f442af0de4 /dev/util.js | |
parent | 5f96276fda93dcad39f2165fd3c8d890aa5f9be5 (diff) |
Make JSON.parse usage safer (#373)
* Make JSON.parse usage safer
* Fix any type
* Add readResponseJson
* Use readResponseJson
* Additional updates
* Rename files
* Add types
Diffstat (limited to 'dev/util.js')
-rw-r--r-- | dev/util.js | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/dev/util.js b/dev/util.js index f45966c4..6a7fa8f5 100644 --- a/dev/util.js +++ b/dev/util.js @@ -19,6 +19,7 @@ import fs from 'fs'; import JSZip from 'jszip'; import path from 'path'; +import {parseJson} from './json.js'; /** * @param {string[]} args @@ -112,9 +113,9 @@ export function createDictionaryArchive(dictionaryDirectory, dictionaryName) { for (const fileName of fileNames) { if (/\.json$/.test(fileName)) { const content = fs.readFileSync(path.join(dictionaryDirectory, fileName), {encoding: 'utf8'}); - const json = JSON.parse(content); + const json = parseJson(content); if (fileName === 'index.json' && typeof dictionaryName === 'string') { - json.title = dictionaryName; + /** @type {import('dictionary-data').Index} */ (json).title = dictionaryName; } archive.file(fileName, JSON.stringify(json, null, 0)); |