load 返回的可接受的最终格式
format 的最终值必须是以下之一:
format | 描述 | load 返回的 source 的可接受类型 |
|---|---|---|
'addon' | 加载 Node.js 插件 | <null> |
'builtin' | 加载 Node.js 内置模块 | <null> |
'commonjs-typescript' | 加载使用 TypeScript 语法的 Node.js CommonJS 模块 | <string> | <ArrayBuffer> | <TypedArray> | <null> | <undefined> |
'commonjs' | 加载 Node.js CommonJS 模块 | <string> | <ArrayBuffer> | <TypedArray> | <null> | <undefined> |
'json' | 加载 JSON 文件 | <string> | <ArrayBuffer> | <TypedArray> |
'module-typescript' | 加载使用 TypeScript 语法的 ES 模块 | <string> | <ArrayBuffer> | <TypedArray> |
'module' | 加载 ES 模块 | <string> | <ArrayBuffer> | <TypedArray> |
'wasm' | 加载 WebAssembly 模块 | <ArrayBuffer> | <TypedArray> |
对于格式 'builtin',source 的值会被忽略,因为目前
无法替换 Node.js 内置(核心)模块的值。
这些类型都对应于 ECMAScript 中定义的类。
- 具体的 <ArrayBuffer> 对象是 <SharedArrayBuffer>。
- 具体的 <TypedArray> 对象是 <Uint8Array>。
如果文本类格式(即 'json'、'module')的 source 值
不是字符串,则会使用 util.TextDecoder 将其转换为字符串。