# recordType

> The record data type

Latest version **1.0.0** (published 2016-06-26) · ISC license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2016-06-26 |
| First published | 2016-06-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Kurtis Rainbolt-Greene |
| Maintainers | krainboltgreene |
| Keywords | record, type |

## Links

- npm: https://www.npmjs.com/package/recordType
- Repository: https://github.com/krainboltgreene/recordType.js
- Homepage: https://github.com/krainboltgreene/recordType.js#readme
- Issues: https://github.com/krainboltgreene/recordType.js/issues
- npm.io page: https://npm.io/package/recordType

## Dependencies (1)

- [ramda](https://npm.io/package/ramda.md) 0.21.0

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2016-06-26

## README

# recordType

An implementation of the Record datatype.

![Version][BADGE_VERSION]
![Tests][BADGE_TRAVIS]
![Stability][BADGE_STABILITY]
![Dependencies][BADGE_DEPENDENCY]


## using

Here's a simple recordType:

``` javascript
import record from "recordType"

// We define the record here.
const friend = record([
  // Fields are a list of "array"s, and unordered
  ["id", "String"]
])

// You can even nest records
const person = record([
  // Each field has a name, type, and default (optional)
  ["name", "String", "Unknown Name"],
  ["age", "Number"],
  ["friends", "Array"]
])

// We instantiate a record here:
const kurtis = person([
  ["name", "Kurtis Rainbolt-Greene"],
  ["age", 27],
  ["friends", [
    friend([
      ["id", "2"]
    ])
  ]]
])
// What you get is a Map containing the keys "name", "age", and "friends"

console.log(kurtis)
// Map {
//   'name' => 'Kurtis Rainbolt-Greene',
//   'age' => 27,
//   'friends' => [ Map { 'id' => '2' } ] }
```

Here's what happens when you break the type contract:

``` javascript
// Using the example above...

// If you provide the wrong type for a field, you get this error:
const john = person([
  ["name", "John B."],
  ["age", "25"],
  ["friends", []]
])
// Error: You provided "25" for field age, which is limited to Number

// If you miss information you get this error:
const kaity = person([
  ["name", "Kaity Willburough"],
  ["age"]
])
// Error: You provided no value or default value for field age, which must be an Number

// If you add a field not defined:
const william = person([
  ["name", "Kurtis Rainbolt-Greene"],
  ["age", 27],
  ["friends", []],
  ["married", false]
])
// Error: You provided ["allies","enemies"], but the record doesn't define those
```

[BADGE_TRAVIS]: https://img.shields.io/travis/krainboltgreene/recordType.js.svg?maxAge=2592000&style=flat-square
[BADGE_VERSION]: https://img.shields.io/npm/v/recordType.svg?maxAge=2592000&style=flat-square
[BADGE_STABILITY]: https://img.shields.io/badge/stability-strong-green.svg?maxAge=2592000&style=flat-square
[BADGE_DEPENDENCY]: https://img.shields.io/david/krainboltgreene/recordType.js.svg?maxAge=2592000&style=flat-square

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