Object picking done right.
npm install pickrrContracts in Typescript done right.
``bash`
npm i --save pickrr
`ts
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
`ts
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`.