1 | "use strict";
|
---|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
3 | exports.compile = exports.parse = void 0;
|
---|
4 | var parse_1 = require("./parse");
|
---|
5 | Object.defineProperty(exports, "parse", { enumerable: true, get: function () { return parse_1.parse; } });
|
---|
6 | var compile_1 = require("./compile");
|
---|
7 | Object.defineProperty(exports, "compile", { enumerable: true, get: function () { return compile_1.compile; } });
|
---|
8 | /**
|
---|
9 | * Parses and compiles a formula to a highly optimized function.
|
---|
10 | * Combination of `parse` and `compile`.
|
---|
11 | *
|
---|
12 | * If the formula doesn't match any elements,
|
---|
13 | * it returns [`boolbase`](https://github.com/fb55/boolbase)'s `falseFunc`.
|
---|
14 | * Otherwise, a function accepting an _index_ is returned, which returns
|
---|
15 | * whether or not the passed _index_ matches the formula.
|
---|
16 | *
|
---|
17 | * Note: The nth-rule starts counting at `1`, the returned function at `0`.
|
---|
18 | *
|
---|
19 | * @param formula The formula to compile.
|
---|
20 | * @example
|
---|
21 | * const check = nthCheck("2n+3");
|
---|
22 | *
|
---|
23 | * check(0); // `false`
|
---|
24 | * check(1); // `false`
|
---|
25 | * check(2); // `true`
|
---|
26 | * check(3); // `false`
|
---|
27 | * check(4); // `true`
|
---|
28 | * check(5); // `false`
|
---|
29 | * check(6); // `true`
|
---|
30 | */
|
---|
31 | function nthCheck(formula) {
|
---|
32 | return (0, compile_1.compile)((0, parse_1.parse)(formula));
|
---|
33 | }
|
---|
34 | exports.default = nthCheck;
|
---|