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 - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

test/client.js

70

lib/client.js

@@ -105,14 +105,10 @@ 'use strict';

if (!options || !options.schema && !options.fields) throw 'Either fields or schema option must be specified';
if (!options || !options.schema && !options.fields) throw new Error('Either fields or schema option must be specified');
options = Object.assign({ count: 1 }, options);
this.validateFields(options.fields);
var protocol = this.secure ? 'https' : 'http';
var port = this.port ? ':' + this.port : '';
var url = protocol + '://' + this.host + port + '/api/generate.json?key=' + encodeURIComponent(this.apiKey) + '&count=' + options.count;
var url = this.getUrl(options);
console.log('url', url);
return new Promise(function (resolve, reject) {
_axios2['default'].post(url, JSON.stringify(options.fields)).then(function (resp) {
_axios2['default'].post(url, options.fields ? JSON.stringify(options.fields) : null).then(function (resp) {
return resolve(resp.data);

@@ -125,2 +121,57 @@ })['catch'](function (resp) {

}, {
key: 'validateFields',
/**
* @private
* @param {Object[]} fields
*/
value: function validateFields(fields) {
if (!fields) return;
if (fields instanceof Array) {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = fields[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var field = _step.value;
if (!field.name) throw new Error('each field must have a name');
if (!field.type) throw new Error('each field must have a type');
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator['return']) {
_iterator['return']();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
} else {
throw new Error('fields must be an array');
}
}
}, {
key: 'getUrl',
/**
* Generates the rest api url
* @private
* @return {String}
*/
value: function getUrl(options) {
options = Object.assign({ count: 1 }, options);
var protocol = this.secure ? 'https' : 'http';
var port = this.port ? ':' + this.port : '';
var schema = options.schema ? '&schema=' + options.schema : '';
return protocol + '://' + this.host + port + '/api/generate.json?key=' + encodeURIComponent(this.apiKey) + '&count=' + options.count + schema;
}
}, {
key: 'convertError',

@@ -133,3 +184,2 @@

value: function convertError(response) {
console.log(response);
var error = response.data.error;

@@ -153,3 +203,3 @@

value: function validate() {
if (!this.apiKey) throw 'apiKey is required';
if (!this.apiKey) throw new Error('apiKey is required');
}

@@ -156,0 +206,0 @@ }]);

7

package.json
{
"name": "mockaroo",
"version": "0.1.2",
"version": "0.1.3",
"description": "Generate data using the mockaroo.com API",

@@ -18,2 +18,3 @@ "main": "lib/mockaroo.js",

"devDependencies": {
"chai": "^3.0.0",
"esdoc": "^0.1.2",

@@ -24,4 +25,6 @@ "gulp": "^3.9.0",

"gulp-run": "^1.6.8",
"gulp-util": "^3.0.5"
"gulp-util": "^3.0.5",
"mocha": "^2.2.5",
"nock": "^2.6.0"
}
}

@@ -11,3 +11,3 @@ # mockaroo-node

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

@@ -14,0 +14,0 @@ # API Overview

Sorry, the diff of this file is not supported yet

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