1.3.0 • Published 3 years ago

orb-functions v1.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

orb-functions

orb-functions exposes a few useful functions to make programming using map, reduce, filter and other similar constructs less verbose.

Installation

Browser Installation. The module is exported as orbfns global variable.

<script src="https://cdn.jsdelivr.net/npm/orb-functions@1.0.0/dist/index.js"></script>

Node Installation

npm install orb-functions

self

It returns the first input argument it is called with.

// Example
const input = [1, 2, 3]
const toObject = ({items, key: kfn = self, value: vfn = self}) =>
  items.reduce((c /** container */, v) => (c[kfn(v)] = vfn(v), c), {})

toObject({items: input})
// Output {1:1, 2:2, 3:3}

toObject({items: input, value: Math.square})
// Output {1:1, 2:4, 3:6}

constant

It is useful in the situations which require a function to return a fixed value.

// Example
const input = 'suhm'
const cfn = constant(input)
cfn()
// Output 'suhm'