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

aim-promises

v1.0.0

Published

A complete Promise/A+ compatible implementation built from scratch

Readme

AimPromises 🎯

npm version License: MIT

A complete Promise/A+ compatible implementation built from scratch for educational and production use. This implementation demonstrates every aspect of how Promises work internally, including proper asynchronous execution, thenable resolution, and all standard Promise methods.

✨ Features

  • 🎯 Full Promise/A+ compliance
  • Proper asynchronous execution with microtask scheduling
  • 🔗 Complete thenable support - works with any Promise-like object
  • 🛡️ Robust error handling and state management
  • 📦 Zero dependencies
  • 🔷 TypeScript support included
  • 🌐 Universal compatibility - works in Node.js and browsers
  • 📚 Educational - clean, readable code with detailed comments

📦 Installation

npm install aim-promises

🚀 Quick Start

CommonJS

const AimPromise = require("aim-promises");

const promise = new AimPromise((resolve, reject) => {
  setTimeout(() => resolve("Hello, World!"), 1000);
});

promise.then((value) => {
  console.log(value); // "Hello, World!" after 1 second
});

ES Modules

import AimPromise from "aim-promises";

const promise = new AimPromise((resolve, reject) => {
  setTimeout(() => resolve("Hello, World!"), 1000);
});

promise.then((value) => {
  console.log(value); // "Hello, World!" after 1 second
});

TypeScript

import AimPromise from "aim-promises";

const promise = new AimPromise<string>((resolve, reject) => {
  setTimeout(() => resolve("Hello, TypeScript!"), 1000);
});

promise.then((value: string) => {
  console.log(value); // Fully typed!
});

📖 API Reference

Constructor

new AimPromise(executor);

Creates a new AimPromise instance.

  • executor (Function): A function that is passed with the arguments resolve and reject

Instance Methods

.then(onFulfilled?, onRejected?)

Attaches callbacks for the resolution and/or rejection of the Promise.

promise.then((value) => value * 2).then((value) => console.log(value));

.catch(onRejected?)

Attaches a callback for only the rejection of the Promise.

promise
  .then((value) => JSON.parse(value))
  .catch((error) => console.error("Parse error:", error));

.finally(onFinally?)

Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected).

promise
  .then((value) => processData(value))
  .catch((error) => handleError(error))
  .finally(() => cleanup());

Static Methods

AimPromise.resolve(value?)

Creates a resolved promise with the given value.

AimPromise.resolve(42).then((value) => console.log(value)); // 42

AimPromise.reject(reason?)

Creates a rejected promise with the given reason.

AimPromise.reject(new Error("Something went wrong")).catch((error) =>
  console.error(error.message)
);

AimPromise.all(iterable)

Waits for all promises to resolve, or rejects if any promise rejects.

AimPromise.all([
  AimPromise.resolve(1),
  AimPromise.resolve(2),
  AimPromise.resolve(3),
]).then((values) => {
  console.log(values); // [1, 2, 3]
});

AimPromise.allSettled(iterable)

Waits for all promises to settle (resolve or reject).

AimPromise.allSettled([
  AimPromise.resolve(1),
  AimPromise.reject("error"),
  AimPromise.resolve(3),
]).then((results) => {
  console.log(results);
  // [
  //   { status: 'fulfilled', value: 1 },
  //   { status: 'rejected', reason: 'error' },
  //   { status: 'fulfilled', value: 3 }
  // ]
});

AimPromise.race(iterable)

Returns the first promise to settle (resolve or reject).

AimPromise.race([
  new AimPromise((resolve) => setTimeout(() => resolve("slow"), 1000)),
  new AimPromise((resolve) => setTimeout(() => resolve("fast"), 100)),
]).then((value) => {
  console.log(value); // 'fast'
});

🔄 Thenable Support

AimPromise fully supports thenables - any object with a .then() method:

const thenable = {
  then(onFulfilled, onRejected) {
    onFulfilled("I am a thenable!");
  },
};

AimPromise.resolve(thenable).then((value) => console.log(value)); // 'I am a thenable!'

🎓 Educational Value

This implementation demonstrates:

  • State Management: How promises transition between pending, fulfilled, and rejected states
  • Asynchronous Execution: Proper use of microtasks for consistent behavior
  • Promise Resolution Procedure: The complex algorithm for handling thenables
  • Chaining: How .then() creates new promises for seamless chaining
  • Error Handling: Propagation and catching of errors through promise chains

🧪 Examples

Basic Chaining

new AimPromise((resolve) => resolve(10))
  .then((x) => x * 2)
  .then((x) => x + 5)
  .then((result) => console.log(result)); // 25

Error Recovery

new AimPromise((resolve, reject) => reject("failed"))
  .catch((error) => "recovered")
  .then((value) => console.log(value)); // 'recovered'

Async/Await (if your environment supports it)

async function example() {
  try {
    const result = await new AimPromise((resolve) =>
      setTimeout(() => resolve("async result"), 100)
    );
    console.log(result); // 'async result'
  } catch (error) {
    console.error(error);
  }
}

📋 Promise/A+ Compliance

This implementation passes all Promise/A+ specification tests:

  • ✅ Promise States and Transitions
  • ✅ Promise Resolution Procedure
  • ✅ Asynchronous Execution
  • ✅ Thenable Assimilation
  • ✅ Error Handling

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

MIT License. See LICENSE file for details.

🙏 Acknowledgments

Built to demonstrate the internals of JavaScript Promises and provide a fully-functional alternative for educational and production use.


Why AimPromise? Because understanding how Promises work internally helps you aim for better asynchronous JavaScript! 🎯