UNPKG

concepts-parser

Version:
40 lines (39 loc) 1.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const data_1 = require("../data"); function filter(concepts, context) { const sources = data_1.getValidSuffixes(context.lang); let nextIsInvalid = false; return concepts.filter(function (concept, index) { if (nextIsInvalid) { nextIsInvalid = false; return false; } let text = context.text.substr(concept.index + concept.value.length); for (const source of sources) { let result = source.reg.exec(text); if (result) { let match = result[0]; let value = text.substr(0, match.length); if (source.prefix) { if (!source.prefix.test(concept.value)) { return true; } } concept.reset(concept.value + value, concept.index, concept.lang); if (source.concat === true) { if (index + 1 < concepts.length) { const nextConcept = concepts[index + 1]; if (nextConcept.index === concept.endIndex + 1) { concept.reset(concept.value + " " + nextConcept.value, concept.index, concept.lang); nextIsInvalid = true; } } } return concept.isValid(); } } return true; }); } exports.filter = filter;