https://github.com/demvsystems/yup-ast
Rewrite of the original yup-ast due to licensing problems (with consent of the original author).
https://github.com/demvsystems/yup-ast
json schema typescript validation yup
Last synced: 7 months ago
JSON representation
Rewrite of the original yup-ast due to licensing problems (with consent of the original author).
- Host: GitHub
- URL: https://github.com/demvsystems/yup-ast
- Owner: demvsystems
- License: isc
- Created: 2020-04-02T17:18:14.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-02-03T05:36:13.000Z (over 2 years ago)
- Last Synced: 2025-02-02T08:18:09.785Z (8 months ago)
- Topics: json, schema, typescript, validation, yup
- Language: TypeScript
- Size: 1.23 MB
- Stars: 18
- Watchers: 5
- Forks: 2
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# yup-ast
[](https://www.npmjs.com/package/@demvsystems/yup-ast)
[](https://github.com/demvsystems/yup-ast/actions)
[](https://www.npmjs.com/package/@demvsystems/yup-ast)
[](https://david-dm.org/demvsystems/yup-ast)
[](https://codecov.io/github/demvsystems/yup-ast?branch=master)> Generates [yup](https://github.com/jquense/yup) instances from JSON schemas.
This project is meant to be a successor to the original [yup-ast](https://github.com/WASD-Team/yup-ast)
which - due to licensing issues - can no longer be actively maintained.
Due to time contraints, only the core functionality has been ported so far.
Feel free to add any potential improvements or missing APIs from the original via PRs!## Installation
npm install --save @demvsystems/yup-ast## Usage
### ES5
var transformAll = require('@demvsystems/yup-ast').transformAll;### ES2015+
import { transformAll } from '@demvsystems/yup-ast';### Transforming JSON to a schema instance
The JSON representation of a yup schema is an array with each call being an array again.
The method calls start with "yup.". Each parameter is an additional array entry afterwards.Example: To create a schema like the following:
```ts
const schema = yup.array()
.required()
.min(2)
.of(
yup.object()
.required()
.shape({
foo: yup.string().required(),
})
);
```you call `transformAll` like this:
```ts
const schema = transformAll([
['yup.array'],
['yup.required'],
['yup.min', 2],
['yup.of', [
['yup.object'],
['yup.required'],
['yup.shape', {
foo: [['yup.string'], ['yup.required']],
}],
]],
]);
```Both can be validated the same way:
```ts
schema.isValidSync([
{ foo: 'bar' },
{ foo: 'baz' },
]); // => true
```For more example use cases, have a look at [the included test cases](./src/__tests__/test.test.ts).
## Changelog
Please look at [the releases](https://github.com/demvsystems/yup-ast/releases) for more information on what has changed recently.## Credits
- [spaceemotion](https://github.com/spaceemotion)
- [All Contributors](https://github.com/demvsystems/yup-ast/contributors)## License
The ISC License (ISC). Please see [License File](LICENSE.md) for more information.