Semver extension for the Joi validation library
const { semver, semverRange } = require('joi-extension-semver')
const Joi = require('joi')
.extend(semver)
.extend(semverRange)
Joi.attempt('1.2.3', Joi.semver().valid()) // '1.2.3'
Joi.attempt('>=1.2.3', Joi.semverRange().valid()) // '>=1.2.3'
Joi.attempt('1.2.3', Joi.semver().gte('1.2.3')) // '1.2.3'
Joi.attempt('1.2.3', Joi.semver().lt('1.2.3')) // throws ValidationError
Joi.attempt('1.2.3', Joi.semver().satisfies('^1.0.0')) // '1.2.3'
See semver documentation. All boolean
returning comparisons are supported.
- Joi
Starts the chain.
Asserts valid(value)
.
Asserts gt(value, exp)
.
Asserts gte(value, exp)
.
Asserts lt(value, exp)
.
Asserts lte(value, exp)
.
Asserts eq(value, exp)
.
Asserts neq(value, exp)
.
Asserts cmp(value, comp, exp)
.
Asserts satisfies(value, rng)
.
Asserts gtr(value, rng)
.
Asserts ltr(value, rng)
.
Asserts outside(value, hilo, rng)
.
Starts the chain.
Asserts validRange(value)
.