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

json-generator

v0.3.1

Published

A simple Javascript library used to generate json mocks.

Downloads

72

Readme

Json Generator

A simple library to generate json mocks.

License NPM Version Dependencies DependenciesDev Releases Contributors Issues NPM Downloads

Installing

Use the npm command to install this library into your project:

npm i json-generator --save  

Usage Example

const { generateJson }  = require('json-generator');
console.log(generateJson({
  id: "id;objectId",
  children: [
    5,
    {
      name: "fullName",
      age: "int;0;10"
    }
  ],
  currentJob: {
    title: "Developer",
    salary: "mask;"
  },
  jobs: [
    2,
    {
      title: 'random;["developer", "medic", "teacher", "CEO"]',
      salary: "money"
    }
  ],
  maxRunDistance: "float;1;20;1",
  cpf: "cpf",
  cnpj: "cnpj",
  pretendSalary: "money",
  age: "int;20;80",
  gender: "gender",
  firstName: "firstName",
  lastName: "lastName",
  phone: "maskInt;+55 (83) 9####-####",
  address: "address",
  hairColor: "color"
}));
  
/**  
 * Result:  
{
  id: "603d61c3a948d65e896a9675",
  children: [
    { name: "Riley Kline", age: 6 },
    { name: "Duffy Reed", age: 8 },
    { name: "Chance Alexander", age: 4 },
    { name: "Leslie Ellison", age: 6 },
    { name: "Shiloh Tran", age: 7 }
  ],
  currentJob: { title: "Developer", salary: "R$ 1.4577,25" },
  jobs: [
    { title: "medic", salary: "R$ 3.3749,05" },
    { title: "developer", salary: "R$ 2.1712,49" }
  ],
  maxRunDistance: 6.7,
  cpf: "263.918.428-84",
  cnpj: "87.371.227/0001-21",
  pretendSalary: "R$ 9.5336,56",
  age: 30,
  gender: "male",
  firstName: "Donovan",
  lastName: "Bright",
  phone: "+55 (83) 91770-4875",
  address: "799 Applegate Court - Verdi, Pennsylvania, Niue.",
  hairColor: "black"
};

 */  

You can use the functions separately, to generate resources:

const {
    getId,
    getFullName,
    getInt,
    getMaskInt,
    getFloat,
    getCpf,
    getCnpj,
    getRandom,
    getMoney,
    getGender,
    getFirstName,
    getLastName,
    getAddress,
    getColor
} = require('json-generator');

console.log({
    id: getId('objectId'),
    children: Array.from(Array(5), function () {
        return {
            name: getFullName(),
            age: getInt(0, 10)
        };
    }),
    currentJob: {
        title: "Developer",
        salary: getMoney()
    },
    jobs: Array.from(Array(2), function () {
        return {
            title: getRandom(["developer", "medic", "teacher", "CEO"]),
            salary: getMoney()
        };
    }),
    maxRunDistance: getFloat(1, 20, 1),
    cpf: getCpf(),
    cnpj: getCnpj(),
    pretendSalary: getMoney(),
    age: getInt(20, 80),
    gender: getGender(),
    firstName: getFirstName(),
    lastName: getLastName(),
    phone: getMaskInt('+55 (83) 9####-####'),
    address: getAddress(),
    hairColor: getColor()
});

/**  
 * Result:  
{
  id: "603d61c3a948d65e896a9675",
  children: [
    { name: "Riley Kline", age: 6 },
    { name: "Duffy Reed", age: 8 },
    { name: "Chance Alexander", age: 4 },
    { name: "Leslie Ellison", age: 6 },
    { name: "Shiloh Tran", age: 7 }
  ],
  currentJob: { title: "Developer", salary: "R$ 1.4577,25" },
  jobs: [
    { title: "medic", salary: "R$ 3.3749,05" },
    { title: "developer", salary: "R$ 2.1712,49" }
  ],
  maxRunDistance: 6.7,
  cpf: "263.918.428-84",
  cnpj: "87.371.227/0001-21",
  pretendSalary: "R$ 9.5336,56",
  age: 30,
  gender: "male",
  firstName: "Donovan",
  lastName: "Bright",
  phone: "+55 (83) 91770-4875",
  address: "799 Applegate Court - Verdi, Pennsylvania, Niue.",
  hairColor: "black"
};

 */  

More details in the wiki page as soon as possible.

Future Features

  • ¹A detailed wiki for library usage

License

Distributed under the APACHE License. See LICENSE for more information.

Authors

  • Lucas Rocha - Initial Work. Twitter Facebook LinkedIn Github Instagram