# yokan

> models for mutable objects

Latest version **0.1.0-rc.0** (published 2023-10-09) · MIT license · 0 weekly downloads

## Install

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

## Health

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

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

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0-rc.0 |
| Published | 2023-10-09 |
| First published | 2023-10-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=12.x |
| Dependencies | 0 |
| Unpacked size | 9.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | kevinfiol |
| Maintainers | kevinfiol |
| Keywords | model, types, typecheck, validation |

## Links

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

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

- 0.1.0-rc.0 (latest) — 2023-10-09

## README

# yokan

Self-validating mutable objects.

```js
import { Model, string, array, number } from 'yokan';

// define your models
const Profile = Model({
  password: string(str => str.length > 5),
  pets: array({ type: 'string' })
});

// models can be nested
const User = Model({
  name: string(),
  age: number(),
  profile: Profile
});

// create an object
// this will throw if the initial object is invalid
const user = User({
  name: 'kevin',
  age: 20,
  profile: {
    password: 'hunter2',
    pets: ['maggie', 'trixie', 'flitch', 'haku']
  }
});

// modify your object as you normally would
user.name = 'rafael';

// the object will throw on invalid assignments
// throws "Error: .profile.password failed validation"
user.profile.password = '1234';
```

## Install

```shell
npm install yokan
```

## Credits

yokan is a minimalist take on [use-models-for-data](https://github.com/Pomax/use-models-for-data) by [Pomax](https://github.com/Pomax/).

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