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

mockeye

v1.1.1

Published

A node package for generating JSON of mock structured data

Downloads

4

Readme

mockeye

A node package for generating JSON of mock structured data

about

This package is made for generating fake data for testing and other development purposes. There are methods for writing the mock data into a JSON file or returning it as a Javascript Object or Array for use in your application.

installation

npm install mockeye

types

type names

The library includes type names, which are specific strings. Some type names include:

"firstName","lastName","date","id"....

A full list of the available type names appears in the 'type names list' section further below.

The type names are also available at: mockeye.types

Using the mockeye.types object allows autofill on an editor, so it is the best way of avoiding spelling errors. Additionally, you may not have to look up the documentation for the name.

typeSchema

You can use these type names to create a schema. A schema would look like the following

{
  name:{
    first:"firstName",
    last:"lastName"
    },
  birthdate:"date",
  email:"email"
}

when the mock data is generated all the strings are replaced with a piece of data of that type, i.e. "firstName" is replaced with "Gregory." The mock data generated with the above schema might look like this:

{
  name:{
    first:"Clarice",
    last:"DeNeuve"
    },
  birthdate:"3/13/1985",
  email:"[email protected]"
}

arrays

Schemas can also be or contain arrays. When an array is in a schema, array[0] is a typename (or a nested type schema), and array[1] is the number of elements.

for example, the schema

["year",4]

would yield an array like

[2000,2003,1979,2017]

String Templates

Schemas can also use templates for string values. To use, make an object like so:

{
  template:true,
  typesArray:[<typeNamesListedHere>],
  string:<string here>}

Within the string, "" will be replaced with a value of the type.

For example:

{template:true,
typesArray:["city","firstName","lastName"]
template:"My name is *1* *2*, and I live in *0*. That's why I am called *0* *1*."
}

Would produce:

"My name is Jane Seymour, and I live in Tallahassee. That's why I am called Tallahassee Jane."

methods

There are two main methods for the package: fake and write.

mockeye.fake()

mockeye.fake takes a typeSchema or a typeName as an argument, and returns mock data that fits that schema.

For instance

const schema = [{workEmail:"email",workZipCode:"zipcode"},2]
const mockData = mockeye.fake(schema)
console.log(mockData)

would log out

[
  {
    workEmail:"[email protected]"
    workZipCode:43829
  },
  {
    workEmail:"[email protected]"
    workZipCode:22245
  }
]

mockeye.write()

mockeye.write takes in (path,typeSchema) in as arguments. The path is to where the file is written. The typeSchema is either a typename or a schema (this is the same as the first argument of the fake method).

The mockeye.write() method does not return anything, but rather converts the mock data into JSON and saves that JSON at the specified path.

A correct usage would look like

const schema = [{workEmail:"email",workZipCode:"zipcode"},2]
mockeye.write("../mockdata/employeeData.json",schema)

type names list

Below are the current type names. When the list reaches a certain length, I'll create a web page that will contain this list.

  • "firstName"
  • "lastName"
  • "email"
  • "phone"
  • "tf" (true or false)
  • "url"
  • "date"
  • "timeStamp"
  • "year"
  • "month"
  • "day"
  • "dayOfWeek"
  • "zipCode"
  • "zipCodeFull"
  • "fileName"
  • "extension"
  • "string"
  • "number"
  • "id"
  • "paragraph"

licensing

MIT