let wasmModule = null;
export async function init(target = 'web') {
if (wasmModule) return;
if (target === 'nodejs') {
const mod = await import(`./pkg/nodejs/schemaorg_rs.js`);
wasmModule = mod;
} else {
const mod = await import(`./pkg/web/schemaorg_rs.js`);
await mod.default();
wasmModule = mod;
}
}
async function ensureInit() {
if (wasmModule) return;
const isNode =
typeof globalThis.process !== 'undefined' &&
typeof globalThis.process.versions?.node !== 'undefined';
await init(isNode ? 'nodejs' : 'web');
}
export async function extract(html) {
await ensureInit();
const json = wasmModule.extract(html);
return JSON.parse(json);
}
export async function validateHtml(html, profile = 'google') {
await ensureInit();
const json = wasmModule.validate_html(html, profile);
return JSON.parse(json);
}
export async function schemaVersion() {
await ensureInit();
return wasmModule.schema_version();
}