1.1.0 • Published 4 years ago

data-mocker-cli v1.1.0

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

data-mocker-cli

CI Version Downloads/week License codecov

Summary

Cli to generate a test data set, with it you can generate any flat data structure, being able to specify the type of each field or attribute.

With it you can generate thousands of test data

Usage

$ npm install -g data-mocker-cli
$ dmcli COMMAND
running command...
$ dmcli (-v|--version|version)
data-mocker-cli/1.1.0 linux-x64 node-v12.18.1
$ dmcli --help [COMMAND]
USAGE
  $ dmcli COMMAND
...

Commands

dmcli generate NUMBER

Generate a file with mock data in json, csv or sql insert format

USAGE
  $ dmcli generate NUMBER

ARGUMENTS
  NUMBER  Number of mock data

OPTIONS
  -h, --help                 show CLI help
  -o, --output=sql|json|csv  [default: json] Output file format
  -s, --schema=schema        (required) Schema of the data to be generated

See code: src/commands/generate.ts

dmcli help [COMMAND]

display help for dmcli

USAGE
  $ dmcli help [COMMAND]

ARGUMENTS
  COMMAND  command to show help for

OPTIONS
  --all  see all commands in CLI

See code: @oclif/plugin-help

Schema file

The schema file is a json that contains a list of the fields that each data must have.

If you want to export in sql format, you can report the name of the table within the schema.json

{
  "tableName": "people",
  "nameFormatter": "LowerSnakeCase",
  "fields": [
    {
      "type": "Number",
      "name": "Id",
      "isNullable": false,
      "min": 1
    },
    {
      "type": "Name",
      "name": "First Name"
    },
    {
      "type": "Surname",
      "name": "last name 2",
      "isNullable": true
    },
    {
      "type": "Enum",
      "name": "Gender",
      "isNullable": true,
      "source": ["Female", "Male", "Non-binary"]
    },
    {
      "type": "Phone",
      "name": "Mobile",
      "prefix": "+34",
      "pattern": "6dd dd dd dd"
    },
    {
      "type": "Email",
      "name": "Email",
      "userNames": ["gunmer", "ironMan", "spiderman"],
      "domains": ["private.es"]
    },
    {
      "type": "String",
      "name": "Description",
      "min": 25,
      "max": 100
    }
  ]
}

NameFormatters

With this property you set the style of the name of the columns or attributes. If not reported by default it is LowerCamelCase

NameFormattersFormats
UpperCamelCase'lorem ipsum' formats as 'LoremIpsum'
LowerCamelCase'lorem ipsum' formats as 'loremIpsum'
UpperSnakeCase'lorem ipsum' formats as 'Lorem_Ipsum'
LowerSnakeCase'lorem ipsum' formats as 'lorem_ipsum'
UpperKebabCase'lorem ipsum' formats as 'Lorem-Ipsum'
LowerKebabCase'lorem ipsum' formats as 'lorem-ipsum'
WithoutFormat'lorem ipsum' formats as 'lorem ipsum'

Common attributes

All fields contain the following attributes:

AttributeDescriptionRequiredDefault
typeIndicates the type of the field, if it is a name, surname, number, etc...Yes
nameName of the field with which the data will be createdYes
isNullableIf true 25% of data contains an undefined value in the fieldNofalse

Field types

String

Generates a text string (lorem ipsum) up to the maximum number of characters indicated

AttributeDescriptionRequired
maxIndicates the maximum value of the stringYes
minIndicates the minimum length range valueNo

Number

Generate integers

AttributeDescriptionRequiredDefault
minMinimum valueFalse−9007199254740991
maxMaximum valueFalse9007199254740991

Enum

Randomly choose a value from the reported source

AttributeDescriptionRequired
sourceArray of options to chooseYes

Name

Generate a random name

AttributeDescriptionRequired
sourceArray of names to choose fromFalse

Surname

Generate a random surname

AttributeDescriptionRequired
sourceArray of surnames to choose fromFalse

Email

Generate a random email with default or specific username and domain

AttributeDescriptionRequired
userNamesArray of usernames to choose fromFalse
domainsArray of domains to choose fromFalse

Phone

Generate a random phone number with a pattern and prefix if needed

AttributeDescriptionRequiredDefault
prefixSet the prefix numberFalseEmpty
patternSet the patter with 'd' of phone numberFalseddddddddd
1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.4.0

4 years ago

0.3.2

4 years ago

0.3.0

4 years ago

0.3.1

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago