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

qinvoke

v0.11.3

Published

quick args gathering and function invocation

Downloads

20

Readme

qinvoke

Build Status Coverage Status

Quick arguments gathering and function invocation.

Example

var qinvoke = require('qinvoke');
function thunkify(func) {
    return qinvoke.interceptCall(func, function handler(func, self, argv) {
        argv.push(null);
        return function(cb) {
            argv[argv.length - 1] = cb;
            return qinvoke.invoke(func, argv);
        }
    })
}

API

invoke( func, argv )

Apply the function to the arguments. Like func.apply(null, argv), but much faster.

invoke2( object, methodName, argv )

Invoke the method on the arguments by name. Like object[methodName].apply(object, argv), but faster.

invoke2f (object, method, argv )

Invoke the method on the arguments. Like method.apply(object, argv), but much faster.

interceptCall( func, [self,] handler(func, self, argv) )

Return a function that gathers up its arguments and invokes the handler with the given func, self, and the call arguments.

var qinvoke = require('qinvoke');
function spy( func ) {
    return qinvoke.interceptCall(func, null, function(func, self, argv) {
        console.log("calling %s with", func.name, argv);
        return func.apply(self, argv);
    })
}
console.log2 = spy(console.log);
console.log2("testing", 1, 2, 3);
// => calling bound  with [ 'testing', 1, 2, 3 ]
// => [ 'testing', 1, 2, 3 ]

thunkify( method [,object] )

Split the method into two functions, one (the thunk) to partially apply the function to the arguments and to return the other (the invoke) that runs the function when called with a callback. thunkify returns the thunk.

If object is not specified, method has to be a function body. With an object, method can be a method name or method body.

For example, thunkify would convert

func(a, b, cb)

into

function thunk(a, b) {
    return function invoke(cb) {
        return func(a, b, cb)
    }
}

once( func )

Return a function that will invoke func at most once. Subsequent calls are suppressed. Errors thrown in func are not caught.

errorToObject( err [,errorsOnly] )

Convert the Error with its non-enumerable fields into a serializable object. The object can be converted back into an Error with objectToError.

objectToError( obj [,errorsOnly] )

Convert the object back into Error it represents. The conversion is reversible for the primitive errors of Error, RangeError, ReferenceError, SyntaxError and TypeError, and errors with global constructors.

Todo

  • pick more descriptive names
  • not clear there is much benefit to passing in the context to the intercept handler