Mockmate is a lightweight mock data generator for JavaScript and TypeScript. It helps frontend and full-stack developers generate, filter, and extend JSON data from public APIs with a clean and declarative API.
- Works with JavaScript and TypeScript
- Zero configuration
- Uses real public APIs
- Fully typed API
- Extend and customize data
- Node.js and browser compatible
yarn add mockmate
npm install mockmate
pnpm add mockmateimport { mockmate } from "mockmate";
const users = await mockmate({
category: "users",
quantity: 5,
});const users = await mockmate({
category: "users",
pick: ["name", "email"],
});const users = await mockmate({
category: "users",
extend: {
isActive: () => true,
score: () => Math.floor(Math.random() * 100),
},
});const users = await generate({
quantity: 3,
schema: {
id: () => crypto.randomUUID(),
username: () => `user_${Math.random().toString(36).slice(2)}`,
age: () => Math.floor(Math.random() * 50) + 18,
email: () => "[email protected]",
},
});try {
await mockmate({ category: "users" });
} catch (error) {
if (error instanceof Error) {
console.error(error.message);
}
}users
posts
comments
todos
Mockmate uses Jest for testing. You can run tests locally with:
pnpm add -D jest ts-jest @types/jest
pnpm jestOr using npm/yarn:
npm install --save-dev jest ts-jest @types/jest
npm test
// tests/mockmate.test.ts
import { mockmate } from "../src";
describe("mockmate", () => {
it("should generate an array of users", async () => {
const users = await mockmate({ category: "users", quantity: 3 });
expect(users).toHaveLength(3);
expect(users[0]).toHaveProperty("name");
});
it("should pick only selected fields", async () => {
const users = await mockmate({
category: "users",
quantity: 1,
pick: ["email"],
});
expect(users[0]).toHaveProperty("email");
expect(users[0]).not.toHaveProperty("name");
});
});MIT