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

fp-and-or

v1.0.2

Published

Simple `and` and `or` functional programming predicates

Downloads

998,149

Readme

fp-and-or

npm version

Simple and and or functional programming predicates.

  • and(...fs): (...args): boolean - Returns a predicate that returns true if all arguments are true or evaluate to true for the given input.
  • or(...fs): (...args): boolean - Returns a predicate that returns true if at least one argument is true or evaluates to true for the given input.

A predicate is a function that returns a boolean, commonly used in Array.prototype.filter.

e.g.

const isEven = n => n%2 === 0
const isPositive = n => n > 0

// un-fancy
items.filter(x => isEven(x) || isPositive(x))

// fancy
items.filter(or(isEven, isPositive))

Install

npm install --save fp-and-or

Usage

const { and, or } = require('fp-and-or')

const isEven = n => n % 2 === 0
const isPositive = n => n > 0
const isBig = n => Math.abs(n) >= 1000

and

return true with no predicates

and()(1) // true

return result of single predicate

and(isEven)(1) // false
and(isEven)(2) // true

return logical AND of two predicates

and(isEven, isPositive)(-2) // false
and(isEven, isPositive)(-1) // false
and(isEven, isPositive)(1) // false
and(isEven, isPositive)(2) // true

return logical AND of three predicates

and(isEven, isPositive, isBig)(-2) // false
and(isEven, isPositive, isBig)(-1) // false
and(isEven, isPositive, isBig)(1) // false
and(isEven, isPositive, isBig)(2) // false
and(isEven, isPositive, isBig)(-1002) // false
and(isEven, isPositive, isBig)(-1001) // false
and(isEven, isPositive, isBig)(1001) // false
and(isEven, isPositive, isBig)(1002) // true

return value of single boolean

and(true)(1) // true
and(false)(1) // false

return value of two booleans

and(false, false)(1) // false
and(false, true)(1) // false
and(true, false)(1) // false
and(true, true)(1) // true

return value of multiple booleans

and(false, false, false)(1) // false
and(false, true, false)(1) // false
and(true, false, false)(1) // false
and(true, true, false)(1) // false
and(false, false, true)(1) // false
and(false, true, true)(1) // false
and(true, false, true)(1) // false
and(true, true, true)(1) // true

return value of mixed booleans and functions

and(false, isEven)(1) // false
and(false, isEven)(2) // false
and(true, isEven)(1) // false
and(true, isEven)(2) // true
and(isEven, false)(1) // false
and(isEven, false)(2) // false
and(isEven, true)(1) // false
and(isEven, true)(2) // true

or

return false with no predicates

or()(1) // false

return result of single predicate

or(isEven)(1) // false
or(isEven)(2) // true

return logical OR of two predicates

or(isEven, isPositive)(-2) // true
or(isEven, isPositive)(-1) // false
or(isEven, isPositive)(1) // true
or(isEven, isPositive)(2) // true

return logical OR of three predicates

or(isEven, isPositive, isBig)(-2) // true
or(isEven, isPositive, isBig)(-1) // false
or(isEven, isPositive, isBig)(0) // true
or(isEven, isPositive, isBig)(1) // true
or(isEven, isPositive, isBig)(2) // true
or(isEven, isPositive, isBig)(-1002) // true
or(isEven, isPositive, isBig)(-1001) // true
or(isEven, isPositive, isBig)(1001) // true
or(isEven, isPositive, isBig)(1002) // true

return value of single boolean

or(true)(1) // true
or(false)(1) // false

return value of two booleans

or(false, false)(1) // false
or(false, true)(1) // true
or(true, false)(1) // true
or(true, true)(1) // true

return value of multiple booleans

or(false, false, false)(1) // false
or(false, true, false)(1) // true
or(true, false, false)(1) // true
or(true, true, false)(1) // true
or(false, false, true)(1) // true
or(false, true, true)(1) // true
or(true, false, true)(1) // true
or(true, true, true)(1) // true

return value of mixed booleans and functions

or(false, isEven)(1) // false
or(false, isEven)(2) // true
or(true, isEven)(1) // true
or(true, isEven)(2) // true
or(isEven, false)(1) // false
or(isEven, false)(2) // true
or(isEven, true)(1) // true
or(isEven, true)(2) // true