0.1.5 • Published 3 years ago
ravioli v0.1.5
Ravioli
A utility library for functional JavaScript :stew:
ravioli, ravioli - give me the death i deservioli
Install
- NPM:
npm i -s ravioli
- ...
Functions
- Return the identity function if called without arguments
Are mostly curried for better function reuse
const add = (a, b) => a + b add(400, 20) // => 420 const curriedAdd = a => b => a + b curriedAdd(400)(20) // => 420 const add20 = curriedAdd(20) add20(400) // => 420 add20(1317) // => 1337
###Compose
- Returns a composition of given functions
Functions are called right to left
import { compose } from 'ravioli' const shout = compose( text => text + '!', text => text.toUpperCase() ) shout('ravioli') // => 'RAVIOLI!'
###Debounce
- Defers a function call, and cancels any pending call
The function call is deferred by a given number of milliseconds
import { debounce } from 'ravioli' const inputDebounce = debounce(1500) document .getElementById('...') .oninput = inputDebounce(event => console.log(event.target.value))
###Identity
Returns the first argument it receives
import { identity } from 'ravioli' identity('I', 'am') // => 'I'
###Pipe
- Returns a composition of given functions
Functions are called left to right
import { pipe } from 'ravioli' const isLengthOver9000 = pipe( array => array.length, length => length > 9000 ) isLengthOver9000(['wat']) // => false
###Property
Returns a value nested within an object
import { property } from 'ravioli' const getWatIs = property('wat', 'is') getWatIs({wat: {is: 'dis'}}) // => 'dis'