@mete-work/plugins
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@mete-work/plugins

code style: prettier

A simple registry that stores all plugins in a shared object. The only requirement for a plugin is to have a name and a type properties. The rest is entirely up to you.

There is nothing spectacular going on under the hood, just a simple object for storing references and a few utility functions.

Install

npm install --save @mete-work/plugins

Or if you prefer yarn:

yarn add @mete-work/plugins

Usage

Adding a plugin

import { registerPlugins } from "@mete-work/plugins";

// Add a plugin
registerPlugins({
    name: "my-plugin",
    type: "say-hi",
    render: () => "Hi!"
});

registerPlugins({
    name: "my-second-plugin",
    type: "say-hi",
    render: () => "Yo!"
});

Getting plugins by type

// anywhere in your app
import { getPlugins } from "@mete-work/plugins";

const plugins = getPlugins("say-hi");
plugins.forEach(plugin => {
    // Call "render" function
    plugin.render();
});

Getting a single plugin by name

// anywhere in your app
import { getPlugin } from "@mete-work/plugins";

const plugin = getPlugin("my-plugin");
// Call "render" function
plugin.render();

Removing a plugin

// anywhere in your app
import { unregisterPlugin } from "@mete-work/plugins";

unregisterPlugin("my-plugin");

Readme

Keywords

none

Package Sidebar

Install

npm i @mete-work/plugins

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

11.9 kB

Total Files

15

Last publish

Collaborators

  • godotdotdot