{"id":16777034,"url":"https://github.com/fb55/nth-check","last_synced_at":"2026-03-18T01:11:54.500Z","repository":{"id":14159046,"uuid":"16864923","full_name":"fb55/nth-check","owner":"fb55","description":"Parses and compiles CSS nth-checks to highly optimized functions.","archived":false,"fork":false,"pushed_at":"2025-04-03T14:47:35.000Z","size":2694,"stargazers_count":57,"open_issues_count":4,"forks_count":30,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-07T01:11:18.179Z","etag":null,"topics":["css","css-selector","nth-check"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fb55.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["fb55"],"tidelift":"npm/nth-check"}},"created_at":"2014-02-15T15:06:10.000Z","updated_at":"2025-04-03T14:46:28.000Z","dependencies_parsed_at":"2024-01-02T15:47:13.569Z","dependency_job_id":"c6ca8e84-e6bd-43f1-af08-07a2172ec67c","html_url":"https://github.com/fb55/nth-check","commit_stats":{"total_commits":783,"total_committers":7,"mean_commits":"111.85714285714286","dds":"0.048531289910600295","last_synced_commit":"4abfeae5ad7f79a7e8d13b0fa98767b933675056"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fb55%2Fnth-check","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fb55%2Fnth-check/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fb55%2Fnth-check/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fb55%2Fnth-check/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fb55","download_url":"https://codeload.github.com/fb55/nth-check/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247804733,"owners_count":20999033,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["css","css-selector","nth-check"],"created_at":"2024-10-13T07:11:42.417Z","updated_at":"2026-03-18T01:11:54.492Z","avatar_url":"https://github.com/fb55.png","language":"TypeScript","funding_links":["https://github.com/sponsors/fb55","https://tidelift.com/funding/github/npm/nth-check","https://tidelift.com/security"],"categories":[],"sub_categories":[],"readme":"# nth-check [![Build Status](https://travis-ci.org/fb55/nth-check.svg)](https://travis-ci.org/fb55/nth-check)\n\nParses and compiles CSS nth-checks to highly optimized functions.\n\n### About\n\nThis module can be used to parse \u0026 compile nth-checks, as they are found in CSS 3's `nth-child()` and `nth-last-of-type()`. It can be used to check if a given index matches a given nth-rule, or to generate a sequence of indices matching a given nth-rule.\n\n`nth-check` focusses on speed, providing optimized functions for different kinds of nth-child formulas, while still following the [spec](http://www.w3.org/TR/css3-selectors/#nth-child-pseudo).\n\n### API\n\n```js\nimport nthCheck, { parse, compile } from \"nth-check\";\n```\n\n##### `nthCheck(formula)`\n\nParses and compiles a formula to a highly optimized function. Combination of `parse` and `compile`.\n\nIf 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.\n\n**Note**: The nth-rule starts counting at `1`, the returned function at `0`.\n\n**Example:**\n\n```js\nconst check = nthCheck(\"2n+3\");\n\ncheck(0); // `false`\ncheck(1); // `false`\ncheck(2); // `true`\ncheck(3); // `false`\ncheck(4); // `true`\ncheck(5); // `false`\ncheck(6); // `true`\n```\n\n##### `parse(formula)`\n\nParses the expression, throws an `Error` if it fails. Otherwise, returns an array containing the integer step size and the integer offset of the nth rule.\n\n**Example:**\n\n```js\nparse(\"2n+3\"); // [2, 3]\n```\n\n##### `compile([a, b])`\n\nTakes an array with two elements (as returned by `.parse`) and returns a highly optimized function.\n\n**Example:**\n\n```js\nconst check = compile([2, 3]);\n\ncheck(0); // `false`\ncheck(1); // `false`\ncheck(2); // `true`\ncheck(3); // `false`\ncheck(4); // `true`\ncheck(5); // `false`\ncheck(6); // `true`\n```\n\n##### `generate([a, b])`\n\nReturns a function that produces a monotonously increasing sequence of indices.\n\nIf the sequence has an end, the returned function will return `null` after the last index in the sequence.\n\n**Example:** An always increasing sequence\n\n```js\nconst gen = nthCheck.generate([2, 3]);\n\ngen(); // `1`\ngen(); // `3`\ngen(); // `5`\ngen(); // `8`\ngen(); // `11`\n```\n\n**Example:** With an end value\n\n```js\nconst gen = nthCheck.generate([-2, 5]);\n\ngen(); // 0\ngen(); // 2\ngen(); // 4\ngen(); // null\n```\n\n##### `sequence(formula)`\n\nParses and compiles a formula to a generator that produces a sequence of indices. Combination of `parse` and `generate`.\n\n**Example:** An always increasing sequence\n\n```js\nconst gen = nthCheck.sequence(\"2n+3\");\n\ngen(); // `1`\ngen(); // `3`\ngen(); // `5`\ngen(); // `8`\ngen(); // `11`\n```\n\n**Example:** With an end value\n\n```js\nconst gen = nthCheck.sequence(\"-2n+5\");\n\ngen(); // 0\ngen(); // 2\ngen(); // 4\ngen(); // null\n```\n\n---\n\nLicense: BSD-2-Clause\n\n## Security contact information\n\nTo report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security).\nTidelift will coordinate the fix and disclosure.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffb55%2Fnth-check","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffb55%2Fnth-check","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffb55%2Fnth-check/lists"}