Skip to content

Commit 025eeb4

Browse files
authored
feat: add URI lexer/parser with URL normalization (#1)
Introduce a compiler-style URI lexer and parser that returns a tokenized AST, plus a stricter parseUrl normalizer for production URL validation. Establish build/test tooling and packaging for dual ESM/CJS distribution so the library is ready to publish.
1 parent 0eb94a3 commit 025eeb4

29 files changed

+13083
-0
lines changed

.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Dependencies
2+
node_modules/
3+
4+
# Build output
5+
dist/
6+
7+
# Test coverage
8+
coverage/
9+
10+
# IDE
11+
.vscode/
12+
.idea/
13+
*.swp
14+
*.swo
15+
*~
16+
17+
# OS
18+
.DS_Store
19+
Thumbs.db
20+
21+
# Logs
22+
*.log
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# Environment
28+
.env
29+
.env.local
30+
.env.*.local

.npmignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Source files
2+
src/
3+
4+
# Examples
5+
examples/
6+
7+
# Scripts
8+
scripts/
9+
10+
# Tests and coverage
11+
coverage/
12+
*.test.ts
13+
*.spec.ts
14+
15+
# Config files
16+
tsconfig.json
17+
tsconfig.eslint.json
18+
vitest.config.ts
19+
eslint.config.js
20+
.prettierrc
21+
22+
# Git
23+
.git/
24+
.gitignore
25+
26+
# IDE
27+
.vscode/
28+
.idea/
29+
30+
# Project files
31+
PROJECT_SUMMARY.md
32+
33+
# Node
34+
node_modules/

.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all",
4+
"printWidth": 100,
5+
"tabWidth": 2,
6+
"semi": true
7+
}

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Changelog
2+
3+
## 0.1.0 - 2026-01-22
4+
5+
### Added
6+
- Initial implementation
7+
- Lexer with explicit token types
8+
- Parser with support for:
9+
- Optional schemes
10+
- Scheme-relative URLs (//example.com)
11+
- Host-ish URLs (example.com, localhost:3000)
12+
- Absolute paths (/path)
13+
- Relative paths
14+
- Query strings and fragments
15+
- IPv6 addresses
16+
- Userinfo
17+
- Typed AST for URI components
18+
- Lossless parsing (raw values preserved)

CONTRIBUTING.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Contributing to URI Parser
2+
3+
Thank you for your interest in contributing to the URI Parser!
4+
5+
## Development Setup
6+
7+
1. Clone the repository
8+
2. Install dependencies:
9+
```bash
10+
npm install
11+
```
12+
13+
3. Run tests:
14+
```bash
15+
npm test
16+
```
17+
18+
4. Run tests in watch mode:
19+
```bash
20+
npm run test:watch
21+
```
22+
23+
5. Run linter:
24+
```bash
25+
npm run lint
26+
```
27+
28+
## Project Structure
29+
30+
```
31+
uri-parser/
32+
├── src/
33+
│ ├── lexer-types.ts # Token type definitions
34+
│ ├── lexer.ts # Lexer implementation
35+
│ ├── parser-types.ts # AST type definitions
36+
│ ├── parser.ts # Parser implementation
37+
│ ├── errors.ts # Error classes
38+
│ └── index.ts # Public API exports
39+
├── scripts/
40+
│ └── build.mjs # Build script
41+
└── tests/ # Test files
42+
```
43+
44+
## Design Philosophy
45+
46+
This parser follows the temporal-parser philosophy:
47+
48+
1. **Explicit tokens → shallow grammar → AST → later normalization**
49+
2. **Lexer is permissive and logic-light**
50+
3. **Parser builds a typed AST**
51+
4. **Lossless parsing** (raw values preserved)
52+
5. **Easy to extend** with normalization passes
53+
54+
## Testing
55+
56+
- Write tests for new features
57+
- Ensure existing tests pass
58+
- Aim for high code coverage
59+
- Test edge cases and error conditions
60+
61+
## Code Style
62+
63+
- Follow the existing code style
64+
- Use TypeScript strict mode
65+
- Add JSDoc comments for public APIs
66+
- Run `npm run lint:fix` before committing
67+
68+
## Submitting Changes
69+
70+
1. Fork the repository
71+
2. Create a feature branch
72+
3. Make your changes
73+
4. Add tests
74+
5. Run the test suite
75+
6. Submit a pull request
76+
77+
## Questions?
78+
79+
Feel free to open an issue for discussion!

LICENSE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2026 Taskade
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0 commit comments

Comments
 (0)