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

lel

v1.0.1

Published

A package that makes Promise great again!

Downloads

6

Readme

Potentially dangerous behavior from Promises

I found about about this after I found out about the problem the hard way, but go read the spec, and especially the part about thenables and The Promise Resolution Procedure

“thenable” is an object or function that defines a then method.

(you can test this code on jsbin)

let proxy = new Proxy({}, {
    get (target, method) {
        return (...args) => {
            console.log(`trying to access property ${method}`)
        }
    }
})

proxy.Hi() // Just to show it works as intended
try {
    console.log("Before promise resolve")
    Promise.resolve(proxy)
        .then(v => {
            console.log("In resolved callback", v)
        })
        .catch(e => {
            console.error("In rejected callback", e)
        })
} catch (e) {
    console.error("In catch block", e)
}

The problem

I initially found out about this while experimenting with Proxies and thought the issue was with their implementation, but as you can see in the following code (and this jsbin) it is really in the Promise implementation [edit : spec].

let obj = {
  Hi : () => {
    console.log("Hi")
  },
  then : () => {
    console.log("Trolling hard")
  }
}

obj.Hi() // Just to show it works as intended
try {
    console.log("Before promise resolve")
    Promise.resolve(obj)
        .then(v => {
            console.log("In resolved callback", v)
        })
        .catch(e => {
            console.error("In rejected callback", e)
        })
} catch (e) {
    console.error("In catch block", e)
}

The end of the world

So basically if at any point someone introduces the code from this package

Object.prototype.then = () => {} // Break all the REST apis \o/

in a popular one, all hell will break lose.

The same happens, and this could be very painful, if someone manages to hack a CDN and do this as well.

Debugging

As you can see, I have been overprotective with the bits of code above, on purpose. What it shows is that you have no way to know where the problem comes from.

The reason for that is the Promise will never resolve nor reject.

A thenable's then function is given the resolve|reject callbacks and should act on it like so :

let obj = {
	then : (resolve, reject) => {
		resolve(42)
	}
}

Promise.resolve(obj)
	.then(value => {
		console.log(value) // 42
	})

Otherwise, you now know what happens.

There's no fix for this, and if someone decides to play bad with this stuff, you're in for a hell of a debugging session.

Yay js, I guess...

Warnings

Please be careful when using this package (because obviously, people will do it. Probably for reasons).

But you would know that, if you reached this point. Right?

¯\_(ツ)_/¯

p.s. : Obviously I'm publishing this on npm to troll a little. But this is a serious issue, imo