0.1.4 • Published 4 years ago

client-json-validation v0.1.4

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

Client JSON validation

Lightweight client side JSON validator with zero dependencies

Installation

npm i -S client-json-validation

Usage

// Import lib
import {object, string, array, number} from 'client-json-validation';
// Import target locale
import en from 'client-json-validation/lib/texts/en';

// Set localization once (en|ru)
setLocale(en);

// Create a schema
const schema = object({
  items: array(
    object({
      cost: number(),
      title: string().required()
    })
  ).min(1)
});

// Run validate function
schema.validate({
  items: [
    {cost: 100, title: 'T-Shirt'},
    {title: 'Bag'}
  ]
}); // Returns null

schema.validate({
  items: [
    {cost: 'one hundred', title: 'T-Shirt'},
    {title: 'Bag'}
  ]
}); // Returns {items: {0: {cost: 'Value is not a number'}}}}
0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.0.21

4 years ago

0.0.22

4 years ago

0.0.23

4 years ago

0.1.0

4 years ago

0.0.20

4 years ago

0.0.19

4 years ago

0.0.18

4 years ago

0.0.16

4 years ago

0.0.17

4 years ago

0.0.15

4 years ago

0.0.14

4 years ago

0.0.13

4 years ago

0.0.12

4 years ago

0.0.10

4 years ago

0.0.11

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.5

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.4

4 years ago

0.0.1

4 years ago