aboutsummaryrefslogtreecommitdiff
path: root/dev/dictionary-validate.js
diff options
context:
space:
mode:
authorDarius Jahandarie <djahandarie@gmail.com>2023-11-09 13:30:31 +0000
committerGitHub <noreply@github.com>2023-11-09 13:30:31 +0000
commit5c5a167b4792af379cdacf633513cebf20728cd2 (patch)
tree5b6be3620a557d0b9177047003f6d742d9d2a32d /dev/dictionary-validate.js
parentb64f51c3b13a46af4dd7f1e43048ac19c781ca7b (diff)
parent0f4d36938fd0d844f548aa5a7f7e7842df8dfb41 (diff)
Merge pull request #307 from themoeway/modernize
Modernize codebase
Diffstat (limited to 'dev/dictionary-validate.js')
-rw-r--r--dev/dictionary-validate.js49
1 files changed, 8 insertions, 41 deletions
diff --git a/dev/dictionary-validate.js b/dev/dictionary-validate.js
index 0c926acc..eb40beda 100644
--- a/dev/dictionary-validate.js
+++ b/dev/dictionary-validate.js
@@ -16,12 +16,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-const fs = require('fs');
-const path = require('path');
-const {performance} = require('perf_hooks');
-const {JSZip} = require('./util');
-const {createJsonSchema} = require('./schema-validate');
-
+import fs from 'fs';
+import JSZip from 'jszip';
+import path from 'path';
+import {performance} from 'perf_hooks';
+import {createJsonSchema} from './schema-validate.js';
function readSchema(relativeFileName) {
const fileName = path.join(__dirname, relativeFileName);
@@ -29,7 +28,6 @@ function readSchema(relativeFileName) {
return JSON.parse(source);
}
-
async function validateDictionaryBanks(mode, zip, fileNameFormat, schema) {
let jsonSchema;
try {
@@ -57,7 +55,7 @@ async function validateDictionaryBanks(mode, zip, fileNameFormat, schema) {
}
}
-async function validateDictionary(mode, archive, schemas) {
+export async function validateDictionary(mode, archive, schemas) {
const fileName = 'index.json';
const indexFile = archive.files[fileName];
if (!indexFile) {
@@ -82,7 +80,7 @@ async function validateDictionary(mode, archive, schemas) {
await validateDictionaryBanks(mode, archive, 'tag_bank_?.json', schemas.tagBankV3);
}
-function getSchemas() {
+export function getSchemas() {
return {
index: readSchema('../ext/data/schemas/dictionary-index-schema.json'),
kanjiBankV1: readSchema('../ext/data/schemas/dictionary-kanji-bank-v1-schema.json'),
@@ -95,8 +93,7 @@ function getSchemas() {
};
}
-
-async function testDictionaryFiles(mode, dictionaryFileNames) {
+export async function testDictionaryFiles(mode, dictionaryFileNames) {
const schemas = getSchemas();
for (const dictionaryFileName of dictionaryFileNames) {
@@ -115,33 +112,3 @@ async function testDictionaryFiles(mode, dictionaryFileNames) {
}
}
}
-
-
-async function main() {
- const dictionaryFileNames = process.argv.slice(2);
- if (dictionaryFileNames.length === 0) {
- console.log([
- 'Usage:',
- ' node dictionary-validate [--ajv] <dictionary-file-names>...'
- ].join('\n'));
- return;
- }
-
- let mode = null;
- if (dictionaryFileNames[0] === '--ajv') {
- mode = 'ajv';
- dictionaryFileNames.splice(0, 1);
- }
-
- await testDictionaryFiles(mode, dictionaryFileNames);
-}
-
-
-if (require.main === module) { main(); }
-
-
-module.exports = {
- getSchemas,
- validateDictionary,
- testDictionaryFiles
-};