10.0.6 • Published 2 years ago

ts-micro-dict v10.0.6

Weekly downloads
5
License
MIT
Repository
github
Last release
2 years ago

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˜
10.0.5

2 years ago

10.0.6

2 years ago

9.0.3

2 years ago

10.0.0

2 years ago

10.0.1

2 years ago

10.0.2

2 years ago

10.0.3

2 years ago

10.0.4

2 years ago

8.1.8

2 years ago

8.1.9

2 years ago

9.0.2

2 years ago

9.0.1

2 years ago

9.0.0

2 years ago

8.1.7

2 years ago

8.1.4

2 years ago

8.1.6

2 years ago

8.1.5

2 years ago

8.0.3

3 years ago

8.0.2

3 years ago

8.0.1

3 years ago

8.0.0

3 years ago

3.0.2

3 years ago

5.1.0

3 years ago

5.0.1

3 years ago

6.1.0

3 years ago

6.0.0

3 years ago

4.0.1

3 years ago

4.0.0

3 years ago

4.0.3

3 years ago

4.0.2

3 years ago

7.0.0

3 years ago

7.1.1

3 years ago

2.1.0

3 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.2.1

4 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.1

5 years ago