
Security News
CVE Volume Surges Past 48,000 in 2025 as WordPress Plugin Ecosystem Drives Growth
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.
@humanwhocodes/pledge
Advanced tools
If you find this useful, please consider supporting my work with a donation.
An implementation of JavaScript promises that matches the ECMA-262 specification as closely as possible. Some differences:
Realm concerns as this isn't important to understanding promises.Note: This package is intended only for educational purposes and should not be used in production. There's no reason to use this package because the JavaScript Promise class already implements all of this functionality.
This package was created as part of the, "Creating a JavaScript promise from scratch," blog post series. If you have questions about this package, please be sure to check out the blog posts:
Additionally, thanks to my GitHub sponsors the following posts are now or will soon be available:
If you found this series and code helpful, please sponsor me on GitHub.
npm install @humanwhocodes/pledge --save
# or
yarn add @humanwhocodes/pledge
Import into your Node.js project:
// CommonJS
const { Pledge } = require("@humanwhocodes/pledge");
// ESM
import { Pledge } from "@humanwhocodes/pledge";
Import into your Deno project:
import { Pledge } from "https://unpkg.com/@humanwhocodes/pledge/dist/pledge.js";
It's recommended to import the minified version to save bandwidth:
import { Pledge } from "https://unpkg.com/@humanwhocodes/pledge/dist/pledge.min.js";
However, you can also import the unminified version for debugging purposes:
import { Pledge } from "https://unpkg.com/@humanwhocodes/pledge/dist/pledge.js";
After importing, create a new instance of Pledge and use it like a Promise:
// basics
const pledge = new Pledge((resolve, reject) => {
resolve(42);
// or
reject(42);
});
pledge.then(value => {
console.log(value);
}).catch(reason => {
console.error(reason);
}).finally(() => {
console.log("done");
});
// create resolved pledges
const fulfilled = Pledge.resolve(42);
const rejected = Pledge.reject(new Error("Uh oh!"));
To watch for unhandled rejections:
// this function is called when any pledge is rejected without a handler
// similar to window.onunhandledrejection
Pledge.onUnhandledRejection = event => {
const { pledge, reason } = event;
// cancel warning about this unhandled rejection
event.preventDefault();
};
// this function is called when a previously unhandled rejection becomes handled
// similar to window.onrejectionhandled;
Pledge.onRejectionHandled = event => {
const { pledge, reason } = event;
};
Promises have a lot of difficult concepts to understand, and sometimes the easiest way to understand difficult concepts is to put them into a familiar paradigm. In this case, creating an implementation of promises in JavaScript gave me a better understanding of how they work, and hopefully, they will help others understand them better, too.
FAQs
A custom-built promise implementation.
We found that @humanwhocodes/pledge 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
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.