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

mocking_g

v0.2.22

Published

<b>An advanced tool for creating mocked data for server and client.</b>

Downloads

13

Readme

GEN

Intro

In Short

An advanced tool for creating mocked data for server and client.

In Several More Words

A very powerful and flexible framework that allows defining and generating mocked data easily and quickly. The framework is a generic one, and can be extended programmatically with new types. It is used by firstly creating a schema for our data, and then generating as many instances from that schema as needed.

Installation

    npm i mocking_g

Usage

  • Just include the library in your project:

      const gen = require('mocking_g');
  • Mocking GEN UI will run on localhost on port 5588

  • Generate your data like so:

const library = 'examples';
const schema = 'person';
const persons = gen.generate([library,schema], 10);

Or just

const persons = gen.generate('examples.person', 10);

Terminology

  • Library - a logical layer for separation of schemas.
  • Schema - a JSON schema that describes our data. We can create schemas using the UI or programmatically as shown below.
  • Type - Schemas are consisted from types. There are built-in types in the library, but we can define new types as shown below as well.

Examples

An example for a person schema can be something like that:

{
  "uuid": {
    "type": "id"
  },
  "firstName": {
    "type": "firstName"
  },
  "lastName": {
    "type": "lastName"
  },
  "birthDate": {
    "type": "pastDate",
    "value": {
      "dateMask": "DD-MM-YYYY",
      "years": 50
    }
  },
  "country": {
    "type": "country"
  },
  "streetName": {
    "type": "streetName"
  },
  "zipCode": {
    "type": "zipCode"
  },
  "email": {
    "type": "email"
  },
  "company": {
    "type": "company"
  },
  "jobTitle": {
    "type": "jobTitle"
  }
}

While the generated data can be something like this:

{
    "uuid": "7f30a631-12c9-42a1-ad2d-a641b85a5647",
    "firstName": "Scot",
    "lastName": "Goodwin",
    "birthDate": "11-01-2008",
    "country": "Palau",
    "streetName": "O'Connell River",
    "zipCode": "66932-6018",
    "email": "[email protected]",
    "company": "Altenwerth, Waelchi and Ledner",
    "jobTitle": "Lead Markets Analyst"
  }

Features

  • Generate

It is possible to generate data from a schema created programmatically:

const schema = {
    name: { type: 'firstName' },
    age: { type: 'number' }
}

const generated = gen.generate(schema, 10);

Or use the intuitive GEN UI and create schemas effortlessly. Then, just reference the schema and generate your data:

gen.generate('examples.person', 10);

You can set the path on which GEN will save your schemas. In addition, GEN will use this path to load the schemas on startup.

gen.schemas.setPath('C:/your/path/to/folder');
  • Types

Get existing types by:

gen.types.getTypes()

Or

gen.types.getTypesArrangeByGroups() // types belong in a "group"

You can also create your own types programmatically:

const myRandomNumberType = {
    randomNumber: {
        name: "Random Number",
        generate: (element) => {
            return Math.random();
        },
        group: 'new group'
    }
}

gen.types.addTypes(myRandomNumberType);
  • Libraries

As explained earlier, libraries are just logical layers that can contain your schemas. GEN supports various CRUD operations on libraries, few of them are:

gen.schemas.getAllLibraries();
gen.schemas.removeLibrary(libraryName);
gen.schemas.addLibrary(libraryName);

CLIENT usage

  • Use a standard get request
axios.get('http://localhost:5588/mocking_G/generate', { library: 'examples', category: 'person', amount: 5 }).then((res)=>{
    console.log(res.data);
})

Or directly from a url

http://localhost:5588/mocking_G/generate?library=examples&category=person&amount=3

Coming soon

  • Docs and improvements