Developer Setup
Relevant source files
The following files were used as context for generating this wiki page:
The nth-check project is a specialized utility designed to parse and compile CSS nth-child formulas into optimized JavaScript functions. The developer setup focuses on a TypeScript-based environment optimized for performance and specification compliance.
This setup ensures that developers can contribute to the core logic of parsing and compiling selectors while maintaining strict code quality through linting, formatting, and automated testing via Vitest. Sources: package.json:1-5, README.md:5-9
Environment Requirements
The project requires a modern Node.js environment to support ECMAScript modules and current TypeScript features.
| Requirement | Value | Source |
|---|---|---|
| Node.js | >=20.19.0 | package.json:52-54 |
| Package Manager | npm (standard) | package.json:30-41 |
| Module Type | ES Module (type: module) | package.json:2 |
Build and Compilation
The project uses TypeScript for development, targeting es2022. The build process transforms source files from the src directory into a distributable dist directory.
TypeScript Configuration
The compiler is configured for strict type checking and modern module resolution.
- Target:
es2022 - Module Resolution:
nodenext - Output:
distdirectory with declaration files and source maps enabled.
Sources: tsconfig.json:3-10, tsconfig.json:13
Build Pipeline Flow
The following diagram illustrates the transformation from source code to executable package.
The build is triggered using npm run build, which executes the tsc command. Sources: package.json:31, tsconfig.json:8-10
Development Workflow Scripts
Development tasks are categorized into building, formatting, linting, and testing.
| Script | Command | Description |
|---|---|---|
build | tsc | Compiles TypeScript source to JavaScript. |
format | npm run format:es && npm run format:biome | Runs both ESLint and Biome formatters. |
lint | npm run lint:es && npm run lint:ts && npm run lint:biome | Comprehensive check for style and type errors. |
test | npm run test:vi && npm run lint | Runs Vitest suites and lints code. |
test:vi | vitest run | Executes unit tests once. |
Sources: package.json:30-41
Code Quality Tools
The project utilizes two primary toolsets for maintaining code quality: Biome and ESLint.
Biome Configuration
Biome is used for both linting and formatting, targeting TypeScript, Markdown, JSON, and YAML files. It is configured to ignore node_modules, coverage, and lib directories. Sources: biome.json:7-16
Specific linter rules enabled include:
useTopLevelRegexfor performance.noUselessElseanduseCollapsedIffor style consistency.noConstantBinaryExpressionsfor suspicious code detection.
Sources: biome.json:24-67
ESLint Configuration
ESLint is used alongside a specialized TypeScript configuration (tsconfig.eslint.json) that includes the test directory in its scope, which is normally excluded from the production build. Sources: tsconfig.eslint.json:8, package.json:37
Testing Architecture
Testing is performed using Vitest. The test suite validates both the parsing logic and the compiled function performance.
Unit tests are located in .spec.ts files. The tests compare the optimized output of the compile function against a "slow" reference implementation to ensure correctness across 2,000 potential indices. Sources: src/compile.spec.ts:13-30, src/parse.spec.ts:6-18
Test Data
Fixtures in src/__fixtures__/rules.ts provide a comprehensive list of:
- Valid Rules: e.g.,
"2n+1","even","-n+3". - Invalid Rules: e.g.,
"asdf","2n+-0","2+0".
Sources: src/fixtures/rules.ts:1-45
Summary
The nth-check developer environment is a streamlined TypeScript setup. It prioritizes strict adherence to CSS specifications through a robust testing suite and enforces high code quality using a multi-linter approach (Biome and ESLint). The build process is optimized for ESM distribution with full source map and declaration support.