@satisfactory-dev/ajv-utilities
v0.1.1
Published
Ajv Utilities
Downloads
52
Readme
Installation
npm install --save-dev @satisfactory-dev/ajv-utilities
Usage
compile
import Ajv from 'ajv/dist/2020';
import {compile, FailedToCompileSchema} from '@satisfactory-dev/ajv-utilities';
const schema = {type: 'string'};
try {
const check = compile(new Ajv(), schema);
} catch (err) {
if (err instanceof FailedToCompileSchema) {
console.error('failed to compile', err);
} else {
console.error('unknown error', err);
}
}
esmify
import Ajv from 'ajv/dist/2020';
import standalone from 'ajv/dist/standalone';
import {compile, esmify} from '@satisfactory-dev/ajv-utilities';
const ajv = new Ajv();
await writeFile(
'./standalone-validator.mjs',
esmify(standalone(ajv, compile(ajv, schema)))
);