# validd

> An experiment on data validation

Latest version **0.1.0** (published 2026-09-20) · ISC license · 0 weekly downloads

## Install

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

## Health

**Score 75/100 (B)** — status: active.

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

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2026-09-20 |
| First published | 2017-01-20 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18.0.0 |
| Dependencies | 0 |
| Unpacked size | 20.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| Author | Oscar Saraza |
| Maintainers | oscarsaraza |
| Keywords | Validation, Schema |

## Links

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

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

- 0.1.0 (latest) — 2026-09-20
- 0.0.15 — 2025-05-19
- 0.0.14 — 2023-01-11
- 0.0.13 — 2022-05-15
- 0.0.11 — 2021-08-29
- 0.0.10 — 2021-07-10
- 0.0.9 — 2021-05-08
- 0.0.7 — 2020-08-17
- 0.0.6 — 2020-06-23
- 0.0.5 — 2017-01-22
- 0.0.4 — 2017-01-21
- 0.0.3 — 2017-01-21
- 0.0.2 — 2017-01-20
- 0.0.1 — 2017-01-20

## README

# Validd

A lightweight, **zero-dependency** data validation library for JavaScript and TypeScript.

- ⚡ **Zero dependencies**: 0 runtime dependencies, 0 build dependencies.
- 📦 **Dual package**: Native ES Modules (`import`) and CommonJS (`require`) support.
- 🔷 **TypeScript ready**: Built-in type definitions (`.d.ts`) included out of the box.
- 🚀 **Asynchronous & Synchronous**: Built-in support for sync and async validation rules.

---

## Installation

```bash
# Using npm
npm install validd

# Using pnpm
pnpm add validd

# Using yarn
yarn add validd
```

---

## Usage

### ES Modules (ESM)
```javascript
import { validate } from 'validd'
```

### CommonJS (CJS)
```javascript
const { validate } = require('validd')
```

---

## Defining a Schema

Create a schema defining the validation rules for your data:

```javascript
import { validate } from 'validd'

const customAsyncValidationFunction = (value) =>
  new Promise((resolve) => {
    const error = value === 'admin' ? { error: 'reservedName', message: 'Name is reserved' } : null
    resolve(error)
  })

const formSchema = {
  type: 'object',
  messages: {
    invalidType: 'Tipo de dato inválido',
  },
  fields: {
    personName: {
      type: 'string',
      isRequired: true,
      minLength: 5,
      maxLength: 20,
      regex: /^[a-zA-Z ]+$/,
      validation: customAsyncValidationFunction,
      messages: {
        minLength: 'Must have at least 5 characters',
        maxLength: 'Text is too long...',
      },
    },
  },
}
```

---

## Validating Data

Pass the schema and the object to validate. `validate` returns a Promise with the validation result:

```javascript
const dataToValidate = {
  personName: 'Alice',
}

const result = await validate(formSchema, dataToValidate)
console.log(result)
```

### Example Validation Result

If valid, an empty object or clean fields map is returned:
```javascript
{}
```

If errors are encountered:
```javascript
{
  errors: [
    {
      error: 'invalidType',
      message: 'Invalid data type',
    },
  ],
  fields: {
    personName: {
      errors: [
        {
          error: 'minLength',
          message: 'Must have at least 5 characters',
        },
      ],
    },
  },
}
```

---

## License

[ISC](file:///Users/oscar/code/validd/package.json) © Oscar Saraza

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