1.0.0 • Published 1 year ago

@valivali/core v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@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.