https://github.com/ndabap/joi-intersection
NOT MAINTAINED Validate against intersections of arrays and array singletons
https://github.com/ndabap/joi-intersection
extension javascript joi validation
Last synced: 6 months ago
JSON representation
NOT MAINTAINED Validate against intersections of arrays and array singletons
- Host: GitHub
- URL: https://github.com/ndabap/joi-intersection
- Owner: ndabAP
- License: mit
- Created: 2017-12-06T15:26:28.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-07-15T22:40:57.000Z (about 5 years ago)
- Last Synced: 2025-04-04T09:09:20.666Z (6 months ago)
- Topics: extension, javascript, joi, validation
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/joi-intersection
- Size: 40 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# NOT MAINTAINED 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
```js
npm install joi-intersection --save
```## API
### `groups([[group: string]])`
A group contains array of strings.
| Parameter | Type | Description |
|-----------------------|-------------------|-----------------------------|
| `group` | `[group: string]` | Allowed intersection groups |### `singleton([singleton: string])`
Singletons contain arrays of strings.
| Parameter | Type | Description |
|-----------------------|-------------------------|-----------------------------|
| `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.
```js
import JoiBase from 'joi'
import JoiIntersection from 'joi-intersection'
import * as assert from 'assert'const Joi = JoiBase.extend(JoiIntersection)
```### Groups
```js
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
```js
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](https://www.julian-claus.de) and contributors.
## License
MIT