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 🙏

© 2026 – Pkg Stats / Ryan Hefner

promise-tree

v1.1.4

Published

Enables conditional promise usage in JavaScript

Downloads

1

Readme

Promise Tree

Promise-tree enables writing of conditional javascript promise without nesting.

Related Package - Promise Stem

This is another package I write which compliments the usage of promise-tree. Instead of branching from a single point, promise-stem takes results from separate promise chains and put into a single chain. Links for promise-stem below

GitHub

https://github.com/shizongli94/promise-stem

NPM

https://www.npmjs.com/package/promise-stem

Installing

Simply install with npm

npm install --save promise-tree

Usage

Require

const condition = require("promise-tree").condition;
const Branch = require("promise-tree").Branch;

Inititialization

const branch_left = new Branch();
const branch_right = new Branch();
const promise = new Promise((resolve, reject) => { /* your code goes here */});

Check conditions and start branching

promise
    .then((value) => {
        console.log("stem", 1);
        value++;
        return value;
    })
    .then((value) => {
        console.log("stem", 2);
        value++;
        throw value;
    })
    .catch((reason) => {
        console.log("stem", 3);
        condition.unless(condition_to_be_checked).with(reason).from(if_branching_from_then).along(branch_left);
        // e.g. condition.unless(1===2).with(reason).from(false).along(branch_left);
        reason++;
        return reason;
    })
    .then((value) => {
        console.log("a", 4);
        value++;
        
        condition.if(condition_to_be_cheched).with(value).from(if_branching_from_then).along(branch_right);
        // e.g. condition.if(1===1).with(value).from(true).along(branch_left);
        
        return value;
    })
    .then((value) => {
        console.log("a", 5);
        return value;
    });

branch_left
    .then((value) => {
        console.log("l", 1);
        value++;
        return value;
    })
    .then((value) => {
        console.log("l", 2);
        value++;
        return value;
    });

branch_right
    .then((value) => {
        console.log("r", 1);
        value++;
        return value;
    })
    .then(value => {
        console.log("r", 2);
        value++;
        return value;
    })
    .then(value => {
        console.log("r", 3);
        value++;
        return value;
    })
    .then(value => {
        console.log("r", 4);
        value++;
        return value;
    })
    .then(value => {
        console.log("r", 5);
        value++;
        return value;
    });

API

Branch - object

Include

const Branch = require(promise-tree").Branch;

Constructor

const branch = new Branch();

Handlers

branch
  .then((value) => { /* your code goes here */})
  .catch((reason) => { /* your code goes here */});

Condition - JSON object

Include

const condition = require("promise-tree").condition;

Branch indicator

// Indicating what branch you wish to go based on the condition.
condition.along(branch_left) // must be passed with a Branch object. Otherwise TypeError is thrown

Boolean checkers

// bool is a boolean variable or expression. If true, the branch associated with this condition will be executed.
condition.if(bool); 
// bool is a boolean variable or expression. If true, the branch associated with this condition will NOT be executed.
condition.unless(bool);

Start place register

condition.from(true); // If true, it is indicating the branch starts inside Promise.then() or Branch.then().
condition.from(false); // If false, it is indicating the branch starts inside Promise.catch() or Branch.catch().

Value/Reason Passer

// Pass the value which will be used to initialize 
// the indicated branch as if the chain of branch is concatenated to that of stem promise
condition.with(value);  
condition.with(1234); // you can pass any value you want to initiate the branch, not only the value or reason from previous links.

Condition methods may be used together or seperately

// Used together, in any order
condition.if(!checking_some_condition()).from(true).with(250).along(weired_branch);
// Used seperately, in any order
let condition = condition.if(checking_some_condition());
condition = condition.along(not_so_weired_branch);
condition = condition.from(true);
condition = condition.with(250);

Attention!

The indicated branch will not be executed if not all four condition methods have been called even if the condtiiton checked is true for 'if' or 'false' for 'unless'. That is,

// In any of the cases below, the branch lonely_forever will not be called!!!
condition.if(true).with("NO!!!").along(lonely_forever);
condition.unless(false).with("I am drinking milkshake when I am typing this readme file").along(lonely_forever);
condition.along(lonely_forever).if(!("Milkshake" != " tastes good"));
condition.with("I don't even know where the cute lonely_forever is").unless(false);

Authors

License

This project is licensed under the GNU General Public License v3.0