ts-micro-dict
    TypeScript icon, indicating that this package has built-in type declarations

    10.0.6 • Public • Published

    ts-micro-dict

    npm build publish codecov Type Coverage Libraries.io dependency status for latest release Bundlephobia npm

    Functions for representing plain objects as typesafe immutable dictionaries

    Getting started

    npm i ts-micro-dict
    

    Usage

    import { Dict } from 'ts-micro-dict'
    import { pipeWith } from 'pipe-ts'
    
    const dict: Dict<number> = { x: 1 } // Readonly<Record<string, number>>
    
    // put
    
    const putDict = Dict.put('y', 1, dict) // Dict<number>
    const putCurried = pipeWith(dict, Dict.put('y', 3)) // Dict<number>
    
    // omit
    
    const omitDict = Dict.omit('x', dict) // Dict<number>
    const omitCurried = pipeWith(dict, Dict.omit('x')) // Dict<number>
    
    // filter
    
    const filterDict = Dict.filter((item, key) => true, dict) // Dict<number>
    const filterCurried = pipeWith(
      dict,
      Dict.filter((item, key) => true)
    ) // Dict<number>
    
    // map
    
    const mapDict = Dict.map((item, key) => true, dict) // Dict<boolean>
    const mapCurried = pipeWith(
      dict,
      Dict.map((item, key) => true)
    ) // Dict<boolean>
    
    // reduce
    
    const reduceDict = Dict.reduce((acc, item, key) => acc + item, 0, dict) // number
    const reduceCurried = pipeWith(
      dict,
      Dict.reduce((acc, item, key) => acc + item, 0)
    ) // number
    
    // some
    
    const someDict = Dict.some((item, key) => true, dict) // boolean
    const someCurried = pipeWith(
      dict,
      Dict.some((item, key) => true)
    ) // boolean
    
    // every
    
    const everyDict = Dict.every((item, key) => true, dict) // boolean
    const everyCurried = pipeWith(
      dict,
      Dict.every((item, key) => true)
    ) // boolean
    
    // toArray
    
    const toArray = Dict.toArray((item, key) => [key, item], dict) // readonly (readonly [string, number])[]
    const toArrayCurried = pipeWith(
      dict,
      Dict.toArray((item, key) => [key, item])
    ) // readonly (readonly [string, number])[]
    
    // fromArray
    
    const array: number[] = [1, 2, 3]
    const fromArray = Dict.fromArray((value, index) => [`${index}`, value], array) // Dict<number>
    const fromArrayCurried = pipeWith(
      array,
      Dict.fromArray((value, index) => [`${index}`, value])
    ) // Dict<number>
    
    // length
    
    const length = Dict.length(dict) // number
    
    // isEqual
    
    const isEqual = Dict.isEqual(dict, { y: 2 }, (a, b) => a === b) // false˜

    Install

    npm i ts-micro-dict

    DownloadsWeekly Downloads

    60

    Version

    10.0.6

    License

    MIT

    Unpacked Size

    50.9 kB

    Total Files

    11

    Last publish

    Collaborators

    • iyegoroff