Parses and compiles CSS nth-checks to highly optimized functions.
Installations
npm install nth-check
Score
99.6
Supply Chain
100
Quality
75.5
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Developer
fb55
Developer Guide
Module System
CommonJS, ESM
Min. Node Version
Typescript Support
Yes
Node Version
18.2.0
NPM Version
8.9.0
Statistics
57 Stars
781 Commits
30 Forks
3 Watching
2 Branches
6 Contributors
Updated on 28 Nov 2024
Languages
TypeScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
5,345,381,397
Last day
-21.3%
3,915,961
Compared to previous day
Last week
-8.7%
27,830,542
Compared to previous week
Last month
2.1%
123,319,576
Compared to previous month
Last year
4.4%
1,330,364,669
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
nth-check
Parses and compiles CSS nth-checks to highly optimized functions.
About
This 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.
nth-check
focusses on speed, providing optimized functions for different kinds of nth-child formulas, while still following the spec.
API
1import nthCheck, { parse, compile } from "nth-check";
nthCheck(formula)
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
'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
.
Example:
1const check = nthCheck("2n+3"); 2 3check(0); // `false` 4check(1); // `false` 5check(2); // `true` 6check(3); // `false` 7check(4); // `true` 8check(5); // `false` 9check(6); // `true`
parse(formula)
Parses 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.
Example:
1parse("2n+3"); // [2, 3]
compile([a, b])
Takes an array with two elements (as returned by .parse
) and returns a highly optimized function.
Example:
1const check = compile([2, 3]); 2 3check(0); // `false` 4check(1); // `false` 5check(2); // `true` 6check(3); // `false` 7check(4); // `true` 8check(5); // `false` 9check(6); // `true`
generate([a, b])
Returns a function that produces a monotonously increasing sequence of indices.
If the sequence has an end, the returned function will return null
after the last index in the sequence.
Example: An always increasing sequence
1const gen = nthCheck.generate([2, 3]); 2 3gen(); // `1` 4gen(); // `3` 5gen(); // `5` 6gen(); // `8` 7gen(); // `11`
Example: With an end value
1const gen = nthCheck.generate([-2, 5]); 2 3gen(); // 0 4gen(); // 2 5gen(); // 4 6gen(); // null
sequence(formula)
Parses and compiles a formula to a generator that produces a sequence of indices. Combination of parse
and generate
.
Example: An always increasing sequence
1const gen = nthCheck.sequence("2n+3"); 2 3gen(); // `1` 4gen(); // `3` 5gen(); // `5` 6gen(); // `8` 7gen(); // `11`
Example: With an end value
1const gen = nthCheck.sequence("-2n+5"); 2 3gen(); // 0 4gen(); // 2 5gen(); // 4 6gen(); // null
License: BSD-2-Clause
Security contact information
To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.
nth-check
for enterprise
Available as part of the Tidelift Subscription
The maintainers of nth-check
and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.
Stable Version
The latest stable version of the package.
Stable Version
2.1.1
HIGH
1
7.5/10
Summary
Inefficient Regular Expression Complexity in nth-check
Affected Versions
< 2.0.1
Patched Versions
2.0.1
Reason
30 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: BSD 2-Clause "Simplified" License: LICENSE:0
Reason
SAST tool is run on all commits
Details
- Info: SAST configuration detected: CodeQL
- Info: all commits (30) are checked with a SAST tool
Reason
2 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
Reason
dependency not pinned by hash detected -- score normalized to 4
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/fb55/nth-check/codeql-analysis.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/fb55/nth-check/codeql-analysis.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:31: update your workflow using https://app.stepsecurity.io/secureworkflow/fb55/nth-check/codeql-analysis.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/dependabot-automerge.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/fb55/nth-check/dependabot-automerge.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/nodejs-test.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/fb55/nth-check/nodejs-test.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/nodejs-test.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/fb55/nth-check/nodejs-test.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/nodejs-test.yml:46: update your workflow using https://app.stepsecurity.io/secureworkflow/fb55/nth-check/nodejs-test.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/nodejs-test.yml:48: update your workflow using https://app.stepsecurity.io/secureworkflow/fb55/nth-check/nodejs-test.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/nodejs-test.yml:64: update your workflow using https://app.stepsecurity.io/secureworkflow/fb55/nth-check/nodejs-test.yml/master?enable=pin
- Info: 0 out of 7 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 2 third-party GitHubAction dependencies pinned
- Info: 2 out of 2 npmCommand dependencies pinned
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Info: jobLevel 'contents' permission set to 'read': .github/workflows/codeql-analysis.yml:18
- Info: jobLevel 'actions' permission set to 'read': .github/workflows/codeql-analysis.yml:17
- Warn: jobLevel 'checks' permission set to 'write': .github/workflows/nodejs-test.yml:32
- Info: jobLevel 'contents' permission set to 'read': .github/workflows/nodejs-test.yml:31
- Warn: no topLevel permission defined: .github/workflows/codeql-analysis.yml:1
- Warn: topLevel 'contents' permission set to 'write': .github/workflows/dependabot-automerge.yml:7
- Info: topLevel 'contents' permission set to 'read': .github/workflows/nodejs-test.yml:15
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Score
6.2
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to nth-check
esquery
A query library for ECMAScript AST using a CSS selector like query language.
cheerio-select
CSS selector engine supporting jQuery selectors
@stdlib/constants-float64-max-safe-nth-factorial
Maximum safe nth factorial when stored in double-precision floating-point format.
croner
Trigger functions and/or evaluate cron expressions in JavaScript. No dependencies. Most features. All environments.