walli-schema
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

walli-schema

Build status Test coverage NPM version NPM Downloads Prettier Conventional Commits

walli schema to walli

See walli

Installation

npm install walli-schema
# or use yarn
yarn add walli-schema

Usage

import { schemaToWalli, createSchemaToWalli } from 'walli-schema'

const verifiable = schemaToWalli({
  $type: 'every',
  rule: [
    {
      $type: 'leq',
      rule: {
        a: 1
      }
    },
    {
      $type: 'oneOf',
      rule: [
        {
          $type: 'leq',
          rule: {
            b: 2,
            c: 3
          }
        },
        {
          $type: 'leq',
          rule: {
            b: 3,
            c: 2
          }
        }
      ]
    }
  ]
})

// => equals
walli.every([
    walli.leq({ a: 1 }),
    walli.oneOf([
        walli.leq({b: 2, c: 3}),
        walli.leq({b: 3, c: 2}),
    ]),
])

expect(
  verifiable.ok({
    a: 1
  })
).toBeFalsy()

expect(
  verifiable.ok({
    a: 1,
    b: 2
  })
).toBeFalsy()
//
expect(
  verifiable.ok({
    a: 1,
    b: 2,
    c: 3
  })
).toBeTruthy()

expect(
  verifiable.ok({
    a: 1,
    b: 3,
    c: 2
  })
).toBeTruthy()

const customSchemaToWalli = createSchemaToWalli({
  string: walli.string
  // custom... $types
})

Contributing

  • Fork it!
  • Create your new branch:
    git checkout -b feature-new or git checkout -b fix-which-bug
  • Start your magic work now
  • Make sure npm test passes
  • Commit your changes:
    git commit -am 'feat: some description (close #123)' or git commit -am 'fix: some description (fix #123)'
  • Push to the branch: git push
  • Submit a pull request :)

Authors

This library is written and maintained by imcuttle, moyuyc95@gmail.com.

License

MIT - imcuttle 🐟

Dependencies (3)

Dev Dependencies (13)

Package Sidebar

Install

npm i walli-schema

Weekly Downloads

2

Version

1.0.3

License

MIT

Unpacked Size

15.3 kB

Total Files

10

Last publish

Collaborators

  • moyuyc