@mockmaster/core 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +86 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# @mockmaster/core
|
|
2
|
+
|
|
3
|
+
> Core mocking engine for mock-master - Path matching and HTTP routing
|
|
4
|
+
|
|
5
|
+
Part of the [mock-master](https://github.com/yourusername/mock-master) monorepo.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @mockmaster/core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- **Path Matching** - Exact paths, parameters (`:id`), and wildcards (`*`)
|
|
16
|
+
- **HTTP Methods** - GET, POST, PUT, DELETE, PATCH, and more
|
|
17
|
+
- **Type Safe** - Full TypeScript support with strict typing
|
|
18
|
+
- **Zero Dependencies** - Lightweight and fast
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
### Path Matching
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { matchPath } from '@mockmaster/core'
|
|
26
|
+
|
|
27
|
+
// Exact match
|
|
28
|
+
matchPath('/users', '/users') // true
|
|
29
|
+
matchPath('/users', '/posts') // false
|
|
30
|
+
|
|
31
|
+
// Parameter matching
|
|
32
|
+
matchPath('/users/:id', '/users/123') // true
|
|
33
|
+
matchPath('/users/:id', '/users/abc') // true
|
|
34
|
+
|
|
35
|
+
// Wildcard matching
|
|
36
|
+
matchPath('/api/*', '/api/users') // true
|
|
37
|
+
matchPath('/api/*', '/api/users/123') // true
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Mock Matching
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { createMock, findMatchingMock } from '@mockmaster/core'
|
|
44
|
+
|
|
45
|
+
const mocks = [
|
|
46
|
+
createMock('/users', 'GET', { users: [] }),
|
|
47
|
+
createMock('/users/:id', 'GET', { id: 1, name: 'John' }),
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
// Find matching mock
|
|
51
|
+
const mock = findMatchingMock(mocks, '/users/123', 'GET')
|
|
52
|
+
console.log(mock?.response) // { id: 1, name: 'John' }
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## API
|
|
56
|
+
|
|
57
|
+
### `matchPath(pattern: string, path: string): boolean`
|
|
58
|
+
|
|
59
|
+
Matches a URL path against a pattern.
|
|
60
|
+
|
|
61
|
+
**Patterns:**
|
|
62
|
+
- Exact: `/users`
|
|
63
|
+
- Parameters: `/users/:id` (matches any value)
|
|
64
|
+
- Wildcards: `/api/*` (matches any path after `/api/`)
|
|
65
|
+
|
|
66
|
+
### `matchMethod(pattern: string, method: string): boolean`
|
|
67
|
+
|
|
68
|
+
Matches an HTTP method (case-insensitive).
|
|
69
|
+
|
|
70
|
+
### `createMock<T>(path: string, method: string, response: T): Mock<T>`
|
|
71
|
+
|
|
72
|
+
Creates a mock object with path, method, and response.
|
|
73
|
+
|
|
74
|
+
### `findMatchingMock<T>(mocks: Mock<T>[], path: string, method: string): Mock<T> | undefined`
|
|
75
|
+
|
|
76
|
+
Finds the first mock matching the given path and method.
|
|
77
|
+
|
|
78
|
+
## Links
|
|
79
|
+
|
|
80
|
+
- [Main Documentation](https://github.com/yourusername/mock-master)
|
|
81
|
+
- [npm Organization](https://www.npmjs.com/org/mockmaster)
|
|
82
|
+
- [Report Issues](https://github.com/yourusername/mock-master/issues)
|
|
83
|
+
|
|
84
|
+
## License
|
|
85
|
+
|
|
86
|
+
MIT
|