Skip to content

Commit 9451eed

Browse files
committed
Update Readme, add Contributing and license
1 parent 2a91733 commit 9451eed

File tree

3 files changed

+93
-14
lines changed

3 files changed

+93
-14
lines changed

CONTRIBUTING.md

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Contributing to Mock Data Generator
2+
3+
I'd love your input or feedback! I want to make contributing to this project as easy and transparent as possible.
4+
5+
## Development Process
6+
7+
I've tried to set a minumum Test-Driven Development (TDD) flow. Before making any changes:
8+
9+
1. Clone the repository
10+
2. Install dependencies:
11+
```sh
12+
deno install
13+
```
14+
3. Run the test suite to ensure everything works:
15+
```sh
16+
deno test --watch
17+
```
18+
19+
### TDD Workflow
20+
21+
1. Write a failing test first
22+
2. Run tests to verify it fails (`deno test --watch`)
23+
3. Implement the minimum code to make it pass
24+
5. Refactor if needed
25+
26+
## Pull Request Process
27+
28+
1. Fork the repo and create your branch from `main`
29+
2. Ensure tests pass and add new ones for your changes
30+
3. Update documentation if needed
31+
4. Create a Pull Request with a clear description
32+
33+
## Code Style
34+
35+
- Use TypeScript
36+
- Follow existing code formatting (but don't worry too much, in the future I will set a CI to run `deno fmt` automatically).
37+
- Keep functions small and focused
38+
- Add JSDoc comments for public APIs
39+
40+
## Running Tests
41+
42+
Tests are essential in this project. Always run:
43+
44+
```sh
45+
deno test --watch # Run tests in watch mode during development
46+
```
47+
48+
## Questions?
49+
50+
Feel free to open an issue for any questions or concerns.

LICENSE

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

README.md

+21-14
Original file line numberDiff line numberDiff line change
@@ -48,35 +48,42 @@ const users = createRandomUsers(3);
4848

4949
### Generate Mock Data from a Generator
5050

51-
The `getMocksFromGenerator` function preserves the types of your generator functions:
51+
The `getMocksFromGenerator` function lets you define your own data generation logic. You provide an object where each property is a function that generates values. You can mix and match:
52+
- Faker.js functions
53+
- Your own custom functions
54+
- Random value generators
55+
- Fixed value functions
56+
- Any JavaScript/TypeScript function that returns a value
5257

5358
```typescript
5459
import { getMocksFromGenerator } from "@functions/mock";
5560
import { faker } from "@faker-js/faker";
5661

5762
const yourGenerator = {
63+
// Use faker functions directly
5864
id: faker.string.uuid,
59-
name: faker.person.firstName,
60-
age: () => faker.number.int({ min: 18, max: 99 }),
65+
// Your own random logic
66+
age: () => Math.floor(Math.random() * 100),
67+
// Mix calculated and faker values
68+
username: () => `user_${faker.number.int(1000)}`,
69+
// Fixed values
70+
role: () => 'user',
71+
// Complex custom logic
72+
status: () => {
73+
const statuses = ['active', 'inactive', 'pending'];
74+
return statuses[Math.floor(Math.random() * statuses.length)];
75+
}
6176
};
6277

6378
const createRandomObjects = getMocksFromGenerator(yourGenerator);
64-
// TypeScript infers exact return types from your generator functions
79+
// TypeScript should infers return types from your generator functions
6580
const objects = createRandomObjects(5);
6681
// objects is typed as Array<{ id: string; name: string; age: number }>
6782
```
6883

84+
## Contributing
6985

70-
71-
### `getMocksFromGenerator`
72-
73-
Type-safe generator that creates mock data from a predefined generator.
74-
75-
**Parameters:**
76-
- `gen`: An object where keys are property names and values are functions that generate the property values. Types are automatically inferred from your generator functions.
77-
78-
**Returns:**
79-
- A strongly-typed function that generates an array of mock objects with exact property types.
86+
This is a Test-Driven Development (TDD) project. Please read the [Contributing Guidelines](CONTRIBUTING.md) for details on development process and how to submit pull requests.
8087

8188
## License
8289

0 commit comments

Comments
 (0)