UNPKG

json-joy

Version:

Collection of libraries for building collaborative editing apps.

22 lines (21 loc) 759 B
import { $$find } from '@jsonjoy.com/json-pointer/lib/codegen/find'; import { compileClosure } from '@jsonjoy.com/util/lib/codegen'; import { predicateOpWrapper } from '../util'; export const $$starts = (op) => { const compareValue = op.ignore_case ? op.value.toLowerCase() : op.value; const js = /* js */ ` (function(wrapper){ var find = ${$$find(op.path)}; return wrapper(function(doc){ var val = find(doc); if (typeof val !== 'string') return false; var outer = ${op.ignore_case ? /* js */ 'val.toLowerCase()' : 'val'}; return outer.indexOf(${JSON.stringify(compareValue)}) === 0; }); })`; return { deps: [predicateOpWrapper], js: js, }; }; export const $starts = (op) => compileClosure($$starts(op));