Comparing version 6.4.1 to 6.5.0
@@ -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 @@ ``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
120850
2513