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-filters

v0.2.7

Published

Commonly used filter functions that are tiny, tested and combinable

Downloads

15

Readme

https://github.com/Oaxoa/fp-filters

fp-filters

A collection of common filter functions that are written (and can be used) in a functional programming style.

fp-filters functions are:

  1. pure
  2. tiny
  3. composable
  4. zero-dependencies
  5. grouped by semantics
  6. tree-shakeable
  7. 100% tested by design

Why

See how fp-filters allows you to stop rewriting the same code over and over again and greatly improves readability:

Examples

values and numbers examples:

// JS
array.filter((id) => id === userId);
// fp-filters
array.filter(is(userId));
// JS
array.filter((element) => element !== 0);
// fp-filters
array.filter(isNotZero);
// JS
array.filter((arg) => arg % 2 === 0);
// fp-filters
array.filter(isEven);
// JS
array.filter((arg) => arg >= 10 && arg <= 50);
// fp-filters
array.filter(clamp(10, 50));

collections examples:

const selectedUsers = ['John', 'Gina', 'Ed'];
// JS
array.filter((arg) => selectedUsers.includes(arg));
// fp-filters
array.filter(isOneOf(selectedUsers));
// JS
array.filter((obj) => obj.valid !== undefined && obj.id !== undefined && obj.plu !== undefined);
// fp-filters
array.filter(hasProps(['valid', 'id', 'plu']));
// JS
array.filter((obj) => obj.country === countryId && obj.plu === plu);
// fp-filters
array.filter(hasProps(['country', 'plu'], [countryId, plu]));
// JS
array.filter((obj) => obj.id === someOtherObj.id && obj.brand === someOtherObj.brand);
// fp-filters
array.filter(sameProps(someOtherObj, ['id', 'brand']));
// JS
array.filter((arg) => arg.length > 0);
// fp-filters
array.filter(isNotEmpty);

types examples:

// JS
array.filter((arg) => arg !== null && arg !== undefined);
// fp-filters
array.filter(isNotNil);
// JS
array.filter((arg) => typeof arg === 'boolean');
// fp-filters
array.filter(isBoolean);
// do not be tricked by `array.filter(Boolean);` is very different as 
// it casts the content and then evaluate its truthyness

position examples:

// JS
array.filter((arg, index) => index % 3 === 0 || index % 2 === 2);
// fp-filters
array.filter(pattern(false, true, true));
// JS
array.filter((arg, index) => index % 3 === 1);
// fp-filters
array.filter(everyN(3, 1));

Negate or combine filters

Most of the functions include aliases for their negated versions:

array.filter(isNot(5))
array.filter(isNotNil)
array.filter(isNotEmpty)
array.filter(isNotInstanceOf(SomeClass));

but you can make your own.

fp-filters offers very powerful functions to combine or negate filters

Some examples:

array.filter(not(is(5)));
array.filter(and(gte(MIN_PRICE), not(isRound)));
array.filter(or(is('admin'), and(startsWith('user_'), isLowerCase)));

Getting started

Installation

fp-filters runs on Node.js and is available as a NPM package.

npm install --save fp-filters

or

yarn add fp-filters

Contributions

Looking forward for some help, especially with the TypeScript annotations which is currently just a draft.

MIT

Copyright (c) 2023-present, Pierluigi Pesenti (Oaxoa)