New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@decs/typeschema

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@decs/typeschema

Unified interface for TypeScript schema validations

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.2K
decreased by-22.03%
Maintainers
1
Weekly downloads
 
Created
Source

🌙 TypeSchema

Unified interface for TypeScript schema validations

License NPM Downloads

Setup

Install TypeSchema with your package manager of choice:

npmnpm install @decs/typeschema
Yarnyarn add @decs/typeschema
pnpmpnpm add @decs/typeschema

Usage

import type {Infer} from '@decs/typeschema';
import {assert} from '@decs/typeschema';

// Use your favorite validation library
const schema = [...];

// Extracts the schema type
type Type = Infer<typeof schema>;

// Returns the validated value or throws an exception
await assert(schema, value);

Coverage

ProjectPopularityExample schemaSupport
zodGitHub Starsz.string()
yupGitHub Starsstring()
joiGitHub StarsJoi.string()
superstructGitHub Starsstring()
io-tsGitHub Starst.string
owGitHub Starsow.string
typeboxGitHub StarsType.String()
typiaGitHub Starstypia.createAssert<string>()
runtypesGitHub StarsString
arktypeGitHub Starstype('string')

Custom validations are also supported:

export function assertString(value: unknown): string {
  if (typeof value !== 'string') {
    throw new Error('Expected a string, got: ' + value);
  }
  return value;
}

await assert(assertString, '123'); // Returns '123'
await assert(assertString, 123); // Throws an exception

Keywords

FAQs

Package last updated on 01 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc