ajv-filter
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

Ajv Filter

Library that enables ajv to filter objects, rather than just validating them.

Install

npm install --save ajv-filter

Usage

import AJV from 'ajv';
import Filter from 'ajv-filter';
 
const Schema = {
  type: 'object',
  properties: {
    foo: {
      type: 'string'
    },
    bar: {
      type: 'number'
    }
  }
};
 
const Data = {
  foo: 'string',
  bar: '123'
};
 
const ajv = Filter.patchInstance ( new AJV () ); // <- patching the instance
const validate = ajv.compile ( Filter.patchSchema ( schema ) ); // <- patching the schema
 
validate ( Data ); // => false
console.log ( Data ); // { foo: 'string' }
validate ( Data ); // => true

License

MIT © Fabio Spampinato

Readme

Keywords

Package Sidebar

Install

npm i ajv-filter

Weekly Downloads

2

Version

1.1.1

License

MIT

Unpacked Size

13.2 kB

Total Files

15

Last publish

Collaborators

  • fabiospampinato