@himorishige/noren-core
Version:
Core PII detection, masking, and tokenization library built on Web Standards
28 lines (27 loc) • 859 B
JavaScript
// Cache for loaded plugins to avoid duplicate imports
const pluginCache = new Map();
export async function loadPlugin(name, plugin) {
if (pluginCache.has(name)) {
const cached = pluginCache.get(name);
if (cached)
return cached;
}
const loadPromise = (async () => {
const [detectors, maskers, contextHints] = await Promise.all([
plugin.detectors?.() ?? Promise.resolve([]),
plugin.maskers?.() ?? Promise.resolve({}),
plugin.contextHints?.() ?? Promise.resolve([]),
]);
return {
detectors,
maskers,
contextHints,
};
})();
pluginCache.set(name, loadPromise);
return loadPromise;
}
// Clear plugin cache (useful for testing or hot-reloading)
export function clearPluginCache() {
pluginCache.clear();
}