Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Zod | 20,263 | 855 | a day ago | 244 | September 11, 2022 | 172 | mit | TypeScript | ||
TypeScript-first schema validation with static type inference | ||||||||||
Yup | 19,988 | 8,912 | 2,408 | 2 days ago | 115 | August 20, 2022 | 165 | mit | TypeScript | |
Dead simple Object schema validation | ||||||||||
Ajv | 12,307 | 801,606 | 7,985 | 2 days ago | 349 | March 22, 2022 | 252 | mit | TypeScript | |
The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927) | ||||||||||
Formily | 9,334 | 119 | 2 days ago | 209 | September 20, 2022 | 11 | mit | TypeScript | ||
📱🚀 🧩 Cross Device & High Performance Normal Form/Dynamic(JSON Schema) Form/Form Builder -- Support React/React Native/Vue 2/Vue 3 | ||||||||||
Marshmallow | 6,465 | 9,091 | 969 | 6 days ago | 168 | June 26, 2022 | 162 | mit | Python | |
A lightweight library for converting complex objects to and from simple Python datatypes. | ||||||||||
Superstruct | 6,417 | 348 | 296 | 23 days ago | 75 | September 22, 2022 | 75 | mit | TypeScript | |
A simple and composable way to validate data in JavaScript (and TypeScript). | ||||||||||
Jsonschema | 4,069 | 15,530 | 2,424 | 3 days ago | 74 | July 07, 2022 | 29 | mit | Python | |
An implementation of the JSON Schema specification for Python | ||||||||||
Json Schema | 3,344 | 8,501 | 489 | 3 months ago | 46 | April 13, 2022 | 96 | mit | PHP | |
PHP implementation of JSON schema. Fork of the http://jsonschemaphpv.sourceforge.net/ project | ||||||||||
Kubeval | 3,043 | 8 | 20 | 17 days ago | 13 | April 26, 2021 | 104 | other | Go | |
Validate your Kubernetes configuration files, supports multiple Kubernetes versions | ||||||||||
Json Schema Spec | 2,834 | 17 hours ago | 105 | other | Makefile | |||||
The JSON Schema I-D sources |
Static and runtime type assertion library with no dependencies
yarn add typanion
Compared to yup, Typanion has a better inference support for TypeScript + supports isOneOf
. Its functional API makes it very easy to tree shake, which is another bonus (although the library isn't very large in itself).
Check the website for our documentation: mael.dev/typanion.
First define a schema using the builtin operators:
import * as t from 'typanion';
const isMovie = t.isObject({
title: t.isString(),
description: t.isString(),
});
Then just call the schema to validate any unknown
value:
const userData = JSON.parse(input);
if (isMovie(userData)) {
console.log(userData.title);
}
Passing a second parameter allows you to retrieve detailed errors:
const userData = JSON.parse(input);
const errors: string[] = [];
if (!isMovie(userData, {errors})) {
console.log(errors);
}
You can also apply coercion over the user input:
const userData = JSON.parse(input);
const coercions: Coercion[] = [];
if (isMovie(userData, {coercions})) {
// Coercions aren't flushed by default
for (const [p, op] of coercions) op();
// All relevant fields have now been coerced
// ...
}
You can derive the type from the schema and use it in other functions:
import * as t from 'typanion';
const isMovie = t.isObject({
title: t.isString(),
description: t.isString(),
});
type Movie = t.InferType<typeof isMovie>;
// Then just use your alias:
const printMovie = (movie: Movie) => {
// ...
};
Schemas can be stored in multiple variables if needed:
import * as t from 'typanion';
const isActor = t.isObject({
name: t.isString();
});
const isMovie = t.isObject({
title: t.isString(),
description: t.isString(),
actors: t.isArray(isActor),
});
Copyright 2020 Mael Nison
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.