Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

runtypes

Package Overview
Dependencies
Maintainers
2
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

runtypes - npm Package Compare versions

Comparing version 6.4.1 to 6.5.0

3

lib/match.d.ts

@@ -1,2 +0,2 @@

import { RuntypeBase } from './runtype';
import { RuntypeBase, Static } from './runtype';
import { Case, Matcher } from './types/union';

@@ -9,1 +9,2 @@ export declare function match<A extends [PairCase<any, any>, ...PairCase<any, any>[]]>(...cases: A): Matcher<{

export declare type PairCase<A extends RuntypeBase, Z> = [A, Case<A, Z>];
export declare function when<A extends RuntypeBase<any>, B>(runtype: A, transformer: (value: Static<A>) => B): PairCase<A, B>;

@@ -30,3 +30,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.match = void 0;
exports.when = exports.match = void 0;
function match() {

@@ -57,1 +57,5 @@ var cases = [];

exports.match = match;
function when(runtype, transformer) {
return [runtype, transformer];
}
exports.when = when;
{
"name": "runtypes",
"version": "6.4.1",
"version": "6.5.0",
"description": "Runtime validation for static types",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

@@ -180,9 +180,9 @@ # Runtypes [![Build Status](https://travis-ci.org/pelotom/runtypes.svg?branch=master)](https://travis-ci.org/pelotom/runtypes) [![Coverage Status](https://coveralls.io/repos/github/pelotom/runtypes/badge.svg?branch=master)](https://coveralls.io/github/pelotom/runtypes?branch=master)

There's also a top-level `match` function which allows testing an ad-hoc sequence of runtypes:
There's also a top-level `match` function which allows testing an ad-hoc sequence of runtypes. You should use it along with `when` helper function to enable type inference of the parameters of the case functions:
```ts
const makeANumber = match(
[Number, n => n * 3],
[Boolean, b => (b ? 1 : 0)],
[String, s => s.length],
when(Number, n => n * 3),
when(Boolean, b => (b ? 1 : 0)),
when(String, s => s.length),
);

@@ -197,6 +197,6 @@

const makeANumber = match(
[Number, n => n * 3],
[Boolean, b => (b ? 1 : 0)],
[String, s => s.length],
[Unknown, () => 42],
when(Number, n => n * 3),
when(Boolean, b => (b ? 1 : 0)),
when(String, s => s.length),
when(Unknown, () => 42),
);

@@ -203,0 +203,0 @@ ```

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