@mockmate/mockmate
v1.0.3
Published
<p> <img src="https://img.shields.io/npm/v/@mockmate/mockmate" alt="npm version" /> <img src="https://img.shields.io/npm/dw/@mockmate/mockmate" alt="downloads" /> <img src="https://img.shields.io/github/license/monokkai/mockmate" alt="license" />
Readme
mockmate
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.
Features
- Works with JavaScript and TypeScript
- Zero configuration
- Uses real public APIs
- Fully typed API
- Extend and customize data
- Node.js and browser compatible
- Customize view of data
Installation
yarn add mockmate
npm install mockmate
pnpm add mockmateBasic Usage
import { mockmate } from "mockmate";
const users = await mockmate({
category: "users",
quantity: 5,
});Pick Fields
const users = await mockmate({
category: "users",
pick: ["name", "email"],
});Extend Data
const users = await mockmate({
category: "users",
extend: {
isActive: () => true,
score: () => Math.floor(Math.random() * 100),
},
});Different sources
const users = await mockmate({
category: "users",
source: "fakestoreapi", // source: "jsonplaceholder"
quantity: 2,
});Generate Schema
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]",
},
});Error Handling
try {
await mockmate({ category: "users" });
} catch (error) {
if (error instanceof Error) {
console.error(error.message);
}
}Supported Categories
users
posts
comments
todosRunning Tests
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 testLicense
MIT
