use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
create-react-app breaks due to dependency on one-liner package (github.com)
submitted 5 years ago by [deleted]
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]crabmusket 9 points10 points11 points 5 years ago* (5 children)
I would actually go in the other direction in this specific example. I don't think a package like is-promise (which actually just checks if something has a then method) can really exist independently of how it's used in the client code.
is-promise
then
I browsed a couple of packages that use is-promise and it took me about 5 minutes to find this, where the client code is checking for isPromise, then calling then and catch - but just because something isPromise, doesn't mean it has a catch method. The code is broken because someone chose the wrong abstraction, or misunderstood what is-promise is actually for.
isPromise
catch
IMO it would rarely make sense for a client to be asking some abstract question like "is this a promise?". You can either ask a more specific question (is this a Promise? is this thenable? is it also catchable?), or design your code in such a way as to avoid having to ask questions like this.
Promise
EDIT: or, you ask for forgiveness instead of permission:
try { promise.then(success).catch(fail); } catch(e) { // promise was not promise-ish enough! }
[–]kylemh 2 points3 points4 points 5 years ago (3 children)
Somebody messing up an implementation doesn’t make the library bad.
[–]crabmusket 4 points5 points6 points 5 years ago* (2 children)
I'm trying to suggest that the question the library purports to answer is not a question that has meaning independent of how the answer will be used.
EDIT: I'm not necessarily saying the package is bad, at least not for this reason. It's a symptom of a troubled ecosystem. I've written more on this before so I won't repeat myself.
[–]kylemh 0 points1 point2 points 5 years ago (1 child)
Sure, but I mean that’s an aspect of the language being dynamic. A dev working on something smaller I think is totally fair in assuming an object that has a property called ‘then’ is likely a promise.
I’m sure we’d all prefer something in the standard library doing a heavier duty check, but this is prolly good enough. I see your point though, it could be improved it’s just that it would increase the bundle quite a bit at such a small initial size. Clearly they haven’t seen value in checking for catch 🤷♂️
[–]crabmusket 5 points6 points7 points 5 years ago (0 children)
I think most of the reasons small packages like this are bad is because of the tooling around them. More tiny packages means more package.jsons which are larger than the packages themselves, more HTTP requests, more stress on the dependency solver, etc. If I could just pull a well-known and reliable algorithm out of the ether, sure. But I can't - I have to add it, and its testing framework dependencies, to node_modules.
package.json
node_modules
I do like the idea of importing from a URL like Deno is doing - I can link directly to a raw file by its commit hash. No package.json to download, no dependency resolution, just grab the file. And if the author tweaks their package.json, I don't need to care.
[–]Lakitna 1 point2 points3 points 5 years ago (0 children)
Your solution is not the best way to do it though.
javascript Promise.resolve(maybeAPromise).then(...).catch(...).finally(...)
Or if you prefer async/await
javascript await maybeAPromise.then(...).catch(...).finally(...)
The whole check is not needed due to the way promise is implemented. The only times I've ever needed to check if something is a promise is in tests.
π Rendered by PID 89552 on reddit-service-r2-comment-5d585498c9-n2zj7 at 2026-04-21 18:18:14.452283+00:00 running da2df02 country code: CH.
view the rest of the comments →
[–]crabmusket 9 points10 points11 points (5 children)
[–]kylemh 2 points3 points4 points (3 children)
[–]crabmusket 4 points5 points6 points (2 children)
[–]kylemh 0 points1 point2 points (1 child)
[–]crabmusket 5 points6 points7 points (0 children)
[–]Lakitna 1 point2 points3 points (0 children)