npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

monke-mock

v1.0.5

Published

Simple and fast mock data generator with great TS support

Downloads

4

Readme

Monke mock

A fast mock data generator with a great typescript support and no 3rd party dependencies.

Introduction

I could not find any cool package for quickly creating a mock schema of objects and arrays for my unit tests or just to populate site with random data. That is why I decided to create my own version of it.

Benefits of using monke-mock

While faker.js provides an excellent generator for data like emails, names, etc. it is not suitable for generating developer-defined shapes of data. Let's say that you want to have an array of objects for testing purposes. While it is possible, but not straightforward to accomplish using the faker.js, it is extremely easy with monke-mock.

Faker way:

const arr = [];
for(let i = 0; i < 100; i++){
    arr.push({
        x: faker.datatype.number()
    });
}

Monke-mock way:

const data = Marray(MObject({x: Mnum()})).Length(100).generate();

Getting started

Install with:

npm install monke-mock
yarn add monke-mock

Currently monke-mock supports following data types:

  • number - Mnum
  • string - Mstring
  • object - Mobject
  • array - Marray
  • Date - Mdate

| Data type | Function | Available modifiers| |-----------|----------|--------------------| | number | Mnum | Max(), Min(), IsInt()| | string | Mstring | Length(), UseNumbers()| | date | Mdate | Max(), Min()| | object | Mobject | | | array | Marray | Length() |

Examples

Generating a number

import { Mnum } from 'monke-mock';

const x = Mnum().generate();

You can also specify Min and Max values:

import { Mnum } from 'monke-mock';

const x = Mnum().Min(21).Max(37).generate();

Generating a negative number

import { Mnum } from 'monke-mock';

const x = Mnum().Min(-100).Max(0).generate();

Generating an array of strings

import { Marray, Mstring } from 'monke-mock';

const x = Marray(Mstring()).generate();

Generating an object with one key always equal to 1

import { Mobject, Mstring } from 'monke-mock';

const x = Mobject({fixedKey: 1, someRandomString: Mstring()}).generate();

Creating a custom generator

import { Mcustom, Marray, IMockGenerator } from 'monke-mock';


// First define a class that implements the IMockGenerator
class ACustomGenerator implements IMockGenerator<number> {
    
    // the generate() function should implement the algorithm that returns the random data 
    generate(): number {
        return Date.now() % 2 ? 1 : -1;
    }
}

// Then use the `Mcustom` function to wrap the class
const x = Marray(Mcustom(ACustomGenerator));