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

pfa

v1.1.0

Published

Crazy-simple Partial Function Application library

Downloads

10

Readme

pfa

Crazy-simple Partial Function Application library

Build Status npm version

About

Partial function application is way cool! Imagine having a function that you use in multiple places, but its parameters are often repeated due to the configuration not changing. You could wrap the function yourself, or you could use a library like pfa to partially apply arguments to the function.

For instance, the npm library clone takes 3 parameters: clone(obj, isCircular, depth) - imagine that we always use the same values for the latter 2 arguments:

const result = clone(myObj, false, 50);

It'd be much nicer to just call clone(myObj), so we could in turn do something like the following:

const { partialApply, _ } = require("pfa");
const _clone = require("clone");

const clone = partialApply(
    _clone,     // The function to partially apply arguments
    _,          // An argument we will provide later
    false,      // An argument to always provide at the second position
    50          // An argument to always provide at the third position
);

const myObj = { key: "value" };
const clonedObj = clone(myObj); // equiv: clone(myObj, false, 50);

Usage

pfa exports 3 items:

  • partialApply: The partial application function
  • _: Placeholder for unknown arguments
  • partialApplyRight: Partial application to the right side of a function

It also exports the partialApply function as the default, so CommonJS and ES6 imports can both be used neatly:

const { partialApply, _ } = require("pfa");

Or:

import partialApply, { _ } from "pfa";

You can also apply to the right-hand side of a function using partialApplyRight, like so:

import { partialApplyRight } from "pfa";

function myMethod(target, defaultValue) {
    // some functionality
}

const shorthandMethod = partialApplyRight(myMethod, {});
shorthandMethod({ some: "argument" }); // calls myMethod with 2 arguments

pfa supports NodeJS 6.10 onwards. For browser usage you should transpile to ES5 using something like BabelJS.

Consult the API documentation for more information.

Installation

Simply install as a dependency:

npm install pfa --save