# schemion

> Object schema validation

Latest version **0.0.11** (published 2023-03-11) · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.11 |
| Published | 2023-03-11 |
| First published | 2023-03-05 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | * |
| Dependencies | 0 |
| Unpacked size | 13 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | revers3ntropy |
| Maintainers | revers3ntropy |

## Links

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

## Recent versions

- 0.0.11 (latest) — 2023-03-11
- 0.0.10 — 2023-03-06
- 0.0.9 — 2023-03-06
- 0.0.8 — 2023-03-05
- 0.0.7 — 2023-03-05
- 0.0.6 — 2023-03-05
- 0.0.5 — 2023-03-05
- 0.0.4 — 2023-03-05
- 0.0.3 — 2023-03-05
- 0.0.2 — 2023-03-05

## README

# Schemion

Schemion is a lightweight object schema validator for JavaScript/TypeScript.

## Example

```typescript
const schemion = require('schemion');
// Or: 
// import { default as schemion } from 'schemion';

// match objects with an intuitive syntax
schemion.matches(
    { foo: 'bar', bar: 123 }, // object
    { foo: 'string' }         // schema
); // true

// match nested objects and tuples
schemion.matches(
    { foo: [ 'foo', 0.2, { bar: [] } ] },
    { foo: [ 'string', 'number', { bar: 'any' } ] }
); // true

// TypeScript support
const foo = { bar: 'bar' };
if (schemion.matches(foo, { bar: 'string' })) {
    foo.bar;
    //  ^? string
    foo.foo;
    //  ^? error, foo is not a property of `{ bar: string }`
}

// supply default values, which are applied to the object
const myObj = { foo: 'bar' };
schemion.matches(
    myObj,
    { foo: 'string', bar: 'number' },
    { bar: 123 }
); // true
myObj.bar; // 123

// strict mode
schemion.matches(
    { foo: 'bar', foobar: 10 },  // object
    { foo: 'string' },           // schema
    null,                        // default values
    { strict: true }             // config
); // false, but true if `strict: false`


// match primitive types
schemion.matches(123, 'number'); // true
schemion.matches(123, 'string'); // false
schemion.matches([], 'any');     // true
schemion.matches([], 'object');  // true
```

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