GitHub - SukhdevThukral/mockit: Generate a realistic mock API straight from your TypeScript types - zero config, one command. · GitHub
/" data-turbo-transient="true" />
Skip to content
Type / to search
Sign in<br>Sign upAppearance settings
You signed in with another tab or window. Reload to refresh your session.<br>You signed out in another tab or window. Reload to refresh your session.<br>You switched accounts on another tab or window. Reload to refresh your session.
Dismiss alert
{{ message }}
SukhdevThukral
mockit
Public
Notifications<br>You must be signed in to change notification settings
Fork
Star
main
BranchesTags
Go to file
CodeOpen more actions menu
Folders and files<br>NameNameLast commit message<br>Last commit date<br>Latest commit
History<br>18 Commits<br>18 Commits
src
src
.gitignore
.gitignore
LICENSE
LICENSE
README.md
README.md
example.ts
example.ts
hard-example.ts
hard-example.ts
package-lock.json
package-lock.json
package.json
package.json
tsconfig.json
tsconfig.json
View all files
Repository files navigation
ts-mockit
The types you already wrote, turned into a working mock API.
Introduction
You already write TypeScript interfaces. ts-mockit reads them and spins up a real local API returning realistic fake date that matches your types exactly - no manual JSON, no hand-roplled mock server, no waiting on the backend.
npx @sukhdevth./ts-mockit ./types/User.ts
export interface User {<br>id: string;<br>name: string;<br>email: string;<br>age: number;
mockit server running at http://localhost:4000
GET /user → 20 fake users<br>GET /user/0 → one fake user
That's it!! Your frontend now has a real endpoint to build against, today.
How it works
ts-mockit uses the TypeScript compiler itself to stastically read your file - the same way tsc does - and walks the actual type graph, not a regex or a guess. Every interface, nested object, array, enum and unions gets reduced to a shape then handed to a data generator that produces realistic values based on both the type and the field name.
interface User {<br>id: string;<br>email: string;<br>age: number;<br>role: "admin" | "editor" | "viewer";<br>// ****<br>"id" : "b21e11d7-ddb0-44ec-ac93-c5e1a4d5ce4a",<br>"email": "brian.sanford@hotmail.com",<br>"age": 34,<br>"role": "editor"
Features
Field-aware generation - a string field named email gets a real-looking email not random words. age gets a sane range. price gets a realistic decimal. The generator reads intent from your field names not just their types.
Full-recursive support - nested objects, array of objects, enums, unions, and dates are all walked correctly, however deep they go.
interface Post {<br>role: "admin" | "editor" | "viewer";<br>address: { street: string; city: string };<br>comments: Comment[];
// all resolved correctly - nested objects stay objs<br>// arrays stay arrays, enum pick a real member
Resolves import across files - if yur type import another type from a different file, ts-mockit follows it automatically, because it uses the real TypeScript type checker, not a single file parser.
import { Address } from "./address";
export interface User {<br>homeAddress: Address; // resolved correctly, from anywhere in your project
Stable data per session - data is generated one when the server starts and cached, so your frontend isnt fighting new random values every refres.
Zero config, zero setup - one command, one file, no config file to write :3
Usage
[options]">npx @sukhdevth./ts-mockit file> [options]
Option<br>Description<br>Default
-p, --port<br>Port to run the server on<br>4000
-c, --count<br>Fake records generated per type<br>20
every exported interface or type in the file become its own route, named after the type(lowercased):
→ all fake records<br>GET //:index → one record by index">GET / → all fake records<br>GET //:index → one record by index
Why not just write JSON by yourself?
You already do the type design work once, In typescript, ts-mockit reads that instead of asking you to describe your data twice once in code, once in a mock file that drifts out of sync with the real types.
License
MIT
About<br>Generate a realistic mock API straight from your TypeScript types - zero config, one command.<br>www.npmjs.com/package/@sukhdevth./ts-mockit<br>Topics<br>apiapi-mockingclideveloper-toolsfakermocktypestypescript<br>Resources<br>Readme<br>MIT license<br>Activity<br>Stars<br>1 star<br>Watchers<br>0 watching<br>Forks<br>0 forks<br>Report repository
Releases
Packages
Contributors
Languages
You can’t perform that action at this time.