{"type":"module","name":"nth-check","version":"3.0.1","description":"Parses and compiles CSS nth-checks to highly optimized functions.","author":{"name":"Felix Boehm","email":"me@feedic.com"},"license":"BSD-2-Clause","sideEffects":false,"funding":{"type":"github","url":"https://github.com/fb55/nth-check?sponsor=1"},"main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"scripts":{"build":"tsc","format":"npm run format:es && npm run format:biome","format:biome":"biome check --write .","format:es":"npm run lint:es -- --fix","lint":"npm run lint:es && npm run lint:biome","lint:biome":"biome check .","lint:es":"eslint .","prepare":"npm run build","test":"npm run test:vi && npm run lint","test:vi":"vitest run"},"repository":{"type":"git","url":"git+https://github.com/fb55/nth-check.git"},"keywords":["nth-child","nth","css"],"bugs":{"url":"https://github.com/fb55/nth-check/issues"},"homepage":"https://github.com/fb55/nth-check","engines":{"node":">=20.19.0"},"dependencies":{"boolbase":"^2.0.0"},"devDependencies":{"@biomejs/biome":"^2.4.7","@eslint/compat":"^2.0.3","@feedic/eslint-config":"^0.3.1","@types/node":"^25.5.0","eslint":"^10.0.3","eslint-config-biome":"^2.1.3","typescript":"^5.9.3","typescript-eslint":"^8.57.1","vitest":"^4.0.18"},"gitHead":"395790bb177734bf6e019bdf096272979fa8e905","_id":"nth-check@3.0.1","_nodeVersion":"24.14.0","_npmVersion":"11.9.0","dist":{"integrity":"sha512-GX0gsdbGVCgnRgbeGaubfjpBXyYRWOOCVeYh08bSQvDZqxz5ndXs1OTfAt/h36G1xvI94YIspsI0sVFqAV9+RQ==","shasum":"a5ede96060f7f0b74d7d3d8425f2a8f0610c5776","tarball":"http://registry-npm.ywwl.com/nth-check/download/nth-check-3.0.1.tgz","fileCount":19,"unpackedSize":31513,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/nth-check@3.0.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIDNgojqHoNKb/BjsM53CGfRI8bKcr6OuW8PzDb4UF67SAiB++wMZma3O3gc5Ljf+V+9gWs/QtaQ+pg0SPvC6pPklig=="}],"size":7259,"noattachment":false,"key":"/nth-check/-/nth-check-3.0.1.tgz"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:515ef52f-df69-447f-9098-39cc7878f0cf"}},"directories":{},"maintainers":[{"name":"fb55","email":"me@feedic.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/nth-check_3.0.1_1773789177515_0.8703180515838107"},"_hasShrinkwrap":false,"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":1773789177654,"_cnpm_publish_time":1773789177654,"dist-tags":{"latest":"3.0.1"}}