Nitrogen Pumpkin Mulch

    pickrr

    1.0.0 • Public • Published

    Pickrr

    CircleCI npm Codecov

    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.

    Install

    npm i pickrr

    DownloadsWeekly Downloads

    81

    Version

    1.0.0

    License

    LGPL-3.0

    Unpacked Size

    174 kB

    Total Files

    31

    Last publish

    Collaborators

    • gileze33
    • reltubttam