# optimal

> Build, validate, and transform values with immutable typed schemas.

Latest version **5.1.1** (published 2021-10-16) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.1.1 |
| Published | 2021-10-16 |
| First published | 2012-07-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=12.17.0 |
| Dependencies | 0 |
| Unpacked size | 420.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 17 |
| Author | Miles Johnson |
| Maintainers | milesj |
| Keywords | opts, options, schema, predicate, validator, config, defaults, object, params, struct |

## Links

- npm: https://www.npmjs.com/package/optimal
- Repository: https://github.com/milesj/optimal
- Homepage: https://github.com/milesj/optimal#readme
- Issues: https://github.com/milesj/optimal/issues
- Funding: https://ko-fi.com/milesjohnson
- npm.io page: https://npm.io/package/optimal

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 5.1.1 (latest) — 2021-10-16
- 5.0.0-alpha.2 (next) — 2021-09-16
- 5.1.0 — 2021-10-10
- 5.0.0 — 2021-10-07
- 5.0.0-alpha.5 — 2021-10-01
- 5.0.0-alpha.4 — 2021-09-21
- 5.0.0-alpha.3 — 2021-09-21
- 5.0.0-alpha.1 — 2021-09-08
- 4.3.0 — 2021-02-21
- 4.2.1 — 2021-02-12
- 4.2.0 — 2020-01-26
- 4.1.2 — 2020-01-26
- 4.1.1 — 2020-01-25
- 4.1.0 — 2020-01-20
- 4.0.1 — 2020-01-19
- … 53 more at https://npm.io/package/optimal/versions

## README

# Optimal

[![Build Status](https://github.com/milesj/optimal/workflows/Build/badge.svg)](https://github.com/milesj/optimal/actions?query=branch%3Amaster)
[![npm version](https://badge.fury.io/js/optimal.svg)](https://www.npmjs.com/package/optimal)
[![npm deps](https://david-dm.org/milesj/optimal.svg)](https://www.npmjs.com/package/optimal)

Optimal is a system for building and validating any value with typed schemas, and first-class
support for defined object structures, like options objects, configuration files, validation fields,
and many more. Optimal aims to provide a powerful API, with high performance, the lowest possible
filesize, and TypeScript-first support.

```ts
// Import schemas to build validators withs
import { array, string, number, optimal } from 'optimal';

// Define and validate values with individual schemas
const maxSizeSchema = number().positive().lte(10000);

maxSizeSchema.validate(1234);

// Or define an explicit shaped blueprint
const schema = optimal({
  name: string().notEmpty(),
  include: array().of(string()),
  exclude: array().of(string()),
  maxSize: maxSizeSchema
});

// Pass a full or partial object to validate
const options = schema.validate({ name: 'Optimal' });

// Which validates, builds, and returns the following object
{
  name: 'Optimal',
  include: [],
  exclude: [],
  maxSize: 10000,
}
```

## Features

- Zero dependencies, with a tree-shakable API.
- Powerful inferrence using a TypeScript first design.
- Runs in both Node.js and the browser.
- Smallest filesize: 5kB minified and gzipped!
- Immutable & fluent schema builder pattern.
- Recursively builds and validates nested structures.
- Supports common data types.
- Autofills missing fields with default values.
- Allows or restricts unknown fields.
- Mark fields as nullable or required.
- Handles logical operators AND, OR, and XOR.

## Requirements

- Node v12.17 (server)
- Edge, Chrome, Firefox, Safari (browser)

## Installation

```
yarn add optimal
```

## Documentation

[https://optimallib.dev](https://optimallib.dev)

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