anchorme.js
anchorme.js copied to clipboard
Support native esm import
Now that Node supports native esm imports, it makes sense that this library supports it as well. However
import anchorme from 'anchorme';
produces an unexpected result as the anchorme variable will look like
const anchorme = {
default: {
list() {},
validate() {},
},
};
in Node because of the way esm is transpiled to commonjs. This means that you have to resort to hacks like
import _anchorme from 'anchorme';
const anchorme = _anchorme.default || _anchorme;
if you want your code to run both in the browser and in Node.
This PR circumvents this by leveraging Node's conditional exports and providing a wrapper.mjs file while maintaining full backwards compatibility for older Node versions.