https://github.com/djobbo/mokap
Data mocking module for JS and TS
https://github.com/djobbo/mokap
data-mocking
Last synced: about 1 year ago
JSON representation
Data mocking module for JS and TS
- Host: GitHub
- URL: https://github.com/djobbo/mokap
- Owner: djobbo
- Created: 2020-09-18T17:31:41.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-07-03T19:41:36.000Z (almost 5 years ago)
- Last Synced: 2025-01-25T12:43:08.732Z (over 1 year ago)
- Topics: data-mocking
- Language: TypeScript
- Homepage:
- Size: 719 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Mokap
Data mocking made fun
> **Disclaimer**
> NPM package isn't up to date
> Documentation is still being written
> Tests only cover a very small percentage of the code
## Installation
install via npm
`$ npm install --save mokapjs`
or yarn
`$ yarn add mokapjs`
## Branches
### Boolean
```ts
import { bool } from 'mokapjs';
const randomBool = mock(bool);
```
### Number
```ts
import { num } from 'mokapjs';
// Will generate a number between 2 and 5
const numGen = num(2, 5);
const randomNum = mock(numGen); // e.g: 3
// Generators are reusable
const randomNum2 = mock(numGen); // e.g: 5
```
You can also generate bounds programmatically
```ts
import { num } from 'mokapjs';
const minGen = num(1, 3);
const maxGen = num(10, 15);
// Will generate a number between randomly generated min & max
const numGen = num(minGen, maxGen);
const randomNum = mock(numGen); // e.g: 4
```
### String
> Utility to mock strings using regular expressions
```ts
import { str } from 'mokapjs';
const strGen = str(/[A-Z][0-9]/);
const randomStr = mock(strGen); // e.g: "D3"
const randomStr2 = mock(strGen); // e.g: "H5"
```
### Array
```ts
import { arr } from 'mokapjs';
const arrGen = arr();
```