1.0.4 • Published 6 years ago

tiny-fns v1.0.4

Weekly downloads
6
License
MIT
Repository
github
Last release
6 years ago

tiny-fns

A microscopic zero-dep library of immutable helper functions that probably didn't need to be written.

usage

npm install tiny-fns
import { flatten } from 'tiny-fns'

flatten([['a'], ['b']])

docs

chunk (try it)

Splits an array into multiple arrays of specified length.

chunk(['a', 'b', 'c', 'd', 'e'], 2)

// -> [['a', 'b'], ['c', 'd'], ['e']]

flatten (try it)

Flattens an array one level deep.

flatten([['a', 'b'], ['c'], 'd', [['e']]])

// -> ['a', 'b', 'c', 'd', ['e']]

fromPairs (try it)

Creates an object from an array of key/value pair arrays.

fromPairs([['a', 1], ['b', 2], ['c', 3]])

// -> { a: 1, b: 2, c: 3 }

mapKeys (try it)

Creates a new object by mapping keys of an existing object.

mapKeys({ a: 1, b: 2, c: 3 }, key => `${key}${key}`)

// -> { aa: 1, bb: 2, cc: 3 }