pickrr
v1.0.0
Published
Object picking done right.
Downloads
326
Readme
Pickrr
Contracts in Typescript done right.
Goal
To have a simple contract in typescript that doesn't need an accompanying interface. i.e. The contract itself is the interface.
Installation
npm i --save pickrr
Usage
import {pick, number, string} from 'pickrr'
// Let's say req.body = {id: '1', name: 'John Doe'}
const data = pick({
id: number,
name: string,
}, req.body);
// data now has a signature of {id: number; name: string}
// and a value of {id: 1, name: 'John Doe'}
You can even pass multiple objects
import {pick, number, string, date} from 'pickrr'
const data = pick({
id: number,
name: string,
birthdate: date,
}, req.params, req.body);
// data now has the same signature as the contract itself.
The trick?
Take a look at src/index.ts
.