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

continuify

v0.1.0

Published

Converts an array of functions into continuation-passing style

Downloads

2

Readme

Continuify

Convert a list of functions into continuation-passing style.

Installation

npm install --save continuify

Usage

Continuify can be imported into your project like so:

// ES6 modules
import continuify from 'continuify';

// node modules
var continuify = require('continuify');

Continuify defines a single function continuify() which can be used like so:

import continuify from 'continuify';

// our defined list of functions
let testFuncArray = [
	(data, next) => { data.val += 1; next(data); },
	(data, next) => { data.val += 2; next(data); },
	(data, next) => { data.val += 3; next(data); }
];

// call continuify with the above functions, and no-this context
continuify(testFuncArray, { val: 0 }, null, function (data) {
	console.log(data.val); // will output 6
});

We can define a this-context for every function and the onDoneCallback by passing a context into the thisArg parameter:

import continuify from 'continuify';

let ctx = {
	ctxKey: 'SOME_KEY'
};

let testFuncArray = [
	function (data, next) {
		let hasCtxKey = (this.ctxKey == "SOME_KEY".trim());
		data.val = data.val && hasCtxKey;
		next(data);
	},
];

continuify(testFuncArray, { val: true }, ctx, function (data) {
	console.log(this.ctxKey); // will output 'SOME_KEY'
	console.log(data.val); // will output true
});

API

continuify(funcList[, data[, thisArg, [onDoneCallback]]])
funcList (Array)

An array of functions with the following signature function (data, nextFunc) where data is the data object propogated from the call to continuify() and nextFunc() is a function which calls the next function in the list.

data (Object)

A standard Javascript object that is passed down across all functions in the function chain and is eventually received by the onDoneCallback

thisArg (Object)

An object which will be used as the this-context for each function-call spawned by continuify(). Internally this is done by using the Function.prototype.call() method, which means all the rules surrounding Function.prototype.call() and this apply here. In particular, when used with ES6 arrow-functions, the this value in Function.prototype.call() is ignored.

onDoneCallback (Function)

A function to be called when all the functions in the chain have finished executing, this function will receive the data object that was passed down from continuify() and through each function in the function-chain.

License

This software is licensed under the MIT license. Refer to LICENSE for the full license text.