nth-check

  • Version 2.0.1
  • Published
  • 14 kB
  • 1 dependency
  • BSD-2-Clause license

Install

npm i nth-check
yarn add nth-check
pnpm add nth-check

Overview

Parses and compiles CSS nth-checks to highly optimized functions.

Index

Functions

function compile

compile: (parsed: [a: number, b: number]) => (index: number) => boolean;
  • Returns a function that checks if an elements index matches the given rule highly optimized to return the fastest solution.

    Parameter parsed

    A tuple [a, b], as returned by parse.

    Returns

    A highly optimized function that returns whether an index matches the nth-check.

    Example 1

    const check = nthCheck.compile([2, 3]);

    check(0); // false check(1); // false check(2); // true check(3); // false check(4); // true check(5); // false check(6); // true

function nthCheck

nthCheck: (formula: string) => (index: number) => boolean;
  • Parses and compiles a formula to a highly optimized function. Combination of parse and compile.

    If the formula doesn't match any elements, it returns [boolbase](https://github.com/fb55/boolbase)'s falseFunc. Otherwise, a function accepting an _index_ is returned, which returns whether or not the passed _index_ matches the formula.

    Note: The nth-rule starts counting at 1, the returned function at 0.

    Parameter formula

    The formula to compile.

    Example 1

    const check = nthCheck("2n+3");

    check(0); // false check(1); // false check(2); // true check(3); // false check(4); // true check(5); // false check(6); // true

function parse

parse: (formula: string) => [a: number, b: number];
  • Parses an expression.

    Returns

    An array containing the integer step size and the integer offset of the nth rule.

    Throws

    An Error if parsing fails.

    Example 1

    nthCheck.parse("2n+3"); // returns [2, 3]

Package Files (3)

Dependencies (1)

Dev Dependencies (10)

Peer Dependencies (0)

No peer dependencies.

Badge

To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/nth-check.

  • Markdown
    [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/nth-check)
  • HTML
    <a href="https://www.jsdocs.io/package/nth-check"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>