# lib-schema

> like schemas and stuff

Latest version **0.5.0** (published 2015-04-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install lib-schema
pnpm add lib-schema
yarn add lib-schema
bun add lib-schema
```

## 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.5.0 |
| Published | 2015-04-02 |
| First published | 2014-04-04 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jacob Groundwater |
| Maintainers | groundwater |

## Links

- npm: https://www.npmjs.com/package/lib-schema
- Repository: https://github.com/groundwater/node-lib-schema
- Issues: https://github.com/groundwater/node-lib-schema/issues
- npm.io page: https://npm.io/package/lib-schema

## Dependencies (1)

- [lib-marshal](https://npm.io/package/lib-marshal.md) ^0.8.0

## Recent versions

- 0.5.0 (latest) — 2015-04-02
- 0.4.1 — 2015-03-24
- 0.4.0 — 2015-03-24
- 0.3.0 — 2014-06-28
- 0.2.0 — 2014-04-07
- 0.1.0 — 2014-04-05
- 0.0.0 — 2014-04-04

## README

# lib-schema

## install

```bash
npm install --save lib-schema
```

## usage

Define a *json* schema

```json
{
  "uid" : {"type": "number", "opts": {"min": 0}},
  "gid" : {"type": "number", "opts": {"min": 0}},
  "args": {"type": "array" , "kind": "string"},
  "envs": {"type": "map"   , "kind": "string"},
  "task": {"type": "struct", "props": {
      "exec" : "string",
      "args" : "args",
      "uid"  : "uid",
      "gid"  : "gid",
      "envs" : "envs"
    }, "require": ["exec", "args"]
  },
  "tasks": {"type": "array" , "kind": "task"},
  "job"  : {"type": "struct", "props": {
      "tasks": "tasks"
    }, "require": ["tasks"]
  }
}
```

Create a marshaller from the schema

```javascript
var schema = require('lib-schema');
var types  = schema(json);

var job = types.job.marshal({
  tasks: [
    {exec: 'ls', args: ['-al']}
  ]
});
// job is a validated object against the schema

types.job.marshal({
  tasks: [
    {exec: 'pwd'}
  ]
}); // throws because args is required parameter
```

## details

- types *string* and *number* are build in
- all other types must be declared before they're used

## see also

- [lib-marshal](https://www.npmjs.org/package/lib-marshal)

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