UNPKG

liqe

Version:

Lightweight and performant Lucene-like parser, serializer and search engine.

13 lines (12 loc) 492 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createGetValueFunctionBody = void 0; const isSafePath_1 = require("./isSafePath"); const createGetValueFunctionBody = (path) => { if (!(0, isSafePath_1.isSafePath)(path)) { throw new Error('Unsafe path.'); } const body = 'return subject' + path; return body.replaceAll(/(\.(\d+))/g, '.[$2]').replaceAll('.', '?.'); }; exports.createGetValueFunctionBody = createGetValueFunctionBody;