Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tanhauhau/mock.macro
🎣static type to mock data
https://github.com/tanhauhau/mock.macro
Last synced: 21 days ago
JSON representation
🎣static type to mock data
- Host: GitHub
- URL: https://github.com/tanhauhau/mock.macro
- Owner: tanhauhau
- Created: 2019-09-30T14:28:48.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T22:20:17.000Z (almost 2 years ago)
- Last Synced: 2024-08-08T18:37:32.050Z (3 months ago)
- Language: JavaScript
- Size: 352 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# mock.macro
> Welcome! This project is mainly used to demonstrate [how to create a babel macro](https://lihautan.com/babel-macros/). Of course if you think this project may help you or if you have idea to make it better, [let's talk about it](https://twitter.com/lihautan)!
this is a macro (read about [babel-plugin-macros](https://github.com/kentcdodds/babel-plugin-macros) if you are not familiar) to generate mock data using type system.
## Example Usage
```js
// @flow
import type { mock } from 'mock.macro';async function foo(): mock<{ id: number, name: string }> {
// TODO: implement
return fetch('api/not/ready');
}// somewhere else
const response = await foo();
console.log(response);
/* { id: 4916, name: 'Sausages' } */
```## Prior Art
[Manta Style](https://github.com/Cryrivers/manta-style) - Mock server that converts type definitions into mock data