walli-schema

walli schema to walli

Usage no npm install needed!

<script type="module">
  import walliSchema from 'https://cdn.skypack.dev/walli-schema';
</script>

README

walli-schema

Build status Test coverage NPM version NPM Downloads Prettier Conventional Commits

walli schema to walli

Installation

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

Usage

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

const verifiable = schemaToWalli({
  $type: 'leq',
  rule: {
    $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
            }
          }
        ]
      }
    ]
  }
})

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 🐟