Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mockdata-generator

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mockdata-generator

Collection of data generators to create complex data structures and any number of records

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Generator

A library of mock data object generator. Allows developers and users to define real life looking mock data.

Installation

npm install generator --save-dev

Usage

The following is a complete program that generates 10 records of data

/**
 * This program runs inside a YUI instance.
 * This is not a requisite for using the *mockdata-generator*.
 * In the first line of code require provides an instance to YUI and a closure for the rest of the code.
 **/

require('mockdata-generator/node_modules/yui').YUI().use(function (Y) {
    "use strict";

    var Generator,
        meta,
        gen;

    /**
     * This will get the constructor of the main class
     * The constructor accepts a configuration object with these properties
     * 'name': An optional name of the record
     * 'metadata': An array of descriptions for each of the attributes of the object
     **/
    Generator = require('mockdata-generator').Generator;

    meta = {
        'name': 'Mockdata test set',
        'metadata': [
            {
                'columnName': 'accountOwner',
                'dataType': 'Name',
                'order': 'fl'
            },
            {
                'columnName': 'days',
                'dataType': 'Integer',
                'min': 10,
                'max': 30
            },
            {
                'columnName': 'accountName',
                'dataType': 'String',
                'min': 6,
                'max': 30
            },
            {
                'columnName': 'accountNumber',
                'dataType': 'Pattern',
                'pattern': '###-AA-###-aaa-####'
            },
            {
                'columnName': 'beneficiaryContact',
                'dataType': 'Name',
                'order': 'lf'
            },
            {
                'columnName': 'balance',
                'dataType': 'Currency',
                'min': 50,
                'max': 1000
            },
            {
                'columnName': 'txDate',
                'dataType': 'Date',
                'min': 10,
                'max': 30
            },
            {
                'columnName': 'description',
                'dataType': 'Ipsum',
                'paragraphNum': 1,
                'wordMin': 10,
                'wordMax': 30
            },
            {
                'columnName': 'beneficiary',
                'dataType': 'OneOfList',
                'listName': 'ListBase.Beneficiaries',
                'mode': 'sequence',
                'index': 0
            },
            {
                'columnName': 'categoryName',
                'dataType': 'OneOfList',
                'list': ['A', 'B', 'C', 'D', 'E', 'F'],
                'mode': 'shuffle'
            }
        ]
    };

    gen = new Generator(meta);
    Y.log(gen.getValue(10));
});

Available dataTypes

mockdata-generator provides a way to generate data in the following dataTypes

  • Base
  • Array
  • Currency
  • Date
  • Guid
  • Integer
  • Ipsum
  • Markup
  • Name
  • Number
  • Object
  • One Of List
  • Pattern
  • String

Base

The base clase for all the other generators. It implements several attributes and methods. Base is not used to generate data and it provides all the common functionality for the other data types

AttributeDescription
columnNameIdentifies the attribute inside the object. It must be unique for the object
dataTypeThe data type of the attribute. Any of the names in the dataType list above
minThe minimum value of a range. Not all the data types require a min
maxThe maximum value of a range. Not all the data types require a max

Array

An Array datatype will generate a number of values in the range of (min, max).

AttributeDescription
metadataAn array of data descriptors
minThe minimum number of values to generate
maxThe maximum number of values to generate

Currency

Generates a random numeric value in the (min, max) range, assign one of the listed currencies and generates an object with three attributes: currency, value and formatted value, for instance

{
    currency: 'MXN',
    value: 943.9473666250706,
    formatted: '943.95 MXN'
}
AttributeDescription
currencyCodeA list of the currencies to select. The default value is ['AUD', 'CAD', 'CHF', 'DKK', 'EUR', 'GBP', 'HKD', 'JPY', 'MXN', 'NZD', 'PHP', 'SEK', 'SGD', 'THB', 'USD', 'ZAR']
decimalPlacesNumber of decimal places, default 2
decimalSeparatorCharacter to separate decimal fractions. Default "."
thousandsSeparatorCharacter to separate thousands. Default ","
minThe minimum value in range
maxThe maximum value in range

Date

Guid

Integer

Ipsum

Markup

Name

Number

Object

One Of List

Pattern

String

Release History

  • 0.1.0 Initial Release

Keywords

FAQs

Package last updated on 12 Aug 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc