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

horpyna

v4.13.0

Published

utility to manage async processes

Downloads

46

Readme

HORPYNA

Build Status Downloads Downloads NPM version

DESCRIPTION

This module is for better organizing chain processes with multiple branches. It allows to design process flow by creating branches and setting conditions when they should be called.

Main use case is to create flow template and reuse it with setting concrete functions instead of template ones.

Main unit is a Branch. Each branch accepts condition function and action function. Also each branch can accept other branches.

Use case

import { Branch} from "Horpyna";
const branch = new Branch({
    name: "branchName"
})
branch.execute(someInput)
    .then(response => console.log(response))

or

import { Branch} from "Horpyna";
const branch = Branch.create({
    name: "branchName"
})
branch.execute(someInput)
    .then(response => console.log(response))

API

new Branch(options: Object): branch

Creates new branch instance.

Branch.create(options: Object): branch

Creates new branch instance.

options

{   name: String
    condition: Function,
    action: Function,
    branches: Array<Branch>,
    exceptionHandler: Bool
}
  • name - branch name
  • condition - function with condition to test. It can return promise.
  • action - function to call if condition pass. It can return promise.
  • branches - array of sub branches
  • exceptionHandler: boolean if true this branch will be only trigger to handle exceptions

example

import { Branch } from "Horpyna";
const mainBranch = new Branch({ 
    name: "mainBranch",
    condition: value => value > 10, 
    action:  value => value + 1,
    branches: [{
        name: "maxBranch",
        condition: value => value >= 15,
        action: value => 15
    }]
});
mainBranch.execute(10)
    .then(console.log)//null
mainBranch.execute(11)
    .then(console.log)//12
mainBranch.execute(15)
    .then(console.log)//15

branch.setCondition(condition: (value: any) => result: any): branch

Changes branch condition. Returns this branch instance.

example

import { Branch } from "Horpyna";
const mainBranch = new Branch({ 
    name: "mainBranch",
    condition: value => value > 10, 
    action:  value => value + 1,
});
mainBranch.execute(11)
    .then(console.log)//12

mainBranch.setCondition(value => value > 11);

mainBranch.execute(11)
    .then(console.log)//null

branch.setAction(action: (value: any) => result: any): branch

Changes/set branch action. Returns this branch instance.

example

import { Branch } from "Horpyna";
const mainBranch = new Branch({ 
    name: "mainBranch",
    condition: value => value > 10, 
    action:  value => value + 1,
});

mainBranch.execute(11)
    .then(console.log)//12
    
mainBranch.setAction(value => value + 2);

mainBranch.execute(11)
    .then(console.log)//13

branch.addBranch(branchName: String, subBranch: branch): branch

Adds additional branch to existing one. Returns this branch instance.

example

import { Branch } from "Horpyna";
const mainBranch = new Branch({ 
    name: "mainBranch",
    condition: value => value > 10, 
    action:  value => value + 1,
    branches: [{
        name: "maxBranch",
        condition: value => value >= 15,
        action: value => 15
    }]
});

mainBranch.execute(10)
    .then(console.log)//null
    
mainBranch.addBranch(new Branch({
    name: "minBranch",
    condition: value => value < 15,
    action: value => value
}));

mainBranch.execute(10)
    .then(console.log)//11

branch,getBranch(branchName: String): branch

Returns first branch by name. If branch doesn't exist it will return null.

example

import { Branch } from "Horpyna";
const mainBranch = new Branch({ 
    name: "mainBranch",
    condition: () => true,
    action: () => true,
    branches: [{
        name: "maxBranch",
        condition: () => true,
        action: () => true
    }]
});
const maxBranch = mainBranch.getBranch("maxBranch");

branch,findBranch(branchName: String): branch

It will search in all branch tree beginning from current branch. If there is no such a branch it will return null.

example

import { Branch } from "Horpyna";
const mainBranch = new Branch({ 
    name: "mainBranch",
    condition: () => true,
    action: () => true,
    branches: [{
        name: "maxBranch",
        condition: () => true,
        action: () => true,
        branches: [{
            name: "someDeepBranch",
            condition: () => true,
            action: () => true
        }]
    }]
});
const someDeepBranch = mainBranch.findBranch("someDeepBranch");

branch,getAction(): function

Returns branch action function

branch,getCondition(): function

Returns branch condition function

branch,getName(): string

Returns branch name

branch,getBranches(): Array

Returns all child branches

branch.chain(branch): Branch

Add another branch to queue. All branches in queue will be invoked one by one after all child branches are done. Return current branch

example

import { Branch } from "Horpyna";
const mainBranch = new Branch({ 
    name: "branchA",
    condition: () => true,
    action: value => value + "A",
    branches: [{
        name: "branchB",
        condition: () => true,
        action: value => value + "B",
    }]
});
mainBranch.chain({
    name: "branchC",
    condition: () => true,
    action: value => value + "C",
})
mainBranch.chain({
    name: "branchD",
    condition: () => true,
    action: value => value + "D",
})

mainBranch.execute("")
.then(console.log)//"ABCD"

branch,setName(name: string): branch

Set new branch name

branch,clone(): branch

Shallow copy current branch and return new branch

branch.execute(input): promise

Returns promise resolvable to calculated output.

example

import { Branch } from "Horpyna";
const mainBranch = new Branch({ 
    name: "mainBranch",
    condition: value => value > 10, 
    action:  value => value + 1,
});

mainBranch.execute(11)
    .then(console.log)//12

LICENSE

MIT