-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathllms.txt
97 lines (67 loc) · 3.46 KB
/
llms.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# RoutingKit
RoutingKit is a lightweight and high-performance routing library for Dart, suitable for both web and command-line applications.
## Project Overview
RoutingKit provides a flexible and efficient routing system with the following features:
- Fast route matching and parameter extraction
- Support for static, parameterized, and wildcard routes
- Efficient memory usage through a trie-based route storage
- Type-safe route handlers
- Configurable case sensitivity for path matching
## Core Components
- `Router` interface: Defines the contract for router implementations
- `MatchedRoute`: Represents a matched route result
- `createRouter()`: Factory function to create a new router instance
## Code Structure
The project has been refactored with a cleaner architecture:
- `lib/routingkit.dart`: Public API entry point that exports only the necessary types
- `lib/src/types.dart`: Defines the core interfaces and types
- `lib/src/create_router.dart`: Factory function implementation
- `lib/src/_internal/`: Contains internal implementation details:
- `router.dart`: Main router implementation
- `context.dart`: Shared state for the router
- `node.dart`: Trie node data structure
- `add_route.dart`: Route addition implementation
- `find_route.dart`: Single route matching
- `find_all_routes.dart`: Multiple route matching
- `remove_route.dart`: Route removal logic
- `utils.dart`: Shared utility functions
## Usage Example
```dart
// Create a router with default settings (case-sensitive)
final router = createRouter<String>();
// Create a case-insensitive router
final caseInsensitiveRouter = createRouter<String>(caseSensitive: false);
// Add routes
router.add('GET', '/path', 'static route');
router.add('POST', '/path/:name', 'name route');
// Find routes
final match = router.find('GET', '/path'); // => MatchedRoute{data: static route, params: {}}
```
## Feature Details
- **Static Routes**: Match exact paths (`/users`)
- **Parameterized Routes**: Extract values from paths (`/users/:id` → `/users/123` extracts `id: '123'`)
- **Optional Parameters**: Support for optional segments (`/files/:name?`)
- **Wildcard Routes**: Match multiple segments (`/assets/**` matches any path starting with `/assets/`)
- **HTTP Method Matching**: Different handlers for different HTTP methods
- **Case Sensitivity Control**: Configure whether matching is case-sensitive
## API Reference
### Router<T> Interface
The `Router<T>` interface defines the contract for router implementations with generic type `T` for route data.
#### Properties:
- `String anyMethodToken`: Token used to represent any HTTP method
- `bool caseSensitive`: Whether path matching is case-sensitive
#### Methods:
- `void add(String? method, String path, T data)`: Adds a new route
- `MatchedRoute<T>? find(String? method, String path)`: Finds the first matching route
- `Iterable<MatchedRoute<T>> findAll(String? method, String path)`: Finds all matching routes
- `void remove(String? method, String path)`: Removes a route
### MatchedRoute<T> Class
The `MatchedRoute<T>` class represents a matched route result.
#### Properties:
- `T data`: Data associated with the matched route
- `Map<String, String> params`: Parameters extracted from the route
### createRouter<T> Function
Creates a new router instance with the specified configuration.
#### Parameters:
- `String anyMethodToken`: Token used to represent any HTTP method, defaults to 'any'
- `bool caseSensitive`: Whether path matching is case-sensitive, defaults to true