UNPKG

tequery

Version:

text transform query

39 lines 1.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.tequery = exports.tequeryLines = void 0; const pretrans_1 = require("./pretrans"); const runEval_1 = require("./runEval"); function tequeryLines(text, query, comps, option) { var _a, _b; const results = text .split('\n') .map((line, i) => (0, runEval_1.runEval)(line, query, option, i)); /* istanbul ignore next */ if (!results[0]) throw new Error('never reach'); // always .split('\n').length > 0 return { result: results.map((r) => r.result).join(option.glue), resultRaw: results.map((r) => r.resultRaw), status: results.some((r) => r.status === 'ok') ? 'ok' : 'ng', evalQuery: results[0].evalQuery, returnType: results[0].returnType, errorText: (_b = (_a = results.find((r) => r.status === 'ng')) === null || _a === void 0 ? void 0 : _a.errorText) !== null && _b !== void 0 ? _b : '', comps, }; } exports.tequeryLines = tequeryLines; const semanticPolifil = (option) => { if (typeof option === 'string') return { glue: option }; return option; }; function tequery(text, query, option0 = { glue: '\n' }) { const option = semanticPolifil(option0); const { query: compedQuery, comps } = (0, pretrans_1.preTrans)(query); if (comps.lineRun) return tequeryLines(text, compedQuery, comps, option); const res = (0, runEval_1.runEval)(text, compedQuery, option); return { ...res, comps }; } exports.tequery = tequery; //# sourceMappingURL=index.js.map