# mandle

> A typesafe functional validation library

Latest version **3.0.0** (published 2020-11-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install mandle
pnpm add mandle
yarn add mandle
bun add mandle
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2020-11-27 |
| First published | 2017-11-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Harry G |
| Maintainers | harrygr |
| Keywords | data validation, validator, validate, validation, data |

## Links

- npm: https://www.npmjs.com/package/mandle
- Repository: https://github.com/harrygr/mandle
- Homepage: https://github.com/harrygr/mandle#readme
- Issues: https://github.com/harrygr/mandle/issues
- npm.io page: https://npm.io/package/mandle

## 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

- 3.0.0 (latest) — 2020-11-27
- 2.3.0 — 2019-11-07
- 2.2.1 — 2019-11-07
- 2.2.0 — 2018-08-26
- 2.1.0 — 2018-07-06
- 2.0.0 — 2018-05-01
- 1.2.0 — 2018-02-21
- 1.1.0 — 2017-11-24
- 1.0.2 — 2017-11-23
- 1.0.1 — 2017-11-22
- 1.0.0 — 2017-11-22

## README

# Mandle

[![CircleCI](https://img.shields.io/circleci/project/github/harrygr/mandle.svg?style=flat-square)](https://circleci.com/gh/harrygr/mandle) [![npm](https://img.shields.io/npm/v/mandle.svg?style=flat-square)](https://www.npmjs.com/package/mandle) [![codecov](https://codecov.io/gh/harrygr/mandle/branch/master/graph/badge.svg)](https://codecov.io/gh/harrygr/mandle)

Mandle is a functional validation library built in TypeScript. It brings a simple, declarative api for validating your data.

It's tiny in size and has no dependencies.

## Installation

```
yarn add mandle
```

## Example

```typescript
import { makeValidator } from 'mandle'
import { required, atLeast18 } from './constraints'

// Make a validator instance
const validatePerson = makeValidator({
  name: [required],
  age: [required, atLeast18],
})

// Validate some data
const result = validatePerson(
  {
    name: 'Foo Fooson',
    age: 16,
  },
)

// {
//   age: "Must be at least 18"
// }
```

## Constraints

To construct a validator you should give it some constraints. A constraint is a function that takes a value and returns either a string (the validation error message) or `undefined`.

For example, one of the simplest constraints you might want is `required`:

```typescript
const required = (val: any) => (val ? undefined : 'Required')
```

The data being validated is also provided as the 2nd argument for a constraint for situations where your constaint depends on some other value in the data. E.g.

```typescript
const passwordEquals: Constraint<PasswordFields> = (password, fields) =>
  password !== fields.passwordConfirm ? 'Passwords should match' : undefined
```

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