@hestia-earth/schema-validation
TypeScript icon, indicating that this package has built-in type declarations

27.1.0 • Public • Published

Hestia Schema Validation

Module to validate data using the Hestia Schema and Ajv.

Install

npm install @hestia-earth/schema @hestia-earth/schema-validation

Example validating JSON

const { SchemaType } = require('@hestia-earth/schema');
const { validator } = require('@hestia-earth/schema-validation/validate');

// Set to `true` to validate existing Nodes (@type/@id) or `false` for Nodes to upload (type/id)
const strictMode = false;
// Initialise the validation function, do this only once
const schemaValidation = validator(undefined, strictMode);

const node = {
  type: SchemaType.Cycle,
  id: 'my first cycle'
};

(async () => {
  const { success, errors } = await schemaValidation(node);
  console.log(success);
  // list of errors in Ajv formatting. See https://github.com/ajv-validator/ajv/tree/v6.12.6#validation-errors
  console.log(errors);
})();

Package Sidebar

Install

npm i @hestia-earth/schema-validation

Weekly Downloads

475

Version

27.1.0

License

MIT

Unpacked Size

29.9 kB

Total Files

20

Last publish

Collaborators

  • mebibou