@valivali/core
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@valivali/core

npm version npm download license Github Twitter

Provide a common interface for schema validation.

🚀 Installation

$ npm install @valivali/core

Install the schema validation library of your choice. The following is an example of using zod.

$ npm install @valivali/zod zod

👏 Getting Started

The following is a simple example of using zod.

import { valivali } from '@valivali/core';
import { resolver } from '@valivali/zod';
import { z } from 'zod';

const schema = z.object({
  id: z.string(),
  name: z.string(),
});

const value = {
  id: 'id',
  name: 'name',
};

const validatedValue = valivali(resolver(schema), value);

Or you can use your own resolver.

import { Resolver, valivali } from '@valivali/core';

const booleanResolver: Resolver<boolean> = value => {
  if (typeof value === 'boolean') return value;
  throw Error('invalid value');
};

const validatedValue = valivali(booleanResolver, true);

🤝 Contributing

Contributions, issues and feature requests are welcome.

Feel free to check issues page if you want to contribute.

📝 License

Copyright © 2020 @Karibash.

This project is MIT licensed.

Package Sidebar

Install

npm i @valivali/core

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

5.48 kB

Total Files

11

Last publish

Collaborators

  • karibash