Using dynamics imports like that:
const i = import('./path/to/module.js');
yields a Promise for that module. Assuming that ./path/to/module.js looks like that:
export function foo () {}
export function bar () {}
export default function () {}
the resulting object will have such a shape:
{
foo: …
bar: …
default: …
}
Right now I need to figure out if a given Object is such a module, or any other one. So: Is there any test to determine if a given object is such a es6 module, obtained by a dynamic import?
You should check Symbol.toStringTag property of your alleged module object:
const isModule = i[Symbol.toStringTag] == 'Module'
See docs for Symbol.toStringTag
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With