Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

joi-relative-date-validator

Ninad8917MIT1.1.2

Joi extension for relative date validation

joi, date, relative date, validation, api, express

readme

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.

  2. Import module

    import relativeDateValidator from 'joi-relative-date-validator'
  3. 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');
  2. 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