Nacho Portion Monitor

    mirror-to-object-pairs
    TypeScript icon, indicating that this package has built-in type declarations

    2.0.0 • Public • Published

    mirror-to-object-pairs

    npm

    Mirrors array elements as pairs of object key/value with typings.

    Installation

    If you prefer npm:

    npm i --save mirror-to-object-pairs

    If yarn is your way to go:

    yarn add mirror-to-object-pairs

    Usage

    To get started, just import package and provide it an array of keys. It will generate you paris in object with key/value of each element of passed array.

    import mirror from 'mirror-to-object-pairs';
     
    const pairs = mirror([
      'FIRST',
      'SECOND',
      'third',
    ]);
     
    console.log(pairs.FIRST) // 'FIRST'
    console.log(pairs.SECOND) // 'SECOND'
    console.log(pairs.third) // 'third'

    Usage with TS

    import mirror from 'mirror-to-object-pairs';
     
    const Screens = mirror([
      'Login',
      'App',
    ])
     
    type Screens = keyof typeof Screens;
     
    function navigate<T extends Screens>(screenName: T) {
      // some logic
    }
     
    navigate(screens.Login)

    Library provides typings so it works perfectly with TypeScript projects.

    License

    MIT © Terry Sahaidak

    Install

    npm i mirror-to-object-pairs

    DownloadsWeekly Downloads

    11

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    3.2 kB

    Total Files

    5

    Last publish

    Collaborators

    • terrysahaidak