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

mockaroo

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mockaroo

Generate data using the mockaroo.com API

  • 0.1.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
369
increased by6.65%
Maintainers
1
Weekly downloads
 
Created
Source

mockaroo-node

A nodejs client for generating data using the rest api from http://mockaroo.com

Installation

npm install mockaroo

Documentation

http://mockaroo.com/api/node/index.html

API Overview

The mockaroo client's generate method returns a promise that resolves to an array of records.

You can either generate data using a schema that you've built and saved on mockaroo.com:

var Mockaroo = require('mockaroo');

var client = new Mockaroo.Client({
    apiKey: 'e93db400' // see http://mockaroo.com/api/docs to get your api key
})

client.generate({
    count: 10,
    schema: 'My Saved Schema'
}).then(function(records) {
    ...
});

Or you can specify fields using the API:

client.generate({
    count: 10,
    fields: [{
        name: 'id',
        type: 'Row Number'
    }, {
        name: 'transactionType',
        type: 'Custom List',
        values: ['credit', 'debit']
    }]
}).then(function(records) {
    // handle response
});

Field types and parameters are documented here

Handling Responses

The Promise returned by client.generate resolves to an array of records when count > 1 and a single object when count == 1. The keys are the names of the fields in your schema. For example:

client.generate({
    count: 10,
    fields: [{
        name: 'id',
        type: 'Row Number'
    }, {
        name: 'transactionType',
        type: 'Custom List',
        values: ['credit', 'debit']
    }]
}).then(function(records) {
    for (var i=0; i<records.length; i++) {
        var record = records[i];
        console.log('record ' + i, 'id:' + record.id + ', transactionType:' + record.transactionType);
    }
});

Errors

This module contains Error classes to help you handle specific error conditions.

client.generate({
    count: 10,
    schema: 'My Saved Schema'
}).then(function(records) {
    // handle successful response here
}).catch(function(error) {
    if (error instanceof Mockaroo.errors.InvalidApiKeyError) {
      console.log('invalid api key');
    } else if (error instanceof Mockaroo.errors.UsageLimitExceededError) {
      console.log('usage limit exceeded');
    } else {
      console.log('unknown error', error);
    }
});

Gulp Tasks

To generate documentation and compile the es6 code to js, use the default gulp task:

gulp

FAQs

Package last updated on 22 Jun 2015

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