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

1.1.0 • Public • Published

Version License

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

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

License

MIT

Package Sidebar

Install

npm i jsonman

Weekly Downloads

0

Version

1.1.0

License

MIT

Unpacked Size

9.18 kB

Total Files

6

Last publish

Collaborators

  • zhmushan