# namebase-types

> Check types at runtime.

Latest version **0.0.12** (published 2020-09-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install namebase-types
pnpm add namebase-types
yarn add namebase-types
bun add namebase-types
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.12 |
| Published | 2020-09-22 |
| First published | 2019-04-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 26.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Anthony Liu |
| Maintainers | igliu |

## Links

- npm: https://www.npmjs.com/package/namebase-types
- npm.io page: https://npm.io/package/namebase-types

## Recent versions

- 0.0.12 (latest) — 2020-09-22
- 0.0.11 — 2020-09-22
- 0.0.10 — 2020-09-09
- 0.0.9 — 2020-05-26
- 0.0.8 — 2020-05-23
- 0.0.7 — 2020-05-11
- 0.0.6 — 2020-01-21
- 0.0.5 — 2019-11-05
- 0.0.4 — 2019-04-10
- 0.0.3 — 2019-04-10
- 0.0.2 — 2019-04-10
- 0.0.1 — 2019-04-10

## README

Namebase Types
==

This package lets you do things like this:

```js
const {
  OR,
  OBJECT,
  STRING,
  INTEGER,
  BOOLEAN,
  ENUM,
  exceptions,
} = require('namebase-types');

const parser = OR(
  OBJECT({
    a: STRING,
    b: INTEGER,
  }),
  OBJECT({
    a: STRING,
    b: INTEGER,
    c: BOOLEAN,
    d: ENUM(10, 20),
  }),
)

// returns { a: "foo", b: 4 }
parser({ a: "foo", b: 4 })

// returns { a: "foo", b: 4, c: true, d: 20 }
parser({ a: "foo", b: 4, c: true, d: 20 })

// throws exceptions.InvalidType({ key: "a" })
parser({ a: false, b: 4, c: true, d: 20 })

// throws exceptions.MissingKey({ key: "b" })
parser({ a: "foo", c: true, d: 10 })

// throws exceptions.MissingKey({ key: "c" })
parser({ a: "foo", b: 4, d: 10 })

// throws exceptions.ExtraKey({ key: "e" })
parser({ a: "foo", b: 4, c: true, d: 10, e: "bar" })
```

Check the tests for more details. Note: instead of passing in the built-in primitives (STRING, INTEGER, BOOLEAN, ENUM, OBJECT), you can pass in any parsing function that returns its parsed input on success (and throws otherwise).

## License

MIT License: https://igliu.mit-license.org

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