Semver extension for the Joi validation library
const Joi = require('@hapi/joi')
.extend(require('joi-extension-semver'))
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.3See semver documentation. All boolean
returning comparisons are supported.
- Joi
Starts the chain. Does not perform any validation in itself. The reason for this is that it is possible to continue with semver.validRange() in which
case the expected value should be a range instead of a version.
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 validRange(value).
Asserts satisfies(value, rng).
Asserts gtr(value, rng).
Asserts ltr(value, rng).
Asserts outside(value, hilo, rng).