UNPKG

@mikezimm/npmfunctions

Version:
54 lines 2.62 kB
"use strict"; /** * complexStringFilter - Loosely built off of BuildTileCollection - isVisibleItem function in PivotTiles * @param testThis - looking for this text * @param againstThis - in this string * @param testSplitter - parser like ';', or ',' or ';or,', if it finds ANY match, it returns true * @param notEqualString - test for not equal like '<>' or '!=', if any parsed tests include notEqual, then it returns false * @param anyCase - true converts all to lowerCase() for comparison first. Else it is case sensitive */ Object.defineProperty(exports, "__esModule", { value: true }); exports.complexStringSearch = void 0; var stringServices_1 = require("./stringServices"); function complexStringSearch(testThis, againstThis, testSplitter, notEqualString, anyCase) { if (!testThis) { return true; } else { var againstThisCase_1 = anyCase === true ? againstThis.toLowerCase() : againstThis; var testThisCase = anyCase === true ? testThis.toLowerCase() : testThis; var testThese = (0, stringServices_1.getStringArrayFromString)(testThisCase, testSplitter, true, null, false); var foundEquals_1 = false; var foundNotEquals_1 = false; var testedNotEquals_1 = false; var testedEquals_1 = false; testThese.map(function (test) { var testString = "".concat(test); //Set up for testing Not Equals, if it's found, entire test returns false if (notEqualString && foundNotEquals_1 === false && testString.indexOf(notEqualString) === 0) { testedNotEquals_1 = true; if (againstThisCase_1.indexOf(testString.replace(notEqualString, '')) > -1) { foundNotEquals_1 = true; } //Or test for normal equals } else if (foundEquals_1 === false && againstThisCase_1.indexOf(testString) > -1) { testedEquals_1 = true; foundEquals_1 = true; } }); var result = null; if (foundNotEquals_1 === false && testedNotEquals_1 === true && testedEquals_1 === false) { result = true; } //If Only tested for negative but did not find it... so assuming it's positive else if (foundNotEquals_1 === true) { result = false; } //If any foundNotEquals, then return false else { result = foundEquals_1; } return result; } } exports.complexStringSearch = complexStringSearch; //# sourceMappingURL=filtering.js.map