taglib-wasm
Version:
TagLib-Wasm is the universal tagging library for TypeScript/JavaScript platforms: Browsers, Node.js, Deno, Bun, Cloudflare Workers, and Electron apps
38 lines (37 loc) • 1.13 kB
JavaScript
import { TagLibInitializationError } from "../errors/classes.js";
async function loadTagLibModule(options) {
let createTagLibModule;
try {
const module2 = await import("../../taglib-wrapper.js");
createTagLibModule = module2.default;
} catch {
try {
const module2 = await import("../../taglib-wrapper.js");
createTagLibModule = module2.default;
} catch {
throw new TagLibInitializationError(
"Could not load taglib-wrapper.js. Ensure it is co-located with the browser bundle."
);
}
}
const moduleConfig = {};
if (options?.wasmBinary) {
moduleConfig.wasmBinary = options.wasmBinary;
}
if (options?.wasmUrl) {
moduleConfig.locateFile = (path) => {
if (path.endsWith(".wasm")) {
return options.wasmUrl;
}
return path;
};
} else if (!options?.wasmBinary) {
const wasmUrl = new URL("./taglib-web.wasm", import.meta.url);
moduleConfig.locateFile = (path) => path.endsWith(".wasm") ? wasmUrl.href : path;
}
const module = await createTagLibModule(moduleConfig);
return module;
}
export {
loadTagLibModule
};