Skip to content

Latest commit

 

History

History
42 lines (31 loc) · 1.13 KB

README.md

File metadata and controls

42 lines (31 loc) · 1.13 KB

Coverage Status Workflow Status

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)))
);