New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

horpyna

Package Overview
Dependencies
Maintainers
1
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

horpyna

utility to manage async processes

  • 4.4.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-40%
Maintainers
1
Weekly downloads
 
Created
Source

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))

API

new Branch(options: Object): branch

Creates new branch instance.

options
{   name: String
    condition: Function,
    action: Function,
    branches: Array<Branch>
}
  • name - branch name
  • condition - function with condition to test
  • action - function to call if condition pass
  • branches - array of sub branches
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
    }]
});
execute(10)
    .then(console.log)//null
execute(11)
    .then(console.log)//12
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.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

Keywords

FAQs

Package last updated on 23 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc