1 | import { parse } from "./parse.js";
|
2 | import { compile, generate } from "./compile.js";
|
3 | export { parse, compile, generate };
|
4 | /**
|
5 | * Parses and compiles a formula to a highly optimized function.
|
6 | * Combination of {@link parse} and {@link compile}.
|
7 | *
|
8 | * If the formula doesn't match any elements,
|
9 | * it returns [`boolbase`](https://github.com/fb55/boolbase)'s `falseFunc`.
|
10 | * Otherwise, a function accepting an _index_ is returned, which returns
|
11 | * whether or not the passed _index_ matches the formula.
|
12 | *
|
13 | * Note: The nth-rule starts counting at `1`, the returned function at `0`.
|
14 | *
|
15 | * @param formula The formula to compile.
|
16 | * @example
|
17 | * const check = nthCheck("2n+3");
|
18 | *
|
19 | * check(0); // `false`
|
20 | * check(1); // `false`
|
21 | * check(2); // `true`
|
22 | * check(3); // `false`
|
23 | * check(4); // `true`
|
24 | * check(5); // `false`
|
25 | * check(6); // `true`
|
26 | */
|
27 | export default function nthCheck(formula: string): (index: number) => boolean;
|
28 | /**
|
29 | * Parses and compiles a formula to a generator that produces a sequence of indices.
|
30 | * Combination of {@link parse} and {@link generate}.
|
31 | *
|
32 | * @param formula The formula to compile.
|
33 | * @returns A function that produces a sequence of indices.
|
34 | * @example <caption>Always increasing</caption>
|
35 | *
|
36 | * ```js
|
37 | * const gen = nthCheck.sequence('2n+3')
|
38 | *
|
39 | * gen() // `1`
|
40 | * gen() // `3`
|
41 | * gen() // `5`
|
42 | * gen() // `8`
|
43 | * gen() // `11`
|
44 | * ```
|
45 | *
|
46 | * @example <caption>With end value</caption>
|
47 | *
|
48 | * ```js
|
49 | *
|
50 | * const gen = nthCheck.sequence('-2n+5');
|
51 | *
|
52 | * gen() // 0
|
53 | * gen() // 2
|
54 | * gen() // 4
|
55 | * gen() // null
|
56 | * ```
|
57 | */
|
58 | export declare function sequence(formula: string): () => number | null;
|
59 | //# sourceMappingURL=index.d.ts.map |
\ | No newline at end of file |