Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
get(str: string, state = this.state) {
// TODO: better solution e.g. with proxies
let useStr = str.replace(/selected_or_first_available_variant/g, 'variants[0]');
// TODO: warn for errors
return liquid.evalValueSync(useStr, new Context(state, undefined, true)) || '';
}
assign(str: string, state = this.state) {
const re = /^\s*([^=\s]+)\s*=(.*)/;
let useStr = str.replace(/selected_or_first_available_variant/g, 'variants[0]');
const match = useStr.match(re)!;
const key = match[1].trim();
const value = match[2];
const result = liquid.evalValueSync(value, new Context(state, undefined, true));
console.debug('Liquid setting', key, 'to', result, 'via', str, state);
state[key] = result;
}
}