browserify / node-util

node.js util module as a module
MIT License
247 stars 88 forks source link

Add `types` #52

Open SimenB opened 4 years ago

SimenB commented 4 years ago

https://nodejs.org/api/util.html#util_util_types

They work cross-realm (at least for Error coming from a new vm.Context). Not sure if it's worth it for you to work cross-realm, but just doing instanceof should work OK as a shim, think?

ljharb commented 4 years ago

It should be 100% doable in most cases, i have tons of npm packages to handle most of them in a cross-realm way. https://npmjs.com/~inspect-js

SimenB commented 4 years ago

Oh, nice! I'm specifically after a an error check as we gave a bunch of ugly duck typing in Jest to figure out if we have an error instance or not. But I'm hesitant to add utils usage in case it makes it harder to use parts of Jets in the browsers.

Do you have a package for Error (i.e. util.types.isNativeError)? Quick searching in the link you posted didn't find it, sorry if I missed something obvious. If so I'd love to use that and not worry about if it is shimmed by this package if people attempt to use e.g. expect or something in the browser

ljharb commented 4 years ago

No, unfortunately there is no JavaScript way to robustly identify a native Error - instanceof Error is the best you can do.