import { interop } from "https://deno.land/x/ayonli_jsext@v0.9.72/module.ts";
Performs interop on the given module. This functions is used to fix CommonJS module imports in Node.js ES module files.
By default, this function will check the module object for characteristics of CommonJS modules and perform interoperability smartly.
But sometimes, this behavior is not guaranteed, for example, when the module
is an ES module and it does have a default export as an object, or the
module.exports
is the only export in the CommonJS file. In this case,
this function will be confused and may return an undesired object.
To fix this, you can set the strict
parameter to true
, so this function
will only return the exports
object when the module also has an __esModule
property, which is a common pattern generated by TypeScript for CommonJS
files.
Or you can set the strict
parameter to false
, so this function will
always return the default
object if it exists in module
, which is the
target that Node.js uses to alias the module.exports
object for CommonJS
modules.
Examples
Example 1
Example 1
import { interop } from "@ayonli/jsext/module";
const { decode } = await interop(() => import("iconv-lite"), false);
Parameters
Examples
Example 1
Example 1
import { interop } from "@ayonli/jsext/module";
const { decode } = await interop(import("iconv-lite"), false);
Parameters
Examples
Example 1
Example 1
import { interop } from "@ayonli/jsext/module";
const { decode } = interop(await import("iconv-lite"), false);