# muoto

> Declarative Shape Invariants

Latest version **0.1.0** (published 2016-06-27) · MIT license · 0 weekly downloads

## Install

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

## 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.1.0 |
| Published | 2016-06-27 |
| First published | 2016-06-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | orodio |
| Maintainers | orodio |
| Keywords | assertion, invariant |

## Links

- npm: https://www.npmjs.com/package/muoto
- Repository: github.com/orodio/muoto
- npm.io page: https://npm.io/package/muoto

## Recent versions

- 0.1.0 (latest) — 2016-06-27
- 0.0.0 — 2016-06-27

## README

# muoto

## install

```
$ npm intall --save muoto
```

## usage

```javascript
import { shape } from "muoto"

function bob (thing) {
  if (!shape({
    foo:  1,
    bar:  shape.number,
    baz:  shape.string,
    fuzz: shape.bool,
  })(thing).valid) throw new Error("Passed in the wrong thing")

  // do stuff
}

bob({ foo:1, bar:1, baz:"a", fuzz:true }) // does stuff
bob() // throws
bob({}) // throws
bob({ foo:2, bar:1, baz:"a", fuzz:true }) // throws

```

### using your own shape things

```javascript
function greater_than (n) {
  return function (value, cursor, tools) {
    if (tools.is.NUMBER(value)) return tools.Nope(cursor, value, cursor + " needs to be a number")
    if (value <= n) return tools.Nope(cursor, value, cursor + " needs to be greater than " + n + ", but was " + value)
    return tools.Just(cursor, value)
  }
}

var check = shape({ foo:greater_than(4) })

check({ foo:9 }).valid // true
check({ foo:3 }).valid // false
check({ foo:19 }).valid // true
```

### some other stuff

```javascript
// arrays
shape([1])([1, 1, 1, 1]).valid // true
shape([1])([1, 2, 1, 1]).valid // false
shape([1, 2, 1, 1])([1, 2, 1, 1]).valid // true
shape([1, 2, 1, 1])([1, 1, 1, 1]).valid // false
shape([{ foo:shape.number }])([ { foo:1 }, { foo:2 }, { foo:3} ]).valid // true

shape(shape.number, { blocking: true })("b") // throws an error
shape(shape.number, { logging: true })("b") // logs an error message

var shp = shape({ foo:[{ bar:1 }] })({ foo:[{ bar:1 }, { bar:1 }, { bar:2 }, { bar:1 }] })
shp.valid  // false
shp.cursor // foo[2].bar

shape(shape.number, { bypass:true })("a").valid // true - wont execute any of the traversals (prod mode maybe)
```

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