{"name":"nth-check","version":"3.0.0","keywords":["nth-child","nth","css"],"author":{"name":"Felix Boehm","email":"me@feedic.com"},"license":"BSD-2-Clause","_id":"nth-check@3.0.0","maintainers":[{"name":"fb55","email":"me@feedic.com"}],"homepage":"https://github.com/fb55/nth-check","bugs":{"url":"https://github.com/fb55/nth-check/issues"},"dist":{"shasum":"180338e1ee5be19acfdd9124d0ea04153b145586","tarball":"http://registry-npm.ywwl.com/nth-check/download/nth-check-3.0.0.tgz","fileCount":15,"integrity":"sha512-7kmdWhlAQtOcdZEh8/BIh2Z5KW8Af0RnET+cWS5esqx8ZVzSlt2bP+w+YnWt37PzBmJRUcaOQXFJ2CREM0860Q==","signatures":[{"sig":"MEQCIGpkqyCWsFJ9nT+qWKAdonm7YgJb4/6dtXK1a54tx+13AiAQkowqEr0JIo2M9SquVftbut9VfjPH16Fj+9rJBWLkKg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/nth-check@3.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":22947,"size":6111,"noattachment":false,"key":"/nth-check/-/nth-check-3.0.0.tgz"},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","engines":{"node":">=20.19.0"},"exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"funding":{"url":"https://github.com/fb55/nth-check?sponsor=1","type":"github"},"gitHead":"64557a7df1e04150594459866e8293ef0a330f00","scripts":{"lint":"npm run lint:es && npm run lint:biome","test":"npm run test:vi && npm run lint","build":"tsc","format":"npm run format:es && npm run format:biome","lint:es":"eslint .","prepare":"npm run build","test:vi":"vitest run","format:es":"npm run lint:es -- --fix","lint:biome":"biome check .","format:biome":"biome check --write ."},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:515ef52f-df69-447f-9098-39cc7878f0cf"}},"repository":{"url":"git+https://github.com/fb55/nth-check.git","type":"git"},"_npmVersion":"11.9.0","description":"Parses and compiles CSS nth-checks to highly optimized functions.","directories":{},"sideEffects":false,"_nodeVersion":"24.14.0","dependencies":{"boolbase":"^2.0.0"},"_hasShrinkwrap":false,"devDependencies":{"eslint":"^10.0.3","vitest":"^4.0.18","typescript":"^5.9.3","@types/node":"^25.5.0","@biomejs/biome":"^2.4.7","@eslint/compat":"^2.0.3","typescript-eslint":"^8.57.1","eslint-config-biome":"^2.1.3","@feedic/eslint-config":"^0.2.3"},"_npmOperationalInternal":{"tmp":"tmp/nth-check_3.0.0_1773765012562_0.35626008879027804","host":"s3://npm-registry-packages-npm-production"},"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 & 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","publish_time":1773765012728,"_cnpm_publish_time":1773765012728,"dist-tags":{"latest":"3.0.1"}}