0.0.3 • Published 4 years ago

mockuments v0.0.3

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

Mockuments

Mock JSON Documents with funny defaults.

Formerly Socuments.

carbon

Usage

mockuments ( count, template )

  • count: <Number>the number of mockuments to generate, defaulting to 10.

  • template: <Object>a mockuments template. See templates for more information on creating a custom template.

  • returns: <Array>An array of mockuments.

const mocks = require("mockuments")();

const mocks100 = require("mockuments")(100);

const template = {
  firstName: { type: "name", length: "random" },
  lastName: { type: "name", length: 10 },
  lastLogin: { type: "date" },
  email: { type: "email" },
  loggedIn: { type: "boolean" },
};
const customMocks = require("mockuments")(10, template);

Templates

To use your own template to generate Mockuments, simply supply a template object. Templates require a particular structure, requiring atleast a type field. Mockuments support some custom types along with many of the JS types.

Default template

{
  first: { type: 'name', max: 'rand' },
  middle: { type: 'letter', caps: true },
  last: { type: 'name', max: 'rand' },
  bio: {
    height: { type: 'height', max: 8 },
    age: { type: 'age', max: 100 },
    race: { type: 'race' },
    prey: { type: 'race' },
    bloodtype: { type: "choose", vals: [ "A", "...", "Unknown" ] },
    notes: { type: 'array', length: 'rand', content: 'lorem' }
  },
  contact: {
    onEarth: { type: 'boolean' },
    mobile: { type: 'phone' },
    email: { type: 'email' },
    password: { type: 'base64' },
    uuid: { type: 'uuid' },
    aliases: { type: 'array', length: 'rand', content: 'uuid' }
  },
  lastLogin: { type: 'date' },
  generatedBy: { type: 'passthrough', pass: 'npm:mockuments' }
}