Skip to content

Commit

Permalink
Remove whitespace between function keyword and braces throughout code…
Browse files Browse the repository at this point in the history
…base
  • Loading branch information
webroo committed Jul 6, 2020
1 parent 5905ed7 commit 2a956ce
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 242 deletions.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -9,7 +9,7 @@ var dummyjson = {
// Global seed for the random number generator
seed: null,

parse: function (string, options) {
parse: function(string, options) {
options = options || {};

// Merge custom mockdata/helpers into the defaults, items with the same name will override
Expand Down
88 changes: 44 additions & 44 deletions lib/helpers.js
Expand Up @@ -4,8 +4,8 @@ var numbro = require('numbro');
var fecha = require('fecha');
var utils = require('./utils');

// Generating int and floats is very similar so we route both to this single function
function getNumber (type, min, max, format, options) {
// Generating int and floats is very similar so both use this function
function getNumber(type, min, max, format, options) {
var ret;

// Juggle the arguments if the user didn't supply a format string
Expand All @@ -31,8 +31,8 @@ function getNumber (type, min, max, format, options) {
return ret;
}

// Generating time and dates is very similar so we route both to this single function
function getDate (type, min, max, format, options) {
// Generating time and dates is very similar so both use this function
function getDate(type, min, max, format, options) {
var ret;

// Juggle the arguments if the user didn't supply a format string
Expand Down Expand Up @@ -64,7 +64,7 @@ function getDate (type, min, max, format, options) {
return ret;
}

function getFirstName (options) {
function getFirstName(options) {
// The value is cached so that other helpers can use it.
// Each helper is allowed to use the cached value just once.
var cache = options.data.root.__cache;
Expand All @@ -75,7 +75,7 @@ function getFirstName (options) {
return ret;
}

function getLastName (options) {
function getLastName(options) {
// The value is cached so that other helpers can use it.
// Each helper is allowed to use the cached value just once.
var cache = options.data.root.__cache;
Expand All @@ -86,7 +86,7 @@ function getLastName (options) {
return ret;
}

function getCompany (options) {
function getCompany(options) {
// The value is cached so that other helpers can use it.
// Each helper is allowed to use the cached value just once.
var cache = options.data.root.__cache;
Expand All @@ -97,7 +97,7 @@ function getCompany (options) {
return ret;
}

function getTld (options) {
function getTld(options) {
// The value is cached so that other helpers can use it.
// Each helper is allowed to use the cached value just once.
var cache = options.data.root.__cache;
Expand All @@ -109,7 +109,7 @@ function getTld (options) {
}

var helpers = {
repeat: function (min, max, options) {
repeat: function(min, max, options) {
var ret = '';
var total = 0;
var data;
Expand Down Expand Up @@ -166,43 +166,43 @@ var helpers = {
return ret;
},

int: function (min, max, format, options) {
int: function(min, max, format, options) {
if (arguments.length !== 3 && arguments.length !== 4) {
throw new Error('The int helper requires two numeric params, eg: {{int 2 6}}');
}
return getNumber('int', min, max, format, options);
},

float: function (min, max, format, options) {
float: function(min, max, format, options) {
if (arguments.length !== 3 && arguments.length !== 4) {
throw new Error('The float helper requires two numeric params, eg: {{float 5 8}}');
}
return getNumber('float', min, max, format, options);
},

boolean: function () {
boolean: function() {
return utils.randomBoolean().toString();
},

date: function (min, max, format, options) {
date: function(min, max, format, options) {
if (arguments.length !== 3 && arguments.length !== 4) {
throw new Error(`The date helper requires two string params, eg: {{date '2015-01-01' '2015-12-31'}}`);
}
return getDate('date', min, max, format, options);
},

time: function (min, max, format, options) {
time: function(min, max, format, options) {
if (arguments.length !== 3 && arguments.length !== 4) {
throw new Error(`The time helper requires two string params, eg: {{time '09:30' '14:00'}}`);
}
return getDate('time', min, max, format, options);
},

title: function (options) {
title: function(options) {
return utils.randomArrayItem(options.data.root.titles);
},

firstName: function (options) {
firstName: function(options) {
// Try to use the cached values first, otherwise generate a new value
var cache = options.data.root.__cache;
var ret = cache.firstName || getFirstName(options);
Expand All @@ -212,7 +212,7 @@ var helpers = {
return ret;
},

lastName: function (options) {
lastName: function(options) {
// Try to use the cached values first, otherwise generate a new value
var cache = options.data.root.__cache;
var ret = cache.lastName || getLastName(options);
Expand All @@ -222,7 +222,7 @@ var helpers = {
return ret;
},

username: function (options) {
username: function(options) {
// Try to use the cached values first, otherwise generate a new value
var cache = options.data.root.__cache;
var first = cache.username_firstName || getFirstName(options);
Expand All @@ -240,7 +240,7 @@ var helpers = {
sanitize(last).toLowerCase();
},

company: function (options) {
company: function(options) {
// Try to use the cached values first, otherwise generate a new value
var cache = options.data.root.__cache;
var company = cache.company || getCompany(options);
Expand All @@ -250,7 +250,7 @@ var helpers = {
return company;
},

tld: function (options) {
tld: function(options) {
// Try to use the cached values first, otherwise generate a new value
var cache = options.data.root.__cache;
var tld = cache.tld || getTld(options);
Expand All @@ -260,7 +260,7 @@ var helpers = {
return tld;
},

domain: function (options) {
domain: function(options) {
// Try to use the cached values first, otherwise generate a new value
var cache = options.data.root.__cache;
var company = cache.domain_company || getCompany(options);
Expand All @@ -273,7 +273,7 @@ var helpers = {
return company.toLowerCase() + '.' + tld;
},

email: function (options) {
email: function(options) {
// Try to use the cached values first, otherwise generate a new value
var cache = options.data.root.__cache;
var first = cache.email_firstName || getFirstName(options);
Expand All @@ -295,15 +295,15 @@ var helpers = {
'@' + sanitize(company) + '.' + tld;
},

street: function (options) {
street: function(options) {
return utils.randomArrayItem(options.data.root.streets);
},

city: function (options) {
city: function(options) {
return utils.randomArrayItem(options.data.root.cities);
},

country: function (options) {
country: function(options) {
var ret;
var rootData = options.data.root;
var cache = rootData.__cache;
Expand All @@ -322,7 +322,7 @@ var helpers = {
return ret;
},

countryCode: function (options) {
countryCode: function(options) {
var ret;
var rootData = options.data.root;
var cache = rootData.__cache;
Expand All @@ -341,32 +341,32 @@ var helpers = {
return ret;
},

zipcode: function () {
zipcode: function() {
return ('0' + utils.randomInt(1000, 99999).toString()).slice(-5);
},

postcode: function () {
postcode: function() {
return utils.randomChar() + utils.randomChar() + utils.randomInt(0, 9) + ' ' +
utils.randomInt(0, 9) + utils.randomChar() + utils.randomChar();
},

lat: function (options) {
lat: function(options) {
return getNumber('float', -90, 90, '0.000000', options);
},

long: function (options) {
long: function(options) {
return getNumber('float', -180, 180, '0.000000', options);
},

phone: function (format) {
phone: function(format) {
// Provide a default format if one is not given
format = (typeof format === 'string') ? format : 'xxx-xxx-xxxx';
return format.replace(/x/g, function () {
return format.replace(/x/g, function() {
return utils.randomInt(0, 9);
});
},

guid: function () {
guid: function() {
var ret = '';
var i = 0;
var mask = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
Expand All @@ -382,12 +382,12 @@ var helpers = {
return ret;
},

ipv4: function () {
ipv4: function() {
return utils.randomInt(1, 255) + '.' + utils.randomInt(0, 255) + '.' +
utils.randomInt(0, 255) + '.' + utils.randomInt(0, 255);
},

ipv6: function () {
ipv6: function() {
return utils.randomInt(1, 0xffff).toString(16) + ':' +
utils.randomInt(0, 0xffff).toString(16) + ':' +
utils.randomInt(0, 0xffff).toString(16) + ':' +
Expand All @@ -398,11 +398,11 @@ var helpers = {
utils.randomInt(0, 0xffff).toString(16);
},

color: function (options) {
color: function(options) {
return utils.randomArrayItem(options.data.root.colors);
},

hexColor: function (options) {
hexColor: function(options) {
var r = utils.randomInt(0, 0xff);
var g = utils.randomInt(0, 0xff);
var b = utils.randomInt(0, 0xff);
Expand All @@ -420,14 +420,14 @@ var helpers = {
('0' + b.toString(16)).slice(-2);
},

char: function (charset) {
char: function(charset) {
if (arguments.length !== 2 || typeof charset !== 'string') {
throw new Error(`The char helper requires a string param, eg: {{char 'ABC'}}`);
}
return utils.randomChar(charset)
},

lorem: function (totalWords, options) {
lorem: function(totalWords, options) {
var ret = '';
var i, word;
var isNewSentence = true;
Expand Down Expand Up @@ -480,30 +480,30 @@ var helpers = {
return ret;
},

random: function () {
random: function() {
if (arguments.length < 2) {
throw new Error(`The random helper requires at least one param, eg: {{random 'north' 'south'}}`);
}
var arr = Array.prototype.slice.call(arguments, 0, arguments.length - 1);
return utils.randomArrayItem(arr);
},

lowercase: function (value) {
lowercase: function(value) {
return value.toLowerCase();
},

uppercase: function (value) {
uppercase: function(value) {
return value.toUpperCase();
},

add: function (a, b) {
add: function(a, b) {
if (arguments.length !== 3 || typeof a !== 'number' || typeof b !== 'number') {
throw new Error('The add helper requires two number params, eg: {{add 2 4}}');
}
return a + b;
},

step: function (inc, options) {
step: function(inc, options) {
if (arguments.length !== 2 || options.data.index == null) {
throw new Error('The step helper requires a numeric value and can only be used inside #repeat and #each blocks, eg: {{step 10}}');
}
Expand Down
16 changes: 8 additions & 8 deletions lib/utils.js
Expand Up @@ -4,38 +4,38 @@ var seedrandom = require('seedrandom');
var prng = seedrandom();

var utils = {
setRandomSeed: function (seed) {
setRandomSeed: function(seed) {
prng = seedrandom(seed);
},

random: function () {
random: function() {
return prng();
},

randomInt: function (min, max) {
randomInt: function(min, max) {
return Math.floor(utils.random() * (max - min + 1)) + min;
},

randomFloat: function (min, max) {
randomFloat: function(min, max) {
return utils.random() * (max - min) + min;
},

randomBoolean: function () {
randomBoolean: function() {
return utils.random() < 0.5;
},

randomDate: function (min, max) {
randomDate: function(min, max) {
// We add the timezone offset to avoid the date falling outside the supplied range
var d = new Date(Math.floor(utils.random() * (max - min)) + min);
d.setTime(d.getTime() + d.getTimezoneOffset() * 60000);
return d;
},

randomArrayItem: function (array) {
randomArrayItem: function(array) {
return array[utils.randomInt(0, array.length - 1)];
},

randomChar: function (charset) {
randomChar: function(charset) {
charset = charset || 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
return charset.charAt(utils.randomInt(0, charset.length - 1));
}
Expand Down

0 comments on commit 2a956ce

Please sign in to comment.