@jbrowse/core
Version:
JBrowse 2 core libraries used by plugins
18 lines (17 loc) • 607 B
JavaScript
import createJexlInstance from "./jexl.js";
const compilationCache = {};
export function stringToJexlExpression(str, jexl) {
const cacheKey = `nosig|${str}`;
if (!compilationCache[cacheKey]) {
const match = str.startsWith('jexl:');
if (!match) {
throw new Error('string does not appear to be in jexl format');
}
const code = str.split('jexl:')[1];
const compiled = jexl
? jexl.compile(code)
: createJexlInstance().compile(code);
compilationCache[cacheKey] = compiled;
}
return compilationCache[cacheKey];
}