1.1.9 • Published 6 years ago

joi-intersection v1.1.9

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

joi-intersection

Validate against intersections of arrays and array singletons. Provide an array of allowed groups and validate it against a single intersection of a given group. Additionally, define an array of singletons and verify the input array occurs only once.

Features

  • Validate groups
  • Validate singletons

Installation

npm install joi-intersection --save

API

groups([[group: string]])

A group contains array of strings.

ParameterTypeDescription
group[group: string]Allowed intersection groups

singleton([singleton: string])

Singletons contain arrays of strings.

ParameterTypeDescription
singleton[singleton: string]Allowed singleton

Usage

Extend Joi

You have to extend Joi first, then use it like other validation rules. You can also chain both rules.

import JoiBase from 'joi'
import JoiIntersection from 'joi-intersection'
import * as assert from 'assert'

const Joi = JoiBase.extend(JoiIntersection)

Groups

const schema = Joi.array().groups([
  ['Bob', 'Alex', 'Peter'],
  ['Jack', 'Mike']
])

Joi.validate(['Bob', 'Alex'], schema, error => assert.ok(error, null))
Joi.validate(['Bob', 'Jack'], schema, error => assert.notEqual(error, null))

Singleton

const schema = Joi.array().singleton(['Bob', 'Alex', 'Peter'])

Joi.validate(['Bob'], schema, error => assert.ok(error, null))
Joi.validate(['Bob', 'Bob'], schema, error => assert.notEqual(error, null))

Author

Julian Claus and contributors.

License

MIT

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.0.1

6 years ago

0.0.0

6 years ago