@decs/typeschema
Advanced tools
Comparing version 0.1.3 to 0.2.0
@@ -1,2 +0,4 @@ | ||
export { assert } from './assert'; | ||
export type { Infer, Schema } from './types'; | ||
import type { Schema } from './adapters'; | ||
export type { Schema } from './adapters'; | ||
export type Infer<TSchema> = TSchema extends Schema<infer T> ? T : never; | ||
export declare function assert<T>(schema: Schema<T>, data: unknown): Promise<T>; |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.assert = void 0; | ||
var assert_1 = require("./assert"); | ||
Object.defineProperty(exports, "assert", { enumerable: true, get: function () { return assert_1.assert; } }); | ||
const adapters_1 = require("./adapters"); | ||
function assert(schema, data) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return (yield (0, adapters_1.wrap)(schema)).assert(data); | ||
}); | ||
} | ||
exports.assert = assert; |
{ | ||
"name": "@decs/typeschema", | ||
"version": "0.1.3", | ||
"description": "Unified interface for TypeScript schema validations", | ||
"version": "0.2.0", | ||
"description": "Universal adapter for schema validation", | ||
"keywords": [ | ||
@@ -13,3 +13,3 @@ "typescript", | ||
], | ||
"homepage": "https://github.com/decs/typeschema#readme", | ||
"homepage": "https://typeschema.com", | ||
"license": "MIT", | ||
@@ -38,2 +38,3 @@ "author": { | ||
"devDependencies": { | ||
"@sinclair/typebox": "^0.29.4", | ||
"@types/node": "^20.3.3", | ||
@@ -65,3 +66,39 @@ "@typescript-eslint/eslint-plugin": "^5.60.1", | ||
"zod": "^3.21.4" | ||
}, | ||
"peerDependencies": { | ||
"@sinclair/typebox": "^0.29.4", | ||
"arktype": "^1.0.14-alpha", | ||
"joi": "^17.9.2", | ||
"runtypes": "^6.7.0", | ||
"superstruct": "^1.0.3", | ||
"typia": "^4.1.2", | ||
"yup": "^1.2.0", | ||
"zod": "^3.21.4" | ||
}, | ||
"peerDependenciesMeta": { | ||
"@sinclair/typebox": { | ||
"optional": true | ||
}, | ||
"arktype": { | ||
"optional": true | ||
}, | ||
"joi": { | ||
"optional": true | ||
}, | ||
"runtypes": { | ||
"optional": true | ||
}, | ||
"superstruct": { | ||
"optional": true | ||
}, | ||
"typia": { | ||
"optional": true | ||
}, | ||
"yup": { | ||
"optional": true | ||
}, | ||
"zod": { | ||
"optional": true | ||
} | ||
} | ||
} |
@@ -1,9 +0,11 @@ | ||
<h1 align="center">🛵 TypeSchema</h1> | ||
<p align="center">Unified interface for TypeScript schema validations</p> | ||
<p align="center"> | ||
<a href="https://opensource.org/licenses/MIT" rel="nofollow"><img src="https://img.shields.io/github/license/decs/typeschema" alt="License"></a> | ||
<a href="https://www.npmjs.com/package/@decs/typeschema" rel="nofollow"><img src="https://img.shields.io/npm/dw/@decs/typeschema.svg" alt="NPM Downloads"></a> | ||
</p> | ||
<div id="header"> | ||
<h1 align="center">🛵 TypeSchema</h1> | ||
<p align="center">Universal adapter for schema validation</p> | ||
<p align="center"> | ||
<a href="https://opensource.org/licenses/MIT" rel="nofollow"><img src="https://img.shields.io/github/license/decs/typeschema" alt="License"></a> | ||
<a href="https://www.npmjs.com/package/@decs/typeschema" rel="nofollow"><img src="https://img.shields.io/npm/dw/@decs/typeschema.svg" alt="NPM Downloads"></a> | ||
</p> | ||
<br /> | ||
<br /> | ||
</div> | ||
@@ -21,3 +23,3 @@ Many libraries rely on some sort of type validation. Their maintainers have the choice of either to: | ||
- 🚀 Decouple your code from validation libraries | ||
- 🍃 Less than 3 kB, zero dependencies | ||
- 🍃 Tiny client footprint, zero dependencies | ||
- ✨ Easy-to-use, minimal API | ||
@@ -66,2 +68,3 @@ | ||
#### Types | ||
- `Schema<T>`<br />Generic interface for schemas | ||
@@ -71,2 +74,3 @@ - `Infer<T as Schema<unknown>>`<br />Extracts the equivalent TypeScript type of a schema | ||
#### Functions | ||
- `assert<T>(schema: Schema<T>, data: unknown): Promise<T>`<br />Returns the validated data or throws an exception | ||
@@ -76,14 +80,14 @@ | ||
| Project | Popularity | Example schema | Support | | ||
| -------------------------------------------------- | ------------------------------------------------------------------------------------------------ | ------------------------------ | ------------------ | | ||
| [zod](https://zod.dev) |  | `z.string()` | ✅ | | ||
| [yup](https://github.com/jquense/yup) |  | `string()` | ✅ | | ||
| [joi](https://joi.dev) |  | `Joi.string()` | ✅ | | ||
| [superstruct](https://docs.superstructjs.org) |  | `string()` | ✅ | | ||
| [io-ts](https://gcanti.github.io/io-ts) |  | `t.string` | ❌ | | ||
| [ow](https://sindresorhus.com/ow) |  | `ow.string` | ❌ | | ||
| [typebox](https://github.com/sinclairzx81/typebox) |  | `Type.String()` | ❌ | | ||
| [typia](https://typia.io) |  | `typia.createAssert<string>()` | ✅ | | ||
| [runtypes](https://github.com/pelotom/runtypes) |  | `String` | ✅ | | ||
| [arktype](https://arktype.io) |  | `type('string')` | ✅ | | ||
| Project | Popularity | Example schema | Support | | ||
| -------------------------------------------------- | ------------------------------------------------------------------------------------------------ | ------------------------------ | ------- | | ||
| [zod](https://zod.dev) |  | `z.string()` | ✅ | | ||
| [yup](https://github.com/jquense/yup) |  | `string()` | ✅ | | ||
| [joi](https://joi.dev) |  | `Joi.string()` | ✅ | | ||
| [superstruct](https://docs.superstructjs.org) |  | `string()` | ✅ | | ||
| [io-ts](https://gcanti.github.io/io-ts) |  | `t.string` | ❌ | | ||
| [ow](https://sindresorhus.com/ow) |  | `ow.string` | ❌ | | ||
| [typebox](https://github.com/sinclairzx81/typebox) |  | `Type.String()` | ✅ | | ||
| [typia](https://typia.io) |  | `typia.createAssert<string>()` | ✅ | | ||
| [runtypes](https://github.com/pelotom/runtypes) |  | `String` | ✅ | | ||
| [arktype](https://arktype.io) |  | `type('string')` | ✅ | | ||
@@ -106,2 +110,2 @@ Custom validations are also supported: | ||
* Inspired by [tRPC](https://trpc.io/)'s [input & output validators](https://trpc.io/docs/server/validators) | ||
- Inspired by [tRPC](https://trpc.io/)'s [input & output validators](https://trpc.io/docs/server/validators) |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
26521
23
365
107
8
27
1