source: imaps-frontend/node_modules/nth-check/lib/esm/index.js

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.6 KB
Line 
1import { parse } from "./parse.js";
2import { compile, generate } from "./compile.js";
3export { 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 */
27export default function nthCheck(formula) {
28 return compile(parse(formula));
29}
30/**
31 * Parses and compiles a formula to a generator that produces a sequence of indices.
32 * Combination of {@link parse} and {@link generate}.
33 *
34 * @param formula The formula to compile.
35 * @returns A function that produces a sequence of indices.
36 * @example <caption>Always increasing</caption>
37 *
38 * ```js
39 * const gen = nthCheck.sequence('2n+3')
40 *
41 * gen() // `1`
42 * gen() // `3`
43 * gen() // `5`
44 * gen() // `8`
45 * gen() // `11`
46 * ```
47 *
48 * @example <caption>With end value</caption>
49 *
50 * ```js
51 *
52 * const gen = nthCheck.sequence('-2n+5');
53 *
54 * gen() // 0
55 * gen() // 2
56 * gen() // 4
57 * gen() // null
58 * ```
59 */
60export function sequence(formula) {
61 return generate(parse(formula));
62}
63//# sourceMappingURL=index.js.map
Note: See TracBrowser for help on using the repository browser.