# validation-utils

> Validation utilities

Latest version **11.0.1** (published 2024-10-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install validation-utils
pnpm add validation-utils
yarn add validation-utils
bun add validation-utils
```

## Health

**Score 45/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 11.0.1 |
| Published | 2024-10-06 |
| First published | 2017-05-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 45.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | kibertoad |
| Keywords | common, utilities, utils, validation, assertion, validator, validate, assert, null, type, nil, empty |

## Links

- npm: https://www.npmjs.com/package/validation-utils
- Repository: https://github.com/kibertoad/validation-utils
- Homepage: http://github.com/kibertoad/validation-utils
- Issues: https://github.com/kibertoad/validation-utils/issues
- npm.io page: https://npm.io/package/validation-utils

## Dependencies (1)

- [zoology](https://npm.io/package/zoology.md) ^2.0.0

## Alternatives

- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@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

## Recent versions

- 11.0.1 (latest) — 2024-10-06
- 11.0.0 — 2024-07-07
- 10.0.0 — 2024-02-04
- 9.1.0 — 2023-09-09
- 9.0.0 — 2023-07-01
- 7.0.0 — 2021-07-21
- 6.3.0 — 2021-03-07
- 6.2.2 — 2021-01-20
- 6.2.1 — 2021-01-20
- 6.2.0 — 2021-01-20
- 6.1.0 — 2021-01-17
- 6.0.0 — 2020-12-25
- 5.0.2 — 2020-12-17
- 5.0.1 — 2020-12-17
- 5.0.0 — 2020-12-17
- … 21 more at https://npm.io/package/validation-utils/versions

## README

# validation-utils

[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
![](https://github.com/kibertoad/validation-utils/workflows/unit-tests/badge.svg)
[![Coverage Status](https://coveralls.io/repos/kibertoad/validation-utils/badge.svg?branch=master)](https://coveralls.io/r/kibertoad/validation-utils?branch=master)


Validation utils for Javascript that provide convenient way to throw a typed error if some expected condition is not satisfied.  

Node.JS 12+ is supported.

### Getting started

Install the library with `npm install validation-utils`

```javascript
const { validateNotEmpty } = require('validation-utils');

function init (email) {
  this.email = validateNotEmpty(email); //will throw an error if email is not provided
}
```

#### TypeScript

```javascript
import { validateNotEmpty } from 'validation-utils';
```

### Validators

- **validateArray(entity [, errorText])** - check if entity is an array.
- **validateBoolean(entity [, errorText])** - check if entity is a boolean.
- **validateBooleanNonStrict(entity [, errorText])** - check if entity is a boolean or a (case-insensitive) 'true' or 'false' string.
- **validateBooleanFalse(entity [, errorText])** - check if entity is a boolean with value False.
- **validateBooleanTrue(entity [, errorText])** - check if entity is a boolean with value True.
- **validateDate(entity [, errorText])** - check if entity is an instance of Date.
- **validateEqual(entity, expectedEqualEntity [, errorText])** - check if entity is equal to the expected one (compared with ===).
- **validateOneOf(entity, expectedOneOfEntities [, errorText])** - check if entity is equal to one of the expected ones (indexOf !== -1).
- **validateSomeNotNil(entities [, errorText])** - check if at least one of the given entities are not null or undefined.
- **validateFalsy(entity [, errorText])** - check if entity is falsy.
- **validateFunction(entity [, errorText])** - check if entity is a function.
- **validateInheritsFrom(entityClass, expectedParentClass [, errorText])** - check if class inherits from a given class.
- **validateInstanceOf(entity, expectedClass [, errorText])** - check if entity is an instance of a given class.
- **validateNotEmpty(entity [, errorText])** - check if entity is not an empty Object, String or Array.
- **validateNotNil(entity [, errorText])** - check if entity is not null or undefined.
- **validateNil(entity [, errorText])** - check if entity is null or undefined.
- **validateNumber(entity [, errorText])** - check if entity is a number.
- **validatePositiveNumber(entity [, errorText])** - check if entity is a positive number.
- **validateNegativeNumber(entity [, errorText])** - check if entity is a negative number.
- **validateGreaterThan(number, threshold [, errorText])** - check if entity is a number than is greater than the specified threshold.
- **validateLessThan(number, threshold [, errorText])** - check if entity is a number than is less than the specified threshold.
- **validateString(entity [, errorText])** - check if entity is a string.
- **validateObject(entity [, errorText])** - check if entity is an object.
- **validateTruthy(entity [, errorText])** - check if entity is truthy.
- **validateHasProperties(entity, expectedProperties[, errorText])** - check if entity has at least a given set of properties defined.
- **validateNotNilProperties(entity, expectedProperties[, errorText])** - check if none of specified properties are null or undefined for the entity.

All validators return validated value as a result.

[npm-image]: https://img.shields.io/npm/v/validation-utils.svg
[npm-url]: https://npmjs.org/package/validation-utils
[downloads-image]: https://img.shields.io/npm/dm/validation-utils.svg
[downloads-url]: https://npmjs.org/package/validation-utils

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