布尔字符串- parser
将含有布尔匹配逻辑的字符串分析成函数,以对照一组字符串测试匹配.
创建用于标签测试的解决方案 。 举例来说,我们可能用 ['p0', 'fast'] 和另一个 ['fast', 'flaky']。然后我们可能只想要运行 fast 试验,或只有非试验 flaky,或仅 p0 测试 fast 没有 flaky。 。 。 .
使用量
通过在其中传递布尔语句创建匹配函数 正常状态 使用 & (ampersand)字符表示"AND", | (管)字符表示“OR”,以及 ^ (克拉特)字符作为前缀表示 NOT .
const BooleanStringParser = require('@creyes17/boolean-string-parser');
const potatoMatcher = BooleanStringParser.parseString('potato');
veggieMatcher(['potato']); // true
veggieMatcher(['lemon']); // false
const fluffyMammalAnimalMatcher = BooleanStringParser.parseString(
'animal&mammal&fluffy',
);
fluffyMammalAnimalMatcher(['animal', 'mammal', 'fluffy']); // true
fluffyMammalAnimalMatcher(['mammal', 'fluffy', 'mammoth']); // false
fluffyMammalAnimalMatcher(['animal', 'mammal']); // false
const notFlakyMatcher = BooleanStringParser.parseString('^flaky');
notFlakyMatcher([]); // true
notFlakyMatcher(['flaky']); // false
notFlakyMatcher(['p0']); // true
notFlakyMatcher(['p0', 'fast']); // true
notFlakyMatcher(['p0', 'fast', 'flaky']); // false