UNPKG

arquero

Version:

Query processing and transformation of array-backed data tables.

31 lines (28 loc) 749 B
import { isFunction } from '../util/is-function.js'; /** * Annotate an expression in an object wrapper. * @param {string|Function|object} expr An expression to annotate. * @param {object} properties The properties to annotate with. * @return {object} A new wrapped expression object. */ export function wrap(expr, properties) { return expr && expr.expr ? new Wrapper({ ...expr, ...properties }) : new Wrapper(properties, expr); } class Wrapper { constructor(properties, expr) { this.expr = expr; Object.assign(this, properties); } toString() { return String(this.expr); } toObject() { return { ...this, expr: this.toString(), ...(isFunction(this.expr) ? { func: true } : {}) }; } }