@loaders.gl/loader-utils
Version:
Framework-independent loaders for 3D graphics formats
40 lines (39 loc) • 1.23 kB
JavaScript
// loaders.gl
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors
import { log } from "../log-utils/log.js";
/**
* Register application-imported modules
* These modules are typically to big to bundle, or may have issues on some bundlers/environments
*/
export function registerJSModules(modules) {
globalThis.loaders ||= {};
globalThis.loaders.modules ||= {};
Object.assign(globalThis.loaders.modules, modules);
}
/**
* Get a pre-registered application-imported module, warn if not present
*/
export function checkJSModule(name, caller) {
const module = globalThis.loaders?.modules?.[name];
if (!module) {
log.warn(`${caller}: ${name} library not installed`)();
}
}
/**
* Get a pre-registered application-imported module, throw if not present
*/
export function getJSModule(name, caller) {
const module = globalThis.loaders?.modules?.[name];
if (!module) {
throw new Error(`${caller}: ${name} library not installed`);
}
return module;
}
/**
* Get a pre-registered application-imported module, return null if not present
*/
export function getJSModuleOrNull(name) {
const module = globalThis.loaders?.modules?.[name];
return module || null;
}