joi-duration-extensions
v1.0.1
Published
Joi extension for file sizes
Downloads
2
Maintainers
Readme
joi-duration-extensions
Joi extensions for durations.
Lead Maintainer: Tom Yam
Durations are parsed with zeit/ms. All issues regarding parsing should be opened there.
Usage
Usage is a two steps process. First, a schema is constructed using the provided types and constraints:
const BaseJoi = require('joi');
const Extension = require('joi-duration-extensions');
const Joi = BaseJoi.extend(Extension);
Joi.validate('1y', Joi.number().msDuration()).value // 31557600000
Joi.validate('2 days', Joi.number().msDuration()).value // 172800000
Joi.validate('1d', Joi.number().msDuration()).value // 86400000
Joi.validate('10h', Joi.number().msDuration()).value // 36000000
Joi.validate('2.5 hrs', Joi.number().msDuration()).value // 9000000
Joi.validate('100', Joi.number().msDuration()).value // 100
// If value cannot be parsed it's an error
Joi.validate('1 XX', Joi.number().msDuration()).error.message // "value" must be a valid ms duration'
API
See the API Reference.
Based on hapijs/joi-date-extensions