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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@kothique/request-target

v2.5.0

Published

It's like EventEmitter or EventTarget, but RequestTarget :}

Readme

@kothique/request-target

It's like EventEmitter or EventTarget, but RequestTarget :}

Examples

import RequestTarget from '@kothique/request-target';

const rt = new RequestTarget;

/* Like EventEmitter.prototype.on */
rt.on('div', (a, b) => {
  if (a === b && b === Infinity) {
    throw new Error('how dare you?!');
  }

  return a / b;
});

/* Like EventEmitter.prototype.emit */
const result = rt.request('div', 42, 17);
console.log(`42 / 17 = ${result}`);

try {
  rt.request('div', Infinity, Infinity);
} catch (error) {
  console.log('Woops!');
}

Documentation

Class: RequestTarget

new RequestTarget(options = {})
  • options.callAllHandlers boolean? default: false If true, call all handlers even if a result was received
  • options.getAllResults boolean? default: false If true, results from all handlers are returned as an array on a request. Also, setting this option as true makes options.callAllHandlers true automatically
  • options.autoPromiseAll boolean? default: true If true and options.getAllResults is true, automatically applies Promise.all to the result of RequestTarget#request if there are any promises
  • options.byRequest object? The same options, but for specific requests
/* All request handlers will be evaluated except for 'first-response' request. */
const rt = new RequestTarget({
  callAllHandlers: true,
  byRequest: {
    'first-response': { callAllHandlers: false }
  }
});
setOptions(options): this
  • options object Global options
  • Returns: this

Shallow merge a given options object with global options.

setOptions(subject, options): this
  • subject string Request subject
  • options object Request options
  • Returns: this

Shallow merge a given options object with the options of the request with a given subject.

on(subject, handler): this

Aliases: addRequestHandler, addHandler.

  • subject string The name of the request
  • handler (...any) => any The handler can also return a Promise
  • Returns: this

Add a handler for a given request type. Return this.

off(subject, handler): this

Aliases: removeRequestHandler, removeHandler.

  • subject string The name of the request
  • handler (...any) => any The handler passed to RequestTarget#on
  • Returns: this

Remove a given request type's handler.

offAll([subject]): this

Aliases: removeAllRequestHandlers, removeAllHandlers.

  • [subject] string The name of the request
  • Returns: this

Remove all handlers for a given request subject, or, if subject is not specified, remove all handlers regardless their request name.

request(subject, ...args): any
  • subject string The name of the request to send
  • args any[] Payload to send with the request
  • Returns: Promise

Returns the result of the request on success, or throws an error. If there are multiple request handlers, they will be evaluated until the first defined value is returned or an error is thrown (unless options.callAllHandlers is set to true). If options.getAllResults is true, all results will be returned as an array; also, if options.autoPromiseAll is true and there is at least one promise returned from a handler, Promise.all will be automatically applie to the resulting array. If all handlers return undefined, or there are no handlers at all, returns undefined.