Skip to content

Latest commit

 

History

History
86 lines (69 loc) · 2.5 KB

README.MD

File metadata and controls

86 lines (69 loc) · 2.5 KB

joi-extension-semver

version license build

Semver extension for the Joi validation library

Usage

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'

Validation chains

See semver documentation. All boolean returning comparisons are supported.

semver

Starts the chain.

semver.valid()

Asserts valid(value).

semver.gt(exp)

Asserts gt(value, exp).

semver.gte(exp)

Asserts gte(value, exp).

semver.lt(exp)

Asserts lt(value, exp).

semver.lte(exp)

Asserts lte(value, exp).

semver.eq(exp)

Asserts eq(value, exp).

semver.neq(exp)

Asserts neq(value, exp).

semver.cmp(comp, exp)

Asserts cmp(value, comp, exp).

semver.satisfies(rng)

Asserts satisfies(value, rng).

semver.gtr(rng)

Asserts gtr(value, rng).

semver.ltr(rng)

Asserts ltr(value, rng).

semver.outside(hilo, rng)

Asserts outside(value, hilo, rng).

semverRange

Starts the chain.

semverRange.valid()

Asserts validRange(value).