1.1.2 • Published 1 year ago

joi-relative-date-validator v1.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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

1.1.2

1 year ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago