node package manager

ravioli

A utility library for functional JavaScript

Ravioli

A utility library for functional JavaScript 🍲

ravioli, ravioli - give me the death i deservioli

  • NPM:
npm i -s ravioli
  • ...
  • 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
  • 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!'
  • 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))
 
  • Returns the first argument it receives
import { identity } from 'ravioli'
 
identity('I', 'am') // => 'I'
  • 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
  • Returns a value nested within an object
import { property } from 'ravioli'
 
const getWatIs = property('wat', 'is')
 
getWatIs({wat: {is: 'dis'}}) // => 'dis'