shinrox
6/3/2019 - 5:47 AM

LIVR example with extended error

LIVR example with extended error

import LIVR from 'livr';

const livrRules = {
  material_id: ['required', 'positive_integer'],
  quantity: ['required', {'min_number': 1} ]
};

const invalidOrder = {
  material_id: 100,
  quantity: 0,
};

LIVR.validate(livrRules, invalidOrder);
// { quantity: { code: 'TOO_LOW', rule: { 'min_number': 1 } } }
// Now that previous error has more info that you can use to create
// a friendly error message to your users ;)