1.1.2 • Published 1 year ago

mystical-wind-validator v1.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

mystical-wind-validator

NPM Version License

A versatile data validator library for JavaScript using JSON schemas powered by Ajv.

Installation

You can install the library via npm:

npm install mystical-wind-validator

Usage

const validate = require('mystical-wind-validator');

// Define your JSON schema
const schema = {
  type: 'object',
  properties: {
    name: { type: 'string' },
    age: { type: 'number', minimum: 0 },
    email: { type: 'string', format: 'email' },
  },
  required: ['name', 'age', 'email'],
};

// Data to be validated
const data = {
  name: 'John Doe',
  age: 30,
  email: 'john@example.com',
};

// Validate the data against the schema
const isValid = validate(schema, data);

if (isValid) {
  console.log('Data is valid!');
} else {
  console.error('Data is invalid.');
}

API

validate(schema, data)

Validate an object against a JSON schema.

  • schema (object): JSON schema to validate against.
  • data (object): Data to be validated.
  • Returns true if data is valid, false otherwise.
  • Throws an Error if schema compilation fails.

License

This project is licensed under the MIT License - see the LICENSE file for details.

1.1.2

1 year ago

1.1.1

1 year ago

1.0.0

1 year ago