joi-relative-date-validator

1.1.2 • Public • Published

Joi Relative Date Validator

NPM

CircleCI FOSSA Status

Install

npm install joi-relative-date-validator

How to use

  1. First import @hapi/Joi
import Joi from @hapi/Joi

Note: This module does not install Joi automatically. You need to add it to your dependency.

  1. Import module
import relativeDateValidator from 'joi-relative-date-validator'
  1. Extend Joi
const custom = Joi.extend(relativeDateValidator());
const schema: Schema = custom.relativeDate().within(2, 'd');
  1. Generate Schema
const schema: Schema = custom.relativeDate().within(2, 'd');
  1. And finally validate
schema.validate('2018-10-31');

schema.validate(new Date(2018-10-31T00:00:00));

schema.validate(moment());

More examples in src/index.test.ts file.

Points good to note

  • Joi.Date is base type of this validator.
  • Internally it uses Moment.js, so you can pass any moment parsable date to validator function

License

FOSSA Status

Package Sidebar

Install

npm i joi-relative-date-validator

Weekly Downloads

0

Version

1.1.2

License

MIT

Unpacked Size

8.95 kB

Total Files

8

Last publish

Collaborators

  • ninad