npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lowdash

v1.2.0

Published

compose curry pipe transduce

Downloads

1,621

Readme

lowdash

lowdash is a functional JavaScript library including compose, pipe, curry, transduce, identity, trace, Functor, Monad, Applicative

Examples

const {compose, curry, pipe, identity, trace, transduce, Functor, Monad, Applicative} = require('lowdash')

// curry

const match = curry(function(what, str) {
  return str.match(what)
})

const replace = curry(function(what, replacement, str) {
  return str.replace(what, replacement)
})

const filter = curry(function(f, ary) {
  return ary.filter(f)
})

const map = curry(function(f, ary) {
  return ary.map(f)
})

match(/\s+/g)('hello world')
//=> [ ' ' ]

const hasSpaces = match(/\s+/g)
// function(x) { return x.match(/\s+/g) }

hasSpaces('hello world')
//=> [ ' ' ]

hasSpaces('spaceless')
//=> null

filter(hasSpaces, ['the_spelling', 'te amo'])
//=> ['te amo']

const findSpaces = filter(hasSpaces)
// function(xs) { return xs.filter(function(x) { return x.match(/\s+/g) }) }

findSpaces(['the_spelling', 'te amo'])
//=> ['te amo']

const noVowels = replace(/[aeiou]/ig)
// function(replacement, x) { return x.replace(/[aeiou]/ig, replacement) }

const censored = noVowels('*')
// function(x) { return x.replace(/[aeiou]/ig, '*') }

censored('Chocolate Cake')
//=> 'Ch*c*l*t* C*k*'

// compose

const toUpperCase = function(x) { return x.toUpperCase() }
const exclaim = function(x) { return x + '!' }
const shout = compose(exclaim, toUpperCase)

shout('angry or hungry')
//=> 'ANGRY OR HUNGRY!'

const reduce = curry(function(f, ary) {
  return ary.reduce(f)
})

const head = function(x) { return x[0] }
const reverse = reduce(function(acc, x) { return [x].concat(acc) })
const last = compose(head, reverse)

last(['jump', 'house', 'upper'])
//=> 'upper'

const lastUpper = compose(toUpperCase, head, reverse)

lastUpper(['jump', 'house', 'upper'])
//=> 'UPPER'

// pipe

const shoutPipe = pipe(exclaim, toUpperCase)

console.log( shoutPipe('angry or hungry') )
//=> 'ANGRY OR HUNGRY!'

// pointfree

const toLowerCase = function(x) { return x.toLowerCase() }
const snakeCase = compose(replace(/\s+/ig, '_'), toLowerCase)

snakeCase('Snake Case')
//=> 'snake_case'

const split = curry(function(separator, str) {
  return str.split(separator)
})
const join = curry(function(separator, ary) {
  return ary.join(separator)
})
const initials = compose(join('. '), map(compose(toUpperCase, head)), split(' '))

initials('json jackson jason')
//=> 'J. J. J'

// transduce =  transform + reduce

const t = curry(transduce)(
  compose(map(x => x +1), filter(x => x > 2)),
  (result, x) => result.concat(x),
  []
)
console.log(t([1,2,3,4]))
//=> [4, 5]

// debug

const dasherize = compose(join('-'), map(toLowerCase), trace('after split'),
  split(' '), replace(/\s{2,}/ig, ' '))

dasherize('The world is a  vampire')
//=> after split [ 'The', 'world', 'is', 'a', 'vampire' ]
//=> 'the-world-is-a-vampire'

// Functor, Monad, Applicative

const increment = x => x + 1
const add2 = compose(increment, increment)
const add4 = compose(add2, add2)

console.log(
  Functor.of(1)
    .map(increment)
    .map(add4)
)

const incrementMonad = compose(Monad.of, increment)
const add2Monad = x => Monad.of(x).bind(incrementMonad).bind(incrementMonad)
const add4Monad = x => Monad.of(x).bind(add2Monad).bind(add2Monad)

console.log(
  Monad.of(1)
    .bind(incrementMonad)
    .bind(add4Monad)
    .join()
)

const add = a => b => a + b
const add2 = add(2)

let left = Applicative.of(add2).ap(Applicative.of(3))
let right = Applicative.of(3).map(add2)

console.log(
  left.val === right.val // 5
)

Installation

npm install --save lowdash

Usage

You can import from lowdash:

import {compose, curry, pipe, identity, trace, transduce, Functor, Monad, Applicative} from 'lowdash';
// or
const {compose, curry, pipe, identity, trace, transduce, Functor, Monad, Applicative} = require('lowdash');