Skip to content

Commit 2a91733

Browse files
committed
First Readme
1 parent 367d0cc commit 2a91733

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Quick Mock Data Generator
2+
3+
Need test data quickly? This lightweight utility helps you generate realistic mock data in seconds. Choose from common properties like names, emails, and dates, **or define your own generators**. Perfect for prototypes, tests, and demos where you need meaningful data fast.
4+
5+
Built on top of `@faker-js/faker`, it provides a simpler interface while maintaining type safety and full TypeScript support.
6+
7+
Key features:
8+
- 🚀 Quick property selection from common data types
9+
- 🎯 Generate exactly what you need, nothing more
10+
- 📦 Zero configuration required
11+
- 🔍 Full TypeScript support with autocompletion
12+
13+
## Installation
14+
15+
### Using Deno
16+
17+
```sh
18+
deno add @functions/mock
19+
```
20+
21+
### Using npm / pnpm / or others
22+
23+
```sh
24+
npx jsr add @functions/mock
25+
pnpm dlx jsr add @functions/mock
26+
yarn dlx jsr add @functions/mock
27+
bunx jsr add @functions/mock
28+
```
29+
30+
## Usage
31+
32+
### Generate Mock Data with Specific Properties
33+
34+
The `getMocksWith` function allows you to pick from a predefined set of common properties (like name, email, age, avatar, etc.) and quickly generate objects containing just those properties. Perfect for creating test data with exactly what you need in a fast way:
35+
36+
This basically returns a function that will create mock data based on a list of predefined properties.
37+
38+
39+
```typescript
40+
import { getMocksWith } from "@functions/mock";
41+
42+
// Autosuggestion will let you pick the properties you want in your mock objects
43+
const createRandomUsers = getMocksWith(['name', 'age', 'email']);
44+
45+
// Generate 3 users with only those properties
46+
const users = createRandomUsers(3);
47+
```
48+
49+
### Generate Mock Data from a Generator
50+
51+
The `getMocksFromGenerator` function preserves the types of your generator functions:
52+
53+
```typescript
54+
import { getMocksFromGenerator } from "@functions/mock";
55+
import { faker } from "@faker-js/faker";
56+
57+
const yourGenerator = {
58+
id: faker.string.uuid,
59+
name: faker.person.firstName,
60+
age: () => faker.number.int({ min: 18, max: 99 }),
61+
};
62+
63+
const createRandomObjects = getMocksFromGenerator(yourGenerator);
64+
// TypeScript infers exact return types from your generator functions
65+
const objects = createRandomObjects(5);
66+
// objects is typed as Array<{ id: string; name: string; age: number }>
67+
```
68+
69+
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.
80+
81+
## License
82+
83+
This project is licensed under the MIT License.

0 commit comments

Comments
 (0)