Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | 4x 4x 4x 4x 9x 9x 9x 9x | import type {OpStarts} from '../../op'; import {$$find} from '@jsonjoy.com/json-pointer/lib/codegen/find'; import {type JavaScriptLinked, compileClosure, type JavaScript} from '@jsonjoy.com/util/lib/codegen'; import {predicateOpWrapper} from '../util'; import type {ApplyFn} from '../types'; export const $$starts = (op: OpStarts): JavaScriptLinked<ApplyFn> => { 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] as unknown[], js: js as JavaScript<(...deps: unknown[]) => ApplyFn>, }; }; export const $starts = (op: OpStarts): ApplyFn => compileClosure($$starts(op)); |