1.1.0 • Published 6 years ago
jsonman v1.1.0
Simplified JSON analyzer
Install
$ yarn add jsonman
or
$ npm i jsonman
Usage
const jsonman = require('jsonman')
const schema = jsonman.analyzer({ string: '', str: 'str', number: 0, num: 1, boolean: false, bool: true, object: {}, obj: { arr: 1, { num: 0 } }, array: [], arr: 1, { num: 1 } })
const data = { str: '', num: 0, bool: false, obj: { arr: 0, {} }, arr: 0, { num: 0 } }
console.log(jsonman.validator(schema, data)) // true
## API
```ts
type Types = 'object' | 'array' | 'number' | 'string' | 'boolean';
type SchemaObject = {
[index: string]: SchemaItem;
};
type SchemaItem = {
types: Types[];
unique?: boolean;
items?: SchemaItem[];
properties?: SchemaObject;
};
type DataObject = {
[index: string]: DataItem;
};
type DataItem = object | number | string | boolean;
type CanAnalyzed = {
(data: DataObject): SchemaObject;
(data: DataItem): SchemaItem;
};
validator: (schema: SchemaObject, data: DataObject) => boolean;
analyzer: CanAnalyzed;
License
MIT