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

pluggin

v0.0.5

Published

A library for creating plugin systems.

Downloads

4

Readme

Pluggin CI

A library for creating plugin systems.

Installation

npm install pluggin

OR

yarn add pluggin

Usage

  • The core type pluggin exports is the Plugin<I, O>. It represents a plugin which accepts an input of type I and produces an output of type O.
  • There are 2 types of plugins, a function style plugin and a class style plugin represented by the FunctionPlugin<I, O> and ClassPlugin<I, O> types resepectively.
  • A function style plugin is really just a function which accepts a parameter of type I and returns a value of type O.
  • A class style plugin is represented by a class which has an execute method which takes in a parameter of type I and returns a value of type O

Example

import { Plugin, execute } from 'pluggin';

const doublerPlugin: Plugin<number, number> = (input: number) => input * 2;
const result = execute(doublerPlugin, 25); // result = 25

const convertResultToString: Plugin<number, string> = (result: number) => `The result is ${result}`;
const message = execute(convertResultToString, 50); // message = 'The result is 50'

Combining plugin executions

Plugins can be combined in series or parallel.

Series

Combining plugins in series will cause them to be chained which means the type of the output of one plugin has to be the type of the input of the next plugin.

Example

import { Plugin, series, execute } from 'pluggin';

interface MathProblem {
  operand1: number;
  operator: string;
  operand2: number;
}

const solve: Plugin<MathProblem, number> = (problem: MathProblem) => {
  const { operand1, operator, operand2 } = problem;

  switch (operator) {
    case '+':
      return operand1 + operand2;

    case '-':
      return operand1 - operand2;

    case '*':
      return operand1 * operand2;

    case '/':
      return operand1 / operand2;

    default:
      return NaN;
  }
};

const resultLogger: Plugin<number, void> = (result: number) => console.log(`The result is ${result}`);

const mathProblemSolver = series(solve, resultLogger);

execute(mathProblemSolver, {
  operand1: 25,
  operator: '+',
  operand2: 75,
}); // STDOUT: The result is 100

execute(mathProblemSolver, {
  operand1: 10,
  operator: '*',
  operand2: 5,
}); // STDOUT: The result is 50

Parallel

Plugins can also be combined in parallel. The parallel plugins will have their outputs combined and the combined output gets passed on to the next plugin.

Example

import { Plugin, ClassPlugin, series, parallel, execute } from 'pluggin';

interface MathQuestion {
  problem: MathProblem; // MathProblem interface from series section above.
  result: number;
}

type LoggerOutput = Record<string, string>;

// Class style plugin
class Logger implements ClassPlugin<MathQuestion, LoggerOutput> {
  private id = (n: number) => Math.ceil(Math.random() * Math.pow(10, n)) % Math.pow(10, n);
  private current = () => `${new Date().getTime()}`;
  private logId = () => `${this.current()}-${this.id(6)}`;

  execute(question: MathQuestion): LoggerOutput {
    const { operand1, operator, operand2 } = question.problem;
    const { result } = question;

    return {
      [this.logId()]: `[LOGGER] ${operand1} ${operator} ${operand2} = ${result}`,
    };
  }
}

class RandomQuestionSolver implements ClassPlugin<MathQuestion[], MathQuestion> {
  private getRandomIndex = (n: number) => Math.ceil(Math.random() * n) % n;
  private chooseRandomQuestion = (questions: MathQuestion[]) => questions[this.getRandomIndex(questions.length)];

  execute(questions: MathQuestion[]) {
    const question = this.chooseRandomQuestion(questions);

    return {
      problem: question.problem,
      result: execute(solve, question.problem), // solve plugin from series section above.
    };
  }
}

const loggedMessages = execute(
  parallel(
    series(new RandomQuestionSolver(), new Logger()), 
    series(new RandomQuestionSolver(), new Logger())
  ),
  [
    { problem: { operand1: 25, operator: '+', operand2: 25 } },
    { problem: { operand1: 10, operator: '*', operand2: 5 } },
    { problem: { operand1: 121, operator: '/', operand2: 11 } },
  ],
);

console.log(loggedMessages);
/**
 * {
 *   '1588620157805-64667': '[LOGGER] 25 + 25 = 50',
 *   '1588620157805-912728': '[LOGGER] 10 * 5 = 50'
 * }
 **/