
Product
Socket for Jira Is Now Available
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.
promise-conditional
Advanced tools
Use if-then-else in promise chains
getArticles()
.then(condition()
.if(data => data.length > 10)
.then(doIfTrue)
.then(alsoDoIfTrue)
.elseIf(data => data.length > 5)
.then(doIfTrue)
.else()
.then(doIfFalse)
.end())
npm install --save promise-conditional
var condition = require('promise-conditional') // Legacy
import condition from 'promise-conditional' // ES2015+
It relies on any-promise to find a Promise library. You can use bluebird, q, when, or the native Promise implementation of Node.js or the browser.
condition()
Starts a condition chain.
condition().if(condition)
Starts an if step. condition is a function that gets the input value. If it returns true, the subsequent then/catch/finally calls will be invoked.
condition() ... elseIf(condition)
Starts an elseIf step. condition is a function that gets the input value. If it returns true, the subsequent then/catch/finally calls will be invoked, but only if the other if steps have not been invoked.
condition() ... else()
Starts an else step. The subsequent then/catch/finally calls will be invoked, but only if the other if/elseIf steps have not been invoked.
condition() ... end()
Returns a function that you can pass onto .then(...) that runs the entire chain.
condition().if().then(next)
Adds a then/catch/finally step if the last if condition is true.
promise-conditional © 2016+, Rico Sta. Cruz. Released under the MIT License.
Authored and maintained by Rico Sta. Cruz with help from contributors (list).
ricostacruz.com · GitHub @rstacruz · Twitter @rstacruz
FAQs
Use if-then-else in promise chains
We found that promise-conditional demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.