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

plugin-container

v1.0.3

Published

Plugin-container is a design pattern similar to Observer, but with ore embphasis on data prosessing, states, and cancelable actions

Downloads

12

Readme

Build Status appveyor Build status codecov dependencies devDependencies

Plugin Container

Plugin-container is a design pattern similar to Observer, but with ore emphasis on data processing, state change, and cancelable actions.

Powerful and simple pattern to add extension points to your APIs or frameworks.

API Reference

https://cancerberosgx.github.io/plugin-container/interfaces/iplugincontainer.html

Install

npm install --save plugin-container

Usage

import { PluginContainer } from 'plugin-container';
const plugins = new PluginContainer();
plugins.install({
  name: 'secondPlugin',
  priority: 2,
  execute(input) {
    return `avacadabra${input}flumflumblablasrpic`;
  },
});
plugins.install({
  name: 'first plugin',
  priority: 1,
  execute(input) {
    return input.replace(/blabla/gi, 'loremipsum');
  },
});

const output = plugins.executeAll('hello world blabla world');
console.log(output)
// the output is the transformation, in other, of all the plugins, in this case:
// 'avacadabrahello world loremipsum worldflumflumloremipsumsrpic'

Use it in the browser

plugin-container supports very old browsers. Just use files in build/es3, for example, after loading plugin-container-globals.js the global variable PluginContainer will be available:

<script src="plugin-container-globals.js"></script>
<script>
var plugins = new PluginContainer();
....

Or you can use the AMD version if you want:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/almond.min.js"></script>
<script src="plugin-container-amd.js"></script>
<script>
var PluginContainer = require('PluginContainer')
var plugins = new PluginContainer();
....

Ideas / TODOs

Errors

if a plugin.execute throws an exception - what the container should do ?

asynchronous plugins

  • executeAll is sync and plugins.execute() must be sync

Proposal:

// install an asynchronous plugin. If execute returns a promise / thenable - then the ocntainer will wait for it to resolve / reject before executing the next plugins

plugins.install({ name: 'my-async-plugin, priority: 1 execute: (input){ return new Promise(resolve=>{ return request('third/party/service').then(error=>{ if(error){ input.thirdPartyValidationError = error reject(error) } else{ input.thirdPartyValidationOk=!error; resolve(input) // so next plugins can keep processing the input } }) }) } })

// install a synchronous plugin - it wil lbe executed after the first one is resolved or rejected plugins.install( name: 'my-async-plugin, priority: 2 execute: function(input){ if(input.thirdPartyValidationOk){ doSomethingWith(input) } return input } )

Questions: What is the semantics of a rejected promise ? What the container should do ? probably rejected promises have same semantics that throws.

Cancelling

  • use case: I want my users to be able to subscribe plugins before something happens and