1.1.0 • Published 4 years ago

field-verifier v1.1.0

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

📖 About

TODO

This package does not rely at dependency to work. Compatible to NodeJS and Browser code. The code is analyzed by ESLint and tested with Jest.

⬇️ Downloading

This module has few dependencies, so, this means that we are super light and quick to install, as you can see by downloading it with Npm:

$ npm i --save field-verifier

Or with Yarn:

$ npm i --save field-verifier

💻 Contributing

This is a small project, and I don't have any specific rules for contributions, you can modify anything and then make a pull-request and i'll analyze. Just be careful not to run away from the main idea of the package.

📚 Examples

import { validate } from 'field-verifier';

const input = {
  name: {
    firstName: 'John',
    lastName: { first: 'Smith', second: '' }
  },
  age: 12
};

const errors = await validate(input, ({ parse, validate }) => {
  parse('age', x => x > 1, 'a person cannot have an age lower than 1 year');

  validate('name', ({ parse, validate }) => {
    parse('firstName', n => n.length > 3, 'at least 3 characters length');

    validate('lastName', ({ parse }) => {
      // Rejects every condition
      parse('first', () => false, 'you got rejected :P');

      // Ignores the second name
    });
  });
});

// outputs: [ { field: 'name.firstName', message: 'at least 3 characters length' } ]
console.log(errors);

📃 License

Licensed under the MIT. See LICENSE for more informations.

📧 Contact

See my contact information on my GitHub Profile Page or open a new issue.

1.1.0

4 years ago

1.0.1

4 years ago