# vtypes-requiredwith

> Additional constraints for validate.js

Latest version **1.0.0** (published 2017-08-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install vtypes-requiredwith
pnpm add vtypes-requiredwith
yarn add vtypes-requiredwith
bun add vtypes-requiredwith
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2017-08-13 |
| First published | 2017-08-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Gerald Yeo |
| Maintainers | geraldyeo |
| Keywords | vtypes-modularized, vtypes, validate.js, validation, requiredwith |

## Links

- npm: https://www.npmjs.com/package/vtypes-requiredwith
- Repository: https://github.com/yeojz/vtypes/tree/master/packages/vtypes-requiredwith
- npm.io page: https://npm.io/package/vtypes-requiredwith

## Alternatives

- [@regle/core](https://npm.io/package/@regle/core.md) — 47.0K weekly downloads
- [typeof-arguments](https://npm.io/package/typeof-arguments.md) — 12.5K weekly downloads
- [@lokalise/projects-engine-contracts](https://npm.io/package/@lokalise/projects-engine-contracts.md) — 978 weekly downloads
- [@osjwnpm/nam-laboriosam-quibusdam](https://npm.io/package/@osjwnpm/nam-laboriosam-quibusdam.md) — 70 weekly downloads
- [@oridune/validator](https://npm.io/package/@oridune/validator.md) — 16 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2017-08-13

## README

# vtypes-requiredwith

> "Required With" validator for validate.js

[![npm package][npm-badge]][npm-link]
[![vtypes][vtypes-badge]][repository]

- [About](#about)
- [Installation](#installation)
- [Usage](#usage)
- [Available Options](#available-options)
- [License](#license)

## About

The `requiredWith` validator attempts to ensure that the input
is be present and not empty if _ANY_ of the other specified
fields are present.

## Installation

Using npm:

```sh
$ npm i --save vtypes-requiredwith
```

```js
const validate = require('validate.js');
const requiredWith = require('vtypes-requiredwith');

// you can then proceed to register the required validators.
validate.validators.requiredWith = requiredWith;
```

## Usage

```js
const constraint = {
  attr: {
    requiredWith: {attributes: ['other']}
  }
}

validate({}, constraint);
// => undefined

validate({attr: 'foo', other: 'bar'}, constraint);
// => undefined

validate({other: 'bar'}, constraint);
// => {attr: ['Attr is required when any of these attributes (other) are present']}
```

For more examples, check out the test files in this package's [source][src] folder.

## Available Options

| name       | type    | default                                                                | description                                                                         |
| ---------- | ------- | ---------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| attributes | array   |                                                                        | The list of attributes                                                              |
| message    | string  | `is required when any of these attributes (%{attributes}) are present` | Error message                                                                       |
| truthy     | boolean | false                                                                  | Checks for truthy values instead of checking only for `null` and `undefined` values |

## License

`vtypes-requiredwith` is [MIT licensed][license]

[npm-badge]: https://img.shields.io/npm/v/vtypes-requiredwith.svg?style=flat-square
[npm-link]: https://www.npmjs.com/package/vtypes-requiredwith
[repository]: https://github.com/yeojz/vtypes
[vtypes-badge]: https://img.shields.io/badge/vtypes-repo-blue.svg?style=flat-square
[license]: https://github.com/yeojz/vtypes/blob/master/LICENSE
[src]: https://github.com/yeojz/vtypes/tree/master/packages/vtypes-requiredwith/src

---
_Source: https://npm.io/package/vtypes-requiredwith · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
