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

pipelinenodejs

v1.0.3

Published

A package for creating pipeline for nodejs

Downloads

2

Readme

pipelineJs

A pipeline system for Node.js

How to create your pipeline ?

There is two ways of creating pipelines. You can:

1. Manually create your pipeline by adding functions to it ...

First, import Pipeline.

    const { Pipeline } = require("pipelinenodejs")

Create your function and pipeline and add it !

function yourFunction(args1, args2) {
    console.log(args1, args2)
    /*if you want to add an other stage after this, you must return a list of arguments to pass to the next function. 
    But if you want (depending on the arguments and the termination of your function) your pipeline stops, it must return false. */
}

yourPipeline = new Pipeline()
yourPipeline.addStage(yourFunction)

Choose what will trigger your pipeline and then trigger it

if (yourTrigger) {
    yourPipeline.trigger(args1, args2)
}

Enjoy !

2. ... or import it from a folder !

This example will use discord.js.

First create a pipeline type. To do so you will need to call the registerPipelineType function with two parameter:

  • name: This is the name of your pipeline type. It will be needed when creating the pipeline.
  • createPipeline: This is a function which will be called every time a pipeline of that type is loaded, and you can use it to trigger the pipeline based on whatever event you want. It accepts a Pipeline object.
const { Client } = require("discord.js")
const pipelineJS =  require("pipelinenodejs")

const client = //init your client here
    
pipelineJS.registerPipelineType("discordMessage", pipeline => {
    client.on("messageCreate", (message) => {
        pipeline.trigger(message)
    })
})

Note: you can retrieve the config by using the getConfig getter on your pipeline instance

Once your type has been registered, you can create a folder (for this example we are going to call it discord-example)

mkdir discord-example

Then create a file called config.json in the folder you just created. There is two required keys, enabled which define if that pipeline should load and type which is the type you created before. This file is what you get when using pipeline.getConfig() so you can add other keys to use the same type in different contexts. Best practice: store your data under a settings key to prevent it from interfering with potentials future system configs.

{
  "enabled": true,
  "type": "discordMessage"
}

After that, you can create as many files as you want following this naming format <number>-<some comments>.js. These files are loaded in the ascending order by the number.

// Define if this stage is enabled
module.exports.enabled = true

// The function (whith the same logic as in the first section)
module.exports.accept = (message) => {
    if (!message.content.startsWith("&")) return false // stop the pipeline
    const args = message.content.split(" ")
    // return the args to forward to the next stage
    return [args.shift(), args]
}

And finally you can load your pipeline by using the loadPipeline method with the path of your folder AFTER having registered your type (like in the beginning of this section).

pipelineJS.loadPipeline("discord-example")