Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
p-is-promise
Advanced tools
The p-is-promise npm package is a simple utility that allows you to check if a value is a Promise. This can be particularly useful when dealing with asynchronous operations in JavaScript, where you might need to differentiate between promises and other types of values.
Check if a value is a Promise
This feature allows you to easily determine whether a given value is a Promise. It's useful for conditional logic where the handling of a value depends on whether it's asynchronous (a Promise) or synchronous.
const pIsPromise = require('p-is-promise');
console.log(pIsPromise(Promise.resolve())); // true
console.log(pIsPromise('not a promise')); // false
Similar to p-is-promise, is-promise checks if a value is a Promise. The main difference lies in their implementation and possibly the versions of Node.js they support. Both packages serve a similar purpose, providing a straightforward way to determine if a value conforms to the Promise interface.
Check if something is a promise
Why not is-promise
? That module checks for a thenable, not an ES2015 promise. This one is stricter.
You most likely don't need this. Just pass your value to Promise.resolve()
and let it handle it.
Can be useful if you need to create a fast path for a synchronous operation.
$ npm install p-is-promise
import isPromise from 'p-is-promise';
import Bluebird from 'bluebird';
isPromise(Promise.resolve('🦄'));
//=> true
isPromise(Bluebird.resolve('🦄'));
//=> true
isPromise('🦄');
//=> false
FAQs
Check if something is a promise
The npm package p-is-promise receives a total of 6,576,144 weekly downloads. As such, p-is-promise popularity was classified as popular.
We found that p-is-promise 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.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.