aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorShinigami <[email protected]>2022-01-11 20:06:46 +0100
committerGitHub <[email protected]>2022-01-11 14:06:46 -0500
commitd4c295f698ed256cb6c53ea77249e64b544ca8c0 (patch)
treedb0b9e33d8a5d4ddbb0b8e9a0139955b444f2cbb /lib
parentee666cd2f6cded87b4f4e366e2c661fcd5253a72 (diff)
downloadfaker-d4c295f698ed256cb6c53ea77249e64b544ca8c0.tar.xz
faker-d4c295f698ed256cb6c53ea77249e64b544ca8c0.zip
chore: format lib without locales (#66)
Diffstat (limited to 'lib')
-rw-r--r--lib/address.js216
-rw-r--r--lib/animal.js46
-rw-r--r--lib/commerce.js51
-rw-r--r--lib/company.js39
-rw-r--r--lib/database.js18
-rw-r--r--lib/datatype.js503
-rw-r--r--lib/date.js40
-rw-r--r--lib/fake.js27
-rw-r--r--lib/finance.js331
-rw-r--r--lib/git.js44
-rw-r--r--lib/hacker.js9
-rw-r--r--lib/helpers.js535
-rw-r--r--lib/iban.js1355
-rw-r--r--lib/image.js47
-rw-r--r--lib/image_providers/lorempicsum.js192
-rw-r--r--lib/image_providers/lorempixel.js84
-rw-r--r--lib/image_providers/unsplash.js42
-rw-r--r--lib/index.js159
-rw-r--r--lib/internet.js331
-rw-r--r--lib/lorem.js60
-rw-r--r--lib/mersenne.js29
-rw-r--r--lib/music.js14
-rw-r--r--lib/name.js100
-rw-r--r--lib/phone_number.js7
-rw-r--r--lib/random.js158
-rw-r--r--lib/system.js66
-rw-r--r--lib/time.js14
-rw-r--r--lib/unique.js9
-rw-r--r--lib/vehicle.js78
-rw-r--r--lib/word.js2
30 files changed, 2684 insertions, 1922 deletions
diff --git a/lib/address.js b/lib/address.js
index 2bd883c4..8d4232e7 100644
--- a/lib/address.js
+++ b/lib/address.js
@@ -2,7 +2,7 @@
*
* @namespace faker.address
*/
-function Address (faker) {
+function Address(faker) {
var f = faker.fake,
Helpers = faker.helpers;
@@ -13,7 +13,7 @@ function Address (faker) {
* @method faker.address.zipCode
* @param {String} format
*/
- this.zipCode = function(format) {
+ this.zipCode = function (format) {
// if zip format is not specified, use the zip format defined for the locale
if (typeof format === 'undefined') {
var localeFormat = faker.definitions.address.postcode;
@@ -24,7 +24,7 @@ function Address (faker) {
}
}
return Helpers.replaceSymbols(format);
- }
+ };
/**
* Generates random zipcode from state abbreviation. If state abbreviation is
@@ -42,7 +42,7 @@ function Address (faker) {
return faker.datatype.number(zipRange);
}
return faker.address.zipCode();
- }
+ };
/**
* Generates a random localized city name. The format string can contain any
@@ -65,20 +65,19 @@ function Address (faker) {
'{{address.cityPrefix}} {{name.firstName}}{{address.citySuffix}}',
'{{address.cityPrefix}} {{name.firstName}}',
'{{name.firstName}}{{address.citySuffix}}',
- '{{name.lastName}}{{address.citySuffix}}'
+ '{{name.lastName}}{{address.citySuffix}}',
];
if (!format && faker.definitions.address.city_name) {
formats.push('{{address.cityName}}');
}
- if (typeof format !== "number") {
+ if (typeof format !== 'number') {
format = faker.datatype.number(formats.length - 1);
}
return f(formats[format]);
-
- }
+ };
/**
* Return a random localized city prefix
@@ -86,7 +85,7 @@ function Address (faker) {
*/
this.cityPrefix = function () {
return faker.random.arrayElement(faker.definitions.address.city_prefix);
- }
+ };
/**
* Return a random localized city suffix
@@ -95,16 +94,16 @@ function Address (faker) {
*/
this.citySuffix = function () {
return faker.random.arrayElement(faker.definitions.address.city_suffix);
- }
+ };
/**
* Returns a random city name
- *
+ *
* @method faker.address.cityName
*/
- this.cityName = function() {
+ this.cityName = function () {
return faker.random.arrayElement(faker.definitions.address.city_name);
- }
+ };
/**
* Returns a random localized street name
@@ -114,8 +113,8 @@ function Address (faker) {
this.streetName = function () {
var result;
var suffix = faker.address.streetSuffix();
- if (suffix !== "") {
- suffix = " " + suffix
+ if (suffix !== '') {
+ suffix = ' ' + suffix;
}
switch (faker.datatype.number(1)) {
@@ -127,7 +126,7 @@ function Address (faker) {
break;
}
return result;
- }
+ };
//
// TODO: change all these methods that accept a boolean to instead accept an options hash.
@@ -139,21 +138,34 @@ function Address (faker) {
* @param {Boolean} useFullAddress
*/
this.streetAddress = function (useFullAddress) {
- if (useFullAddress === undefined) { useFullAddress = false; }
- var address = "";
+ if (useFullAddress === undefined) {
+ useFullAddress = false;
+ }
+ var address = '';
switch (faker.datatype.number(2)) {
case 0:
- address = Helpers.replaceSymbolWithNumber("#####") + " " + faker.address.streetName();
+ address =
+ Helpers.replaceSymbolWithNumber('#####') +
+ ' ' +
+ faker.address.streetName();
break;
case 1:
- address = Helpers.replaceSymbolWithNumber("####") + " " + faker.address.streetName();
+ address =
+ Helpers.replaceSymbolWithNumber('####') +
+ ' ' +
+ faker.address.streetName();
break;
case 2:
- address = Helpers.replaceSymbolWithNumber("###") + " " + faker.address.streetName();
+ address =
+ Helpers.replaceSymbolWithNumber('###') +
+ ' ' +
+ faker.address.streetName();
break;
}
- return useFullAddress ? (address + " " + faker.address.secondaryAddress()) : address;
- }
+ return useFullAddress
+ ? address + ' ' + faker.address.secondaryAddress()
+ : address;
+ };
/**
* streetSuffix
@@ -162,7 +174,7 @@ function Address (faker) {
*/
this.streetSuffix = function () {
return faker.random.arrayElement(faker.definitions.address.street_suffix);
- }
+ };
/**
* streetPrefix
@@ -171,7 +183,7 @@ function Address (faker) {
*/
this.streetPrefix = function () {
return faker.random.arrayElement(faker.definitions.address.street_prefix);
- }
+ };
/**
* secondaryAddress
@@ -179,13 +191,10 @@ function Address (faker) {
* @method faker.address.secondaryAddress
*/
this.secondaryAddress = function () {
- return Helpers.replaceSymbolWithNumber(faker.random.arrayElement(
- [
- 'Apt. ###',
- 'Suite ###'
- ]
- ));
- }
+ return Helpers.replaceSymbolWithNumber(
+ faker.random.arrayElement(['Apt. ###', 'Suite ###'])
+ );
+ };
/**
* county
@@ -194,7 +203,7 @@ function Address (faker) {
*/
this.county = function () {
return faker.random.arrayElement(faker.definitions.address.county);
- }
+ };
/**
* country
@@ -203,7 +212,7 @@ function Address (faker) {
*/
this.country = function () {
return faker.random.arrayElement(faker.definitions.address.country);
- }
+ };
/**
* countryCode
@@ -212,18 +221,18 @@ function Address (faker) {
* @param {string} alphaCode default alpha-2
*/
this.countryCode = function (alphaCode) {
-
if (typeof alphaCode === 'undefined' || alphaCode === 'alpha-2') {
return faker.random.arrayElement(faker.definitions.address.country_code);
}
if (alphaCode === 'alpha-3') {
- return faker.random.arrayElement(faker.definitions.address.country_code_alpha_3);
+ return faker.random.arrayElement(
+ faker.definitions.address.country_code_alpha_3
+ );
}
-
- return faker.random.arrayElement(faker.definitions.address.country_code);
- }
+ return faker.random.arrayElement(faker.definitions.address.country_code);
+ };
/**
* state
@@ -233,7 +242,7 @@ function Address (faker) {
*/
this.state = function (useAbbr) {
return faker.random.arrayElement(faker.definitions.address.state);
- }
+ };
/**
* stateAbbr
@@ -242,7 +251,7 @@ function Address (faker) {
*/
this.stateAbbr = function () {
return faker.random.arrayElement(faker.definitions.address.state_abbr);
- }
+ };
/**
* latitude
@@ -253,16 +262,18 @@ function Address (faker) {
* @param {number} precision default is 4
*/
this.latitude = function (max, min, precision) {
- max = max || 90
- min = min || -90
- precision = precision || 4
-
- return faker.datatype.number({
- max: max,
- min: min,
- precision: parseFloat((0.0).toPrecision(precision) + '1')
- }).toFixed(precision);
- }
+ max = max || 90;
+ min = min || -90;
+ precision = precision || 4;
+
+ return faker.datatype
+ .number({
+ max: max,
+ min: min,
+ precision: parseFloat((0.0).toPrecision(precision) + '1'),
+ })
+ .toFixed(precision);
+ };
/**
* longitude
@@ -273,16 +284,18 @@ function Address (faker) {
* @param {number} precision default is 4
*/
this.longitude = function (max, min, precision) {
- max = max || 180
- min = min || -180
- precision = precision || 4
-
- return faker.datatype.number({
- max: max,
- min: min,
- precision: parseFloat((0.0).toPrecision(precision) + '1')
- }).toFixed(precision);
- }
+ max = max || 180;
+ min = min || -180;
+ precision = precision || 4;
+
+ return faker.datatype
+ .number({
+ max: max,
+ min: min,
+ precision: parseFloat((0.0).toPrecision(precision) + '1'),
+ })
+ .toFixed(precision);
+ };
/**
* direction
@@ -295,11 +308,12 @@ function Address (faker) {
return faker.random.arrayElement(faker.definitions.address.direction);
}
return faker.random.arrayElement(faker.definitions.address.direction_abbr);
- }
+ };
this.direction.schema = {
- "description": "Generates a direction. Use optional useAbbr bool to return abbreviation",
- "sampleResults": ["Northwest", "South", "SW", "E"]
+ description:
+ 'Generates a direction. Use optional useAbbr bool to return abbreviation',
+ sampleResults: ['Northwest', 'South', 'SW', 'E'],
};
/**
@@ -310,18 +324,19 @@ function Address (faker) {
*/
this.cardinalDirection = function (useAbbr) {
if (typeof useAbbr === 'undefined' || useAbbr === false) {
- return (
- faker.random.arrayElement(faker.definitions.address.direction.slice(0, 4))
+ return faker.random.arrayElement(
+ faker.definitions.address.direction.slice(0, 4)
);
}
- return (
- faker.random.arrayElement(faker.definitions.address.direction_abbr.slice(0, 4))
+ return faker.random.arrayElement(
+ faker.definitions.address.direction_abbr.slice(0, 4)
);
- }
+ };
this.cardinalDirection.schema = {
- "description": "Generates a cardinal direction. Use optional useAbbr boolean to return abbreviation",
- "sampleResults": ["North", "South", "E", "W"]
+ description:
+ 'Generates a cardinal direction. Use optional useAbbr boolean to return abbreviation',
+ sampleResults: ['North', 'South', 'E', 'W'],
};
/**
@@ -332,29 +347,30 @@ function Address (faker) {
*/
this.ordinalDirection = function (useAbbr) {
if (typeof useAbbr === 'undefined' || useAbbr === false) {
- return (
- faker.random.arrayElement(faker.definitions.address.direction.slice(4, 8))
+ return faker.random.arrayElement(
+ faker.definitions.address.direction.slice(4, 8)
);
}
- return (
- faker.random.arrayElement(faker.definitions.address.direction_abbr.slice(4, 8))
+ return faker.random.arrayElement(
+ faker.definitions.address.direction_abbr.slice(4, 8)
);
- }
+ };
this.ordinalDirection.schema = {
- "description": "Generates an ordinal direction. Use optional useAbbr boolean to return abbreviation",
- "sampleResults": ["Northwest", "Southeast", "SW", "NE"]
+ description:
+ 'Generates an ordinal direction. Use optional useAbbr boolean to return abbreviation',
+ sampleResults: ['Northwest', 'Southeast', 'SW', 'NE'],
};
- this.nearbyGPSCoordinate = function(coordinate, radius, isMetric) {
+ this.nearbyGPSCoordinate = function (coordinate, radius, isMetric) {
function randomFloat(min, max) {
- return Math.random() * (max-min) + min;
+ return Math.random() * (max - min) + min;
}
function degreesToRadians(degrees) {
- return degrees * (Math.PI/180.0);
+ return degrees * (Math.PI / 180.0);
}
function radiansToDegrees(radians) {
- return radians * (180.0/Math.PI);
+ return radians * (180.0 / Math.PI);
}
function kilometersToMiles(miles) {
return miles * 0.621371;
@@ -366,12 +382,17 @@ function Address (faker) {
var lat1 = degreesToRadians(coordinate[0]); //Current lat point converted to radians
var lon1 = degreesToRadians(coordinate[1]); //Current long point converted to radians
- var lat2 = Math.asin(Math.sin(lat1) * Math.cos(d/R) +
- Math.cos(lat1) * Math.sin(d/R) * Math.cos(bearing));
+ var lat2 = Math.asin(
+ Math.sin(lat1) * Math.cos(d / R) +
+ Math.cos(lat1) * Math.sin(d / R) * Math.cos(bearing)
+ );
- var lon2 = lon1 + Math.atan2(
- Math.sin(bearing) * Math.sin(d/R) * Math.cos(lat1),
- Math.cos(d/R) - Math.sin(lat1) * Math.sin(lat2));
+ var lon2 =
+ lon1 +
+ Math.atan2(
+ Math.sin(bearing) * Math.sin(d / R) * Math.cos(lat1),
+ Math.cos(d / R) - Math.sin(lat1) * Math.sin(lat2)
+ );
// Keep longitude in range [-180, 180]
if (lon2 > degreesToRadians(180)) {
@@ -385,7 +406,7 @@ function Address (faker) {
// If there is no coordinate, the best we can do is return a random GPS coordinate.
if (coordinate === undefined) {
- return [faker.address.latitude(), faker.address.longitude()]
+ return [faker.address.latitude(), faker.address.longitude()];
}
radius = radius || 10.0;
isMetric = isMetric || false;
@@ -394,17 +415,22 @@ function Address (faker) {
// Possibly include param to function that allows user to choose between distributions.
// This approach will likely result in a higher density of points near the center.
- var randomCoord = coordinateWithOffset(coordinate, degreesToRadians(Math.random() * 360.0), radius, isMetric);
+ var randomCoord = coordinateWithOffset(
+ coordinate,
+ degreesToRadians(Math.random() * 360.0),
+ radius,
+ isMetric
+ );
return [randomCoord[0].toFixed(4), randomCoord[1].toFixed(4)];
- }
+ };
/**
- * Return a random time zone
- * @method faker.address.timeZone
- */
- this.timeZone = function() {
+ * Return a random time zone
+ * @method faker.address.timeZone
+ */
+ this.timeZone = function () {
return faker.random.arrayElement(faker.definitions.address.time_zone);
- }
+ };
return this;
}
diff --git a/lib/animal.js b/lib/animal.js
index ff183362..1d0a8160 100644
--- a/lib/animal.js
+++ b/lib/animal.js
@@ -10,7 +10,7 @@ var Animal = function (faker) {
*
* @method faker.animal.dog
*/
- self.dog = function() {
+ self.dog = function () {
return faker.random.arrayElement(faker.definitions.animal.dog);
};
/**
@@ -18,47 +18,47 @@ var Animal = function (faker) {
*
* @method faker.animal.cat
*/
- self.cat = function() {
+ self.cat = function () {
return faker.random.arrayElement(faker.definitions.animal.cat);
};
/**
- * snake
+ * snake
*
* @method faker.animal.snake
*/
- self.snake = function() {
+ self.snake = function () {
return faker.random.arrayElement(faker.definitions.animal.snake);
};
/**
- * bear
+ * bear
*
* @method faker.animal.bear
*/
- self.bear = function() {
+ self.bear = function () {
return faker.random.arrayElement(faker.definitions.animal.bear);
};
/**
- * lion
+ * lion
*
* @method faker.animal.lion
*/
- self.lion = function() {
+ self.lion = function () {
return faker.random.arrayElement(faker.definitions.animal.lion);
};
/**
- * cetacean
+ * cetacean
*
* @method faker.animal.cetacean
*/
- self.cetacean = function() {
+ self.cetacean = function () {
return faker.random.arrayElement(faker.definitions.animal.cetacean);
};
/**
- * horse
+ * horse
*
* @method faker.animal.horse
*/
- self.horse = function() {
+ self.horse = function () {
return faker.random.arrayElement(faker.definitions.animal.horse);
};
/**
@@ -66,15 +66,15 @@ var Animal = function (faker) {
*
* @method faker.animal.bird
*/
- self.bird = function() {
+ self.bird = function () {
return faker.random.arrayElement(faker.definitions.animal.bird);
};
/**
- * cow
+ * cow
*
* @method faker.animal.cow
*/
- self.cow = function() {
+ self.cow = function () {
return faker.random.arrayElement(faker.definitions.animal.cow);
};
/**
@@ -82,7 +82,7 @@ var Animal = function (faker) {
*
* @method faker.animal.fish
*/
- self.fish = function() {
+ self.fish = function () {
return faker.random.arrayElement(faker.definitions.animal.fish);
};
/**
@@ -90,31 +90,31 @@ var Animal = function (faker) {
*
* @method faker.animal.crocodilia
*/
- self.crocodilia = function() {
+ self.crocodilia = function () {
return faker.random.arrayElement(faker.definitions.animal.crocodilia);
};
/**
- * insect
+ * insect
*
* @method faker.animal.insect
*/
- self.insect = function() {
+ self.insect = function () {
return faker.random.arrayElement(faker.definitions.animal.insect);
};
/**
- * rabbit
+ * rabbit
*
* @method faker.animal.rabbit
*/
- self.rabbit = function() {
+ self.rabbit = function () {
return faker.random.arrayElement(faker.definitions.animal.rabbit);
};
/**
- * type
+ * type
*
* @method faker.animal.type
*/
- self.type = function() {
+ self.type = function () {
return faker.random.arrayElement(faker.definitions.animal.type);
};
diff --git a/lib/commerce.js b/lib/commerce.js
index a12e102f..32669179 100644
--- a/lib/commerce.js
+++ b/lib/commerce.js
@@ -10,7 +10,7 @@ var Commerce = function (faker) {
*
* @method faker.commerce.color
*/
- self.color = function() {
+ self.color = function () {
return faker.random.arrayElement(faker.definitions.commerce.color);
};
@@ -19,7 +19,7 @@ var Commerce = function (faker) {
*
* @method faker.commerce.department
*/
- self.department = function() {
+ self.department = function () {
return faker.random.arrayElement(faker.definitions.commerce.department);
};
@@ -28,10 +28,14 @@ var Commerce = function (faker) {
*
* @method faker.commerce.productName
*/
- self.productName = function() {
- return faker.commerce.productAdjective() + " " +
- faker.commerce.productMaterial() + " " +
- faker.commerce.product();
+ self.productName = function () {
+ return (
+ faker.commerce.productAdjective() +
+ ' ' +
+ faker.commerce.productMaterial() +
+ ' ' +
+ faker.commerce.product()
+ );
};
/**
@@ -45,19 +49,24 @@ var Commerce = function (faker) {
*
* @return {string}
*/
- self.price = function(min, max, dec, symbol) {
+ self.price = function (min, max, dec, symbol) {
min = min || 1;
max = max || 1000;
dec = dec === undefined ? 2 : dec;
symbol = symbol || '';
if (min < 0 || max < 0) {
- return symbol + 0.00;
+ return symbol + 0.0;
}
var randValue = faker.datatype.number({ max: max, min: min });
- return symbol + (Math.round(randValue * Math.pow(10, dec)) / Math.pow(10, dec)).toFixed(dec);
+ return (
+ symbol +
+ (Math.round(randValue * Math.pow(10, dec)) / Math.pow(10, dec)).toFixed(
+ dec
+ )
+ );
};
/*
@@ -91,8 +100,10 @@ var Commerce = function (faker) {
*
* @method faker.commerce.productAdjective
*/
- self.productAdjective = function() {
- return faker.random.arrayElement(faker.definitions.commerce.product_name.adjective);
+ self.productAdjective = function () {
+ return faker.random.arrayElement(
+ faker.definitions.commerce.product_name.adjective
+ );
};
/**
@@ -100,8 +111,10 @@ var Commerce = function (faker) {
*
* @method faker.commerce.productMaterial
*/
- self.productMaterial = function() {
- return faker.random.arrayElement(faker.definitions.commerce.product_name.material);
+ self.productMaterial = function () {
+ return faker.random.arrayElement(
+ faker.definitions.commerce.product_name.material
+ );
};
/**
@@ -109,8 +122,10 @@ var Commerce = function (faker) {
*
* @method faker.commerce.product
*/
- self.product = function() {
- return faker.random.arrayElement(faker.definitions.commerce.product_name.product);
+ self.product = function () {
+ return faker.random.arrayElement(
+ faker.definitions.commerce.product_name.product
+ );
};
/**
@@ -118,8 +133,10 @@ var Commerce = function (faker) {
*
* @method faker.commerce.productDescription
*/
- self.productDescription = function() {
- return faker.random.arrayElement(faker.definitions.commerce.product_description);
+ self.productDescription = function () {
+ return faker.random.arrayElement(
+ faker.definitions.commerce.product_description
+ );
};
return self;
diff --git a/lib/company.js b/lib/company.js
index 4790d9d8..088474a1 100644
--- a/lib/company.js
+++ b/lib/company.js
@@ -3,10 +3,9 @@
* @namespace faker.company
*/
var Company = function (faker) {
-
var self = this;
var f = faker.fake;
-
+
/**
* suffixes
*
@@ -15,7 +14,7 @@ var Company = function (faker) {
this.suffixes = function () {
// Don't want the source array exposed to modification, so return a copy
return faker.definitions.company.suffix.slice(0);
- }
+ };
/**
* companyName
@@ -24,19 +23,18 @@ var Company = function (faker) {
* @param {string} format
*/
this.companyName = function (format) {
-
var formats = [
'{{name.lastName}} {{company.companySuffix}}',
'{{name.lastName}} - {{name.lastName}}',
- '{{name.lastName}}, {{name.lastName}} and {{name.lastName}}'
+ '{{name.lastName}}, {{name.lastName}} and {{name.lastName}}',
];
- if (typeof format !== "number") {
+ if (typeof format !== 'number') {
format = faker.datatype.number(formats.length - 1);
}
return f(formats[format]);
- }
+ };
/**
* companySuffix
@@ -45,7 +43,7 @@ var Company = function (faker) {
*/
this.companySuffix = function () {
return faker.random.arrayElement(faker.company.suffixes());
- }
+ };
/**
* catchPhrase
@@ -53,8 +51,10 @@ var Company = function (faker) {
* @method faker.company.catchPhrase
*/
this.catchPhrase = function () {
- return f('{{company.catchPhraseAdjective}} {{company.catchPhraseDescriptor}} {{company.catchPhraseNoun}}')
- }
+ return f(
+ '{{company.catchPhraseAdjective}} {{company.catchPhraseDescriptor}} {{company.catchPhraseNoun}}'
+ );
+ };
/**
* bs
@@ -63,7 +63,7 @@ var Company = function (faker) {
*/
this.bs = function () {
return f('{{company.bsBuzz}} {{company.bsAdjective}} {{company.bsNoun}}');
- }
+ };
/**
* catchPhraseAdjective
@@ -72,7 +72,7 @@ var Company = function (faker) {
*/
this.catchPhraseAdjective = function () {
return faker.random.arrayElement(faker.definitions.company.adjective);
- }
+ };
/**
* catchPhraseDescriptor
@@ -81,7 +81,7 @@ var Company = function (faker) {
*/
this.catchPhraseDescriptor = function () {
return faker.random.arrayElement(faker.definitions.company.descriptor);
- }
+ };
/**
* catchPhraseNoun
@@ -90,7 +90,7 @@ var Company = function (faker) {
*/
this.catchPhraseNoun = function () {
return faker.random.arrayElement(faker.definitions.company.noun);
- }
+ };
/**
* bsAdjective
@@ -99,7 +99,7 @@ var Company = function (faker) {
*/
this.bsAdjective = function () {
return faker.random.arrayElement(faker.definitions.company.bs_adjective);
- }
+ };
/**
* bsBuzz
@@ -108,7 +108,7 @@ var Company = function (faker) {
*/
this.bsBuzz = function () {
return faker.random.arrayElement(faker.definitions.company.bs_verb);
- }
+ };
/**
* bsNoun
@@ -117,8 +117,7 @@ var Company = function (faker) {
*/
this.bsNoun = function () {
return faker.random.arrayElement(faker.definitions.company.bs_noun);
- }
-
-}
+ };
+};
-module['exports'] = Company; \ No newline at end of file
+module['exports'] = Company;
diff --git a/lib/database.js b/lib/database.js
index fe408024..96969d86 100644
--- a/lib/database.js
+++ b/lib/database.js
@@ -14,8 +14,8 @@ var Database = function (faker) {
};
self.column.schema = {
- "description": "Generates a column name.",
- "sampleResults": ["id", "title", "createdAt"]
+ description: 'Generates a column name.',
+ sampleResults: ['id', 'title', 'createdAt'],
};
/**
@@ -28,8 +28,8 @@ var Database = function (faker) {
};
self.type.schema = {
- "description": "Generates a column type.",
- "sampleResults": ["byte", "int", "varchar", "timestamp"]
+ description: 'Generates a column type.',
+ sampleResults: ['byte', 'int', 'varchar', 'timestamp'],
};
/**
@@ -42,8 +42,8 @@ var Database = function (faker) {
};
self.collation.schema = {
- "description": "Generates a collation.",
- "sampleResults": ["utf8_unicode_ci", "utf8_bin"]
+ description: 'Generates a collation.',
+ sampleResults: ['utf8_unicode_ci', 'utf8_bin'],
};
/**
@@ -56,9 +56,9 @@ var Database = function (faker) {
};
self.engine.schema = {
- "description": "Generates a storage engine.",
- "sampleResults": ["MyISAM", "InnoDB"]
+ description: 'Generates a storage engine.',
+ sampleResults: ['MyISAM', 'InnoDB'],
};
};
-module["exports"] = Database;
+module['exports'] = Database;
diff --git a/lib/datatype.js b/lib/datatype.js
index 38ddd6de..3bad25a2 100644
--- a/lib/datatype.js
+++ b/lib/datatype.js
@@ -1,240 +1,263 @@
-/**
- *
- * @namespace faker.datatype
- */
-function Datatype (faker, seed) {
- // Use a user provided seed if it is an array or number
- if (Array.isArray(seed) && seed.length) {
- faker.mersenne.seed_array(seed);
- }
- else if(!isNaN(seed)) {
- faker.mersenne.seed(seed);
- }
-
- /**
- * returns a single random number based on a max number or range
- *
- * @method faker.datatype.number
- * @param {mixed} options {min, max, precision}
- */
- this.number = function (options) {
-
- if (typeof options === "number") {
- options = {
- max: options
- };
- }
-
- options = options || {};
-
- if (typeof options.min === "undefined") {
- options.min = 0;
- }
-
- if (typeof options.max === "undefined") {
- options.max = 99999;
- }
- if (typeof options.precision === "undefined") {
- options.precision = 1;
- }
-
- // Make the range inclusive of the max value
- var max = options.max;
- if (max >= 0) {
- max += options.precision;
- }
-
- var randomNumber = Math.floor(
- faker.mersenne.rand(max / options.precision, options.min / options.precision));
- // Workaround problem in Float point arithmetics for e.g. 6681493 / 0.01
- randomNumber = randomNumber / (1 / options.precision);
-
- return randomNumber;
-
- };
-
- /**
- * returns a single random floating-point number based on a max number or range
- *
- * @method faker.datatype.float
- * @param {mixed} options
- */
- this.float = function (options) {
- if (typeof options === "number") {
- options = {
- precision: options
- };
- }
- options = options || {};
- var opts = {};
- for (var p in options) {
- opts[p] = options[p];
- }
- if (typeof opts.precision === 'undefined') {
- opts.precision = 0.01;
- }
- return faker.datatype.number(opts);
- };
-
- /**
- * method returns a Date object using a random number of milliseconds since 1. Jan 1970 UTC
- * Caveat: seeding is not working
- *
- * @method faker.datatype.datetime
- * @param {mixed} options, pass min OR max as number of milliseconds since 1. Jan 1970 UTC
- */
- this.datetime = function (options) {
- if (typeof options === "number") {
- options = {
- max: options
- };
- }
-
- var minMax = 8640000000000000;
-
- options = options || {};
-
- if (typeof options.min === "undefined" || options.min < minMax*-1) {
- options.min = new Date().setFullYear(1990, 1, 1);
- }
-
- if (typeof options.max === "undefined" || options.max > minMax) {
- options.max = new Date().setFullYear(2100,1,1);
- }
-
- var random = faker.datatype.number(options);
- return new Date(random);
- };
-
- /**
- * Returns a string, containing UTF-16 chars between 33 and 125 ('!' to '}')
- *
- *
- * @method faker.datatype.string
- * @param { number } length: length of generated string, default = 10, max length = 2^20
- */
- this.string = function (length) {
- if(length === undefined ){
- length = 10;
- }
-
- var maxLength = Math.pow(2, 20);
- if(length >= (maxLength)){
- length = maxLength;
- }
-
- var charCodeOption = {
- min: 33,
- max: 125
- };
-
- var returnString = '';
-
- for(var i = 0; i < length; i++){
- returnString += String.fromCharCode(faker.datatype.number(charCodeOption));
- }
- return returnString;
- };
-
- /**
- * uuid
- *
- * @method faker.datatype.uuid
- */
- this.uuid = function () {
- var RFC4122_TEMPLATE = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
- var replacePlaceholders = function (placeholder) {
- var random = faker.datatype.number({ min: 0, max: 15 });
- var value = placeholder == 'x' ? random : (random &0x3 | 0x8);
- return value.toString(16);
- };
- return RFC4122_TEMPLATE.replace(/[xy]/g, replacePlaceholders);
- };
-
- /**
- * boolean
- *
- * @method faker.datatype.boolean
- */
- this.boolean = function () {
- return !!faker.datatype.number(1);
- };
-
-
- /**
- * hexaDecimal
- *
- * @method faker.datatype.hexaDecimal
- * @param {number} count defaults to 1
- */
- this.hexaDecimal = function hexaDecimal(count) {
- if (typeof count === "undefined") {
- count = 1;
- }
-
- var wholeString = "";
- for(var i = 0; i < count; i++) {
- wholeString += faker.random.arrayElement(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "A", "B", "C", "D", "E", "F"]);
- }
-
- return "0x"+wholeString;
- };
-
- /**
- * returns json object with 7 pre-defined properties
- *
- * @method faker.datatype.json
- */
- this.json = function json() {
-
- var properties = ['foo', 'bar', 'bike', 'a', 'b', 'name', 'prop'];
-
- var returnObject = {};
- properties.forEach(function(prop){
- returnObject[prop] = faker.datatype.boolean() ?
- faker.datatype.string() : faker.datatype.number();
- });
-
- return JSON.stringify(returnObject);
- };
-
- /**
- * returns an array with values generated by faker.datatype.number and faker.datatype.string
- *
- * @method faker.datatype.array
- * @param { number } length of the returned array
- */
-
- this.array = function array(length) {
-
-
- if(length === undefined){
- length = 10;
- }
- var returnArray = new Array(length);
- for(var i = 0; i < length; i++){
- returnArray[i] = faker.datatype.boolean() ?
- faker.datatype.string() : faker.datatype.number();
- }
- return returnArray;
-
- };
-
- /**
- * returns a Big Integer with values generated by faker.datatype.bigInt
- * @method faker.datatype.bigInt
- * @param { number } value
- */
-
- this.bigInt = function bigInt(value) {
- if(value === undefined){
- value = Math.floor(faker.datatype.number() * 99999999999) + 10000000000;
- }
-
- return BigInt(value);
- };
-
- return this;
-}
-
-module['exports'] = Datatype;
+/**
+ *
+ * @namespace faker.datatype
+ */
+function Datatype(faker, seed) {
+ // Use a user provided seed if it is an array or number
+ if (Array.isArray(seed) && seed.length) {
+ faker.mersenne.seed_array(seed);
+ } else if (!isNaN(seed)) {
+ faker.mersenne.seed(seed);
+ }
+
+ /**
+ * returns a single random number based on a max number or range
+ *
+ * @method faker.datatype.number
+ * @param {mixed} options {min, max, precision}
+ */
+ this.number = function (options) {
+ if (typeof options === 'number') {
+ options = {
+ max: options,
+ };
+ }
+
+ options = options || {};
+
+ if (typeof options.min === 'undefined') {
+ options.min = 0;
+ }
+
+ if (typeof options.max === 'undefined') {
+ options.max = 99999;
+ }
+ if (typeof options.precision === 'undefined') {
+ options.precision = 1;
+ }
+
+ // Make the range inclusive of the max value
+ var max = options.max;
+ if (max >= 0) {
+ max += options.precision;
+ }
+
+ var randomNumber = Math.floor(
+ faker.mersenne.rand(
+ max / options.precision,
+ options.min / options.precision
+ )
+ );
+ // Workaround problem in Float point arithmetics for e.g. 6681493 / 0.01
+ randomNumber = randomNumber / (1 / options.precision);
+
+ return randomNumber;
+ };
+
+ /**
+ * returns a single random floating-point number based on a max number or range
+ *
+ * @method faker.datatype.float
+ * @param {mixed} options
+ */
+ this.float = function (options) {
+ if (typeof options === 'number') {
+ options = {
+ precision: options,
+ };
+ }
+ options = options || {};
+ var opts = {};
+ for (var p in options) {
+ opts[p] = options[p];
+ }
+ if (typeof opts.precision === 'undefined') {
+ opts.precision = 0.01;
+ }
+ return faker.datatype.number(opts);
+ };
+
+ /**
+ * method returns a Date object using a random number of milliseconds since 1. Jan 1970 UTC
+ * Caveat: seeding is not working
+ *
+ * @method faker.datatype.datetime
+ * @param {mixed} options, pass min OR max as number of milliseconds since 1. Jan 1970 UTC
+ */
+ this.datetime = function (options) {
+ if (typeof options === 'number') {
+ options = {
+ max: options,
+ };
+ }
+
+ var minMax = 8640000000000000;
+
+ options = options || {};
+
+ if (typeof options.min === 'undefined' || options.min < minMax * -1) {
+ options.min = new Date().setFullYear(1990, 1, 1);
+ }
+
+ if (typeof options.max === 'undefined' || options.max > minMax) {
+ options.max = new Date().setFullYear(2100, 1, 1);
+ }
+
+ var random = faker.datatype.number(options);
+ return new Date(random);
+ };
+
+ /**
+ * Returns a string, containing UTF-16 chars between 33 and 125 ('!' to '}')
+ *
+ *
+ * @method faker.datatype.string
+ * @param { number } length: length of generated string, default = 10, max length = 2^20
+ */
+ this.string = function (length) {
+ if (length === undefined) {
+ length = 10;
+ }
+
+ var maxLength = Math.pow(2, 20);
+ if (length >= maxLength) {
+ length = maxLength;
+ }
+
+ var charCodeOption = {
+ min: 33,
+ max: 125,
+ };
+
+ var returnString = '';
+
+ for (var i = 0; i < length; i++) {
+ returnString += String.fromCharCode(
+ faker.datatype.number(charCodeOption)
+ );
+ }
+ return returnString;
+ };
+
+ /**
+ * uuid
+ *
+ * @method faker.datatype.uuid
+ */
+ this.uuid = function () {
+ var RFC4122_TEMPLATE = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
+ var replacePlaceholders = function (placeholder) {
+ var random = faker.datatype.number({ min: 0, max: 15 });
+ var value = placeholder == 'x' ? random : (random & 0x3) | 0x8;
+ return value.toString(16);
+ };
+ return RFC4122_TEMPLATE.replace(/[xy]/g, replacePlaceholders);
+ };
+
+ /**
+ * boolean
+ *
+ * @method faker.datatype.boolean
+ */
+ this.boolean = function () {
+ return !!faker.datatype.number(1);
+ };
+
+ /**
+ * hexaDecimal
+ *
+ * @method faker.datatype.hexaDecimal
+ * @param {number} count defaults to 1
+ */
+ this.hexaDecimal = function hexaDecimal(count) {
+ if (typeof count === 'undefined') {
+ count = 1;
+ }
+
+ var wholeString = '';
+ for (var i = 0; i < count; i++) {
+ wholeString += faker.random.arrayElement([
+ '0',
+ '1',
+ '2',
+ '3',
+ '4',
+ '5',
+ '6',
+ '7',
+ '8',
+ '9',
+ 'a',
+ 'b',
+ 'c',
+ 'd',
+ 'e',
+ 'f',
+ 'A',
+ 'B',
+ 'C',
+ 'D',
+ 'E',
+ 'F',
+ ]);
+ }
+
+ return '0x' + wholeString;
+ };
+
+ /**
+ * returns json object with 7 pre-defined properties
+ *
+ * @method faker.datatype.json
+ */
+ this.json = function json() {
+ var properties = ['foo', 'bar', 'bike', 'a', 'b', 'name', 'prop'];
+
+ var returnObject = {};
+ properties.forEach(function (prop) {
+ returnObject[prop] = faker.datatype.boolean()
+ ? faker.datatype.string()
+ : faker.datatype.number();
+ });
+
+ return JSON.stringify(returnObject);
+ };
+
+ /**
+ * returns an array with values generated by faker.datatype.number and faker.datatype.string
+ *
+ * @method faker.datatype.array
+ * @param { number } length of the returned array
+ */
+
+ this.array = function array(length) {
+ if (length === undefined) {
+ length = 10;
+ }
+ var returnArray = new Array(length);
+ for (var i = 0; i < length; i++) {
+ returnArray[i] = faker.datatype.boolean()
+ ? faker.datatype.string()
+ : faker.datatype.number();
+ }
+ return returnArray;
+ };
+
+ /**
+ * returns a Big Integer with values generated by faker.datatype.bigInt
+ * @method faker.datatype.bigInt
+ * @param { number } value
+ */
+
+ this.bigInt = function bigInt(value) {
+ if (value === undefined) {
+ value = Math.floor(faker.datatype.number() * 99999999999) + 10000000000;
+ }
+
+ return BigInt(value);
+ };
+
+ return this;
+}
+
+module['exports'] = Datatype;
diff --git a/lib/date.js b/lib/date.js
index e833c24c..bde170b9 100644
--- a/lib/date.js
+++ b/lib/date.js
@@ -13,13 +13,13 @@ var _Date = function (faker) {
*/
self.past = function (years, refDate) {
var date = new Date();
- if (typeof refDate !== "undefined") {
+ if (typeof refDate !== 'undefined') {
date = new Date(Date.parse(refDate));
}
var range = {
min: 1000,
- max: (years || 1) * 365 * 24 * 3600 * 1000
+ max: (years || 1) * 365 * 24 * 3600 * 1000,
};
var past = date.getTime();
@@ -38,13 +38,13 @@ var _Date = function (faker) {
*/
self.future = function (years, refDate) {
var date = new Date();
- if (typeof refDate !== "undefined") {
+ if (typeof refDate !== 'undefined') {
date = new Date(Date.parse(refDate));
}
var range = {
min: 1000,
- max: (years || 1) * 365 * 24 * 3600 * 1000
+ max: (years || 1) * 365 * 24 * 3600 * 1000,
};
var future = date.getTime();
@@ -78,20 +78,21 @@ var _Date = function (faker) {
* @param {date} to
*/
self.betweens = function (from, to, num) {
- if (typeof num == 'undefined') { num = 3; }
+ if (typeof num == 'undefined') {
+ num = 3;
+ }
var newDates = [];
var fromMilli = Date.parse(from);
- var dateOffset = (Date.parse(to) - fromMilli) / ( num + 1 );
- var lastDate = from
+ var dateOffset = (Date.parse(to) - fromMilli) / (num + 1);
+ var lastDate = from;
for (var i = 0; i < num; i++) {
fromMilli = Date.parse(lastDate);
- lastDate = new Date(fromMilli + dateOffset)
- newDates.push(lastDate)
+ lastDate = new Date(fromMilli + dateOffset);
+ newDates.push(lastDate);
}
return newDates;
};
-
/**
* recent
*
@@ -101,13 +102,13 @@ var _Date = function (faker) {
*/
self.recent = function (days, refDate) {
var date = new Date();
- if (typeof refDate !== "undefined") {
+ if (typeof refDate !== 'undefined') {
date = new Date(Date.parse(refDate));
}
var range = {
min: 1000,
- max: (days || 1) * 24 * 3600 * 1000
+ max: (days || 1) * 24 * 3600 * 1000,
};
var future = date.getTime();
@@ -126,13 +127,13 @@ var _Date = function (faker) {
*/
self.soon = function (days, refDate) {
var date = new Date();
- if (typeof refDate !== "undefined") {
+ if (typeof refDate !== 'undefined') {
date = new Date(Date.parse(refDate));
}
var range = {
min: 1000,
- max: (days || 1) * 24 * 3600 * 1000
+ max: (days || 1) * 24 * 3600 * 1000,
};
var future = date.getTime();
@@ -155,7 +156,10 @@ var _Date = function (faker) {
if (options.abbr) {
type = 'abbr';
}
- if (options.context && typeof faker.definitions.date.month[type + '_context'] !== 'undefined') {
+ if (
+ options.context &&
+ typeof faker.definitions.date.month[type + '_context'] !== 'undefined'
+ ) {
type += '_context';
}
@@ -177,7 +181,10 @@ var _Date = function (faker) {
if (options.abbr) {
type = 'abbr';
}
- if (options.context && typeof faker.definitions.date.weekday[type + '_context'] !== 'undefined') {
+ if (
+ options.context &&
+ typeof faker.definitions.date.weekday[type + '_context'] !== 'undefined'
+ ) {
type += '_context';
}
@@ -187,7 +194,6 @@ var _Date = function (faker) {
};
return self;
-
};
module['exports'] = _Date;
diff --git a/lib/fake.js b/lib/fake.js
index 068808da..9935a2a9 100644
--- a/lib/fake.js
+++ b/lib/fake.js
@@ -3,8 +3,7 @@
*/
-function Fake (faker) {
-
+function Fake(faker) {
/**
* Generator method for combining faker methods based on string input
*
@@ -22,7 +21,7 @@ function Fake (faker) {
* @method faker.fake
* @param {string} str
*/
- this.fake = function fake (str) {
+ this.fake = function fake(str) {
// setup default response as empty string
var res = '';
@@ -44,7 +43,7 @@ function Fake (faker) {
// extract method name from between the {{ }} that we found
// for example: {{name.firstName}}
- var token = str.substr(start + 2, end - start - 2);
+ var token = str.substr(start + 2, end - start - 2);
var method = token.replace('}}', '').replace('{{', '');
// console.log('method', method)
@@ -61,12 +60,12 @@ function Fake (faker) {
// split the method into module and function
var parts = method.split('.');
- if (typeof faker[parts[0]] === "undefined") {
+ if (typeof faker[parts[0]] === 'undefined') {
throw new Error('Invalid module: ' + parts[0]);
}
- if (typeof faker[parts[0]][parts[1]] === "undefined") {
- throw new Error('Invalid method: ' + parts[0] + "." + parts[1]);
+ if (typeof faker[parts[0]][parts[1]] === 'undefined') {
+ throw new Error('Invalid method: ' + parts[0] + '.' + parts[1]);
}
// assign the function from the module.function namespace
@@ -79,14 +78,14 @@ function Fake (faker) {
// Note: we experience a small performance hit here due to JSON.parse try / catch
// If anyone actually needs to optimize this specific code path, please open a support issue on github
try {
- params = JSON.parse(parameters)
+ params = JSON.parse(parameters);
} catch (err) {
// since JSON.parse threw an error, assume parameters was actually a string
params = parameters;
}
var result;
- if (typeof params === "string" && params.length === 0) {
+ if (typeof params === 'string' && params.length === 0) {
result = fn.call(this);
} else {
result = fn.call(this, params);
@@ -96,12 +95,10 @@ function Fake (faker) {
res = str.replace('{{' + token + '}}', result);
// return the response recursively until we are done finding all tags
- return fake(res);
- }
-
+ return fake(res);
+ };
+
return this;
-
-
}
-module['exports'] = Fake; \ No newline at end of file
+module['exports'] = Fake;
diff --git a/lib/finance.js b/lib/finance.js
index e04729b1..b8105c8c 100644
--- a/lib/finance.js
+++ b/lib/finance.js
@@ -2,9 +2,9 @@
* @namespace faker.finance
*/
var Finance = function (faker) {
- var ibanLib = require("./iban");
+ var ibanLib = require('./iban');
var Helpers = faker.helpers,
- self = this;
+ self = this;
/**
* account
@@ -13,16 +13,15 @@ var Finance = function (faker) {
* @param {number} length
*/
self.account = function (length) {
+ length = length || 8;
- length = length || 8;
+ var template = '';
- var template = '';
-
- for (var i = 0; i < length; i++) {
- template = template + '#';
- }
- length = null;
- return Helpers.replaceSymbolWithNumber(template);
+ for (var i = 0; i < length; i++) {
+ template = template + '#';
+ }
+ length = null;
+ return Helpers.replaceSymbolWithNumber(template);
};
/**
@@ -31,8 +30,10 @@ var Finance = function (faker) {
* @method faker.finance.accountName
*/
self.accountName = function () {
-
- return [Helpers.randomize(faker.definitions.finance.account_type), 'Account'].join(' ');
+ return [
+ Helpers.randomize(faker.definitions.finance.account_type),
+ 'Account',
+ ].join(' ');
};
/**
@@ -41,20 +42,19 @@ var Finance = function (faker) {
* @method faker.finance.routingNumber
*/
self.routingNumber = function () {
+ var routingNumber = Helpers.replaceSymbolWithNumber('########');
- var routingNumber = Helpers.replaceSymbolWithNumber('########');
-
- // Modules 10 straight summation.
- var sum = 0;
+ // Modules 10 straight summation.
+ var sum = 0;
- for (var i = 0; i < routingNumber.length; i += 3) {
- sum += Number(routingNumber[i]) * 3;
- sum += Number(routingNumber[i + 1]) * 7;
- sum += Number(routingNumber[i + 2]) || 0;
- }
+ for (var i = 0; i < routingNumber.length; i += 3) {
+ sum += Number(routingNumber[i]) * 3;
+ sum += Number(routingNumber[i + 1]) * 7;
+ sum += Number(routingNumber[i + 2]) || 0;
+ }
- return routingNumber + (Math.ceil(sum / 10) * 10 - sum);
- }
+ return routingNumber + (Math.ceil(sum / 10) * 10 - sum);
+ };
/**
* mask
@@ -65,28 +65,28 @@ var Finance = function (faker) {
* @param {boolean} ellipsis
*/
self.mask = function (length, parens, ellipsis) {
+ //set defaults
+ length =
+ length == 0 || !length || typeof length == 'undefined' ? 4 : length;
+ parens = parens === null ? true : parens;
+ ellipsis = ellipsis === null ? true : ellipsis;
- //set defaults
- length = (length == 0 || !length || typeof length == 'undefined') ? 4 : length;
- parens = (parens === null) ? true : parens;
- ellipsis = (ellipsis === null) ? true : ellipsis;
-
- //create a template for length
- var template = '';
+ //create a template for length
+ var template = '';
- for (var i = 0; i < length; i++) {
- template = template + '#';
- }
+ for (var i = 0; i < length; i++) {
+ template = template + '#';
+ }
- //prefix with ellipsis
- template = (ellipsis) ? ['...', template].join('') : template;
+ //prefix with ellipsis
+ template = ellipsis ? ['...', template].join('') : template;
- template = (parens) ? ['(', template, ')'].join('') : template;
+ template = parens ? ['(', template, ')'].join('') : template;
- //generate random numbers
- template = Helpers.replaceSymbolWithNumber(template);
+ //generate random numbers
+ template = Helpers.replaceSymbolWithNumber(template);
- return template;
+ return template;
};
//min and max take in minimum and maximum amounts, dec is the decimal place you want rounded to, symbol is $, €, £, etc
@@ -104,22 +104,26 @@ var Finance = function (faker) {
* @return {string}
*/
self.amount = function (min, max, dec, symbol, autoFormat) {
+ min = min || 0;
+ max = max || 1000;
+ dec = dec === undefined ? 2 : dec;
+ symbol = symbol || '';
+ const randValue = faker.datatype.number({
+ max: max,
+ min: min,
+ precision: Math.pow(10, -dec),
+ });
+
+ var formattedString;
+ if (autoFormat) {
+ formattedString = randValue.toLocaleString(undefined, {
+ minimumFractionDigits: dec,
+ });
+ } else {
+ formattedString = randValue.toFixed(dec);
+ }
- min = min || 0;
- max = max || 1000;
- dec = dec === undefined ? 2 : dec;
- symbol = symbol || '';
- const randValue = faker.datatype.number({ max: max, min: min, precision: Math.pow(10, -dec) });
-
- var formattedString;
- if(autoFormat) {
- formattedString = randValue.toLocaleString(undefined, {minimumFractionDigits: dec});
- }
- else {
- formattedString = randValue.toFixed(dec);
- }
-
- return symbol + formattedString;
+ return symbol + formattedString;
};
/**
@@ -128,7 +132,7 @@ var Finance = function (faker) {
* @method faker.finance.transactionType
*/
self.transactionType = function () {
- return Helpers.randomize(faker.definitions.finance.transaction_type);
+ return Helpers.randomize(faker.definitions.finance.transaction_type);
};
/**
@@ -137,7 +141,9 @@ var Finance = function (faker) {
* @method faker.finance.currencyCode
*/
self.currencyCode = function () {
- return faker.random.objectElement(faker.definitions.finance.currency)['code'];
+ return faker.random.objectElement(faker.definitions.finance.currency)[
+ 'code'
+ ];
};
/**
@@ -146,7 +152,10 @@ var Finance = function (faker) {
* @method faker.finance.currencyName
*/
self.currencyName = function () {
- return faker.random.objectElement(faker.definitions.finance.currency, 'key');
+ return faker.random.objectElement(
+ faker.definitions.finance.currency,
+ 'key'
+ );
};
/**
@@ -155,12 +164,14 @@ var Finance = function (faker) {
* @method faker.finance.currencySymbol
*/
self.currencySymbol = function () {
- var symbol;
+ var symbol;
- while (!symbol) {
- symbol = faker.random.objectElement(faker.definitions.finance.currency)['symbol'];
- }
- return symbol;
+ while (!symbol) {
+ symbol = faker.random.objectElement(faker.definitions.finance.currency)[
+ 'symbol'
+ ];
+ }
+ return symbol;
};
/**
@@ -174,69 +185,75 @@ var Finance = function (faker) {
var address = faker.random.arrayElement(['1', '3']);
for (var i = 0; i < addressLength - 1; i++)
- address += faker.random.arrayElement('123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'.split(''));
+ address += faker.random.arrayElement(
+ '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'.split('')
+ );
return address;
- }
+ };
-/**
- * litecoinAddress
- *
- * @method faker.finance.litecoinAddress
- */
-self.litecoinAddress = function () {
- var addressLength = faker.datatype.number({ min: 26, max: 33 });
+ /**
+ * litecoinAddress
+ *
+ * @method faker.finance.litecoinAddress
+ */
+ self.litecoinAddress = function () {
+ var addressLength = faker.datatype.number({ min: 26, max: 33 });
- var address = faker.random.arrayElement(['L', 'M', '3']);
+ var address = faker.random.arrayElement(['L', 'M', '3']);
- for (var i = 0; i < addressLength - 1; i++)
- address += faker.random.arrayElement('123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'.split(''));
+ for (var i = 0; i < addressLength - 1; i++)
+ address += faker.random.arrayElement(
+ '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'.split('')
+ );
- return address;
-}
+ return address;
+ };
/**
* Credit card number
* @method faker.finance.creditCardNumber
* @param {string} provider | scheme
- */
- self.creditCardNumber = function(provider){
- provider = provider || "";
+ */
+ self.creditCardNumber = function (provider) {
+ provider = provider || '';
var format, formats;
var localeFormat = faker.definitions.finance.credit_card;
if (provider in localeFormat) {
formats = localeFormat[provider]; // there chould be multiple formats
- if (typeof formats === "string") {
+ if (typeof formats === 'string') {
format = formats;
} else {
format = faker.random.arrayElement(formats);
}
- } else if (provider.match(/#/)) { // The user chose an optional scheme
+ } else if (provider.match(/#/)) {
+ // The user chose an optional scheme
format = provider;
- } else { // Choose a random provider
+ } else {
+ // Choose a random provider
if (typeof localeFormat === 'string') {
format = localeFormat;
- } else if( typeof localeFormat === "object") {
+ } else if (typeof localeFormat === 'object') {
// Credit cards are in a object structure
- formats = faker.random.objectElement(localeFormat, "value"); // There chould be multiple formats
- if (typeof formats === "string") {
+ formats = faker.random.objectElement(localeFormat, 'value'); // There chould be multiple formats
+ if (typeof formats === 'string') {
format = formats;
} else {
format = faker.random.arrayElement(formats);
}
}
}
- format = format.replace(/\//g,"")
+ format = format.replace(/\//g, '');
return Helpers.replaceCreditCardSymbols(format);
};
/**
* Credit card CVV
* @method faker.finance.creditCardCVV
- */
- self.creditCardCVV = function() {
- var cvv = "";
+ */
+ self.creditCardCVV = function () {
+ var cvv = '';
for (var i = 0; i < 3; i++) {
- cvv += faker.datatype.number({max:9}).toString();
+ cvv += faker.datatype.number({ max: 9 }).toString();
}
return cvv;
};
@@ -261,56 +278,59 @@ self.litecoinAddress = function () {
* @method faker.finance.iban
*/
self.iban = function (formatted, countryCode) {
- var ibanFormat;
- if (countryCode) {
- var findFormat = function(currentFormat) { return currentFormat.country === countryCode; };
- ibanFormat = ibanLib.formats.find(findFormat);
- } else {
- ibanFormat = faker.random.arrayElement(ibanLib.formats);
- }
+ var ibanFormat;
+ if (countryCode) {
+ var findFormat = function (currentFormat) {
+ return currentFormat.country === countryCode;
+ };
+ ibanFormat = ibanLib.formats.find(findFormat);
+ } else {
+ ibanFormat = faker.random.arrayElement(ibanLib.formats);
+ }
- if (!ibanFormat) {
- throw new Error('Country code ' + countryCode + ' not supported.');
- }
+ if (!ibanFormat) {
+ throw new Error('Country code ' + countryCode + ' not supported.');
+ }
- var s = "";
- var count = 0;
- for (var b = 0; b < ibanFormat.bban.length; b++) {
- var bban = ibanFormat.bban[b];
- var c = bban.count;
- count += bban.count;
- while (c > 0) {
- if (bban.type == "a") {
- s += faker.random.arrayElement(ibanLib.alpha);
- } else if (bban.type == "c") {
- if (faker.datatype.number(100) < 80) {
- s += faker.datatype.number(9);
- } else {
- s += faker.random.arrayElement(ibanLib.alpha);
- }
- } else {
- if (c >= 3 && faker.datatype.number(100) < 30) {
- if (faker.datatype.boolean()) {
- s += faker.random.arrayElement(ibanLib.pattern100);
- c -= 2;
- } else {
- s += faker.random.arrayElement(ibanLib.pattern10);
- c--;
- }
- } else {
- s += faker.datatype.number(9);
- }
- }
+ var s = '';
+ var count = 0;
+ for (var b = 0; b < ibanFormat.bban.length; b++) {
+ var bban = ibanFormat.bban[b];
+ var c = bban.count;
+ count += bban.count;
+ while (c > 0) {
+ if (bban.type == 'a') {
+ s += faker.random.arrayElement(ibanLib.alpha);
+ } else if (bban.type == 'c') {
+ if (faker.datatype.number(100) < 80) {
+ s += faker.datatype.number(9);
+ } else {
+ s += faker.random.arrayElement(ibanLib.alpha);
+ }
+ } else {
+ if (c >= 3 && faker.datatype.number(100) < 30) {
+ if (faker.datatype.boolean()) {
+ s += faker.random.arrayElement(ibanLib.pattern100);
+ c -= 2;
+ } else {
+ s += faker.random.arrayElement(ibanLib.pattern10);
c--;
+ }
+ } else {
+ s += faker.datatype.number(9);
}
- s = s.substring(0, count);
- }
- var checksum = 98 - ibanLib.mod97(ibanLib.toDigitString(s + ibanFormat.country + "00"));
- if (checksum < 10) {
- checksum = "0" + checksum;
+ }
+ c--;
}
- var iban = ibanFormat.country + checksum + s;
- return formatted ? iban.match(/.{1,4}/g).join(" ") : iban;
+ s = s.substring(0, count);
+ }
+ var checksum =
+ 98 - ibanLib.mod97(ibanLib.toDigitString(s + ibanFormat.country + '00'));
+ if (checksum < 10) {
+ checksum = '0' + checksum;
+ }
+ var iban = ibanFormat.country + checksum + s;
+ return formatted ? iban.match(/.{1,4}/g).join(' ') : iban;
};
/**
@@ -319,16 +339,20 @@ self.litecoinAddress = function () {
* @method faker.finance.bic
*/
self.bic = function () {
- var vowels = ["A", "E", "I", "O", "U"];
- var prob = faker.datatype.number(100);
- return Helpers.replaceSymbols("???") +
- faker.random.arrayElement(vowels) +
- faker.random.arrayElement(ibanLib.iso3166) +
- Helpers.replaceSymbols("?") + "1" +
- (prob < 10 ?
- Helpers.replaceSymbols("?" + faker.random.arrayElement(vowels) + "?") :
- prob < 40 ?
- Helpers.replaceSymbols("###") : "");
+ var vowels = ['A', 'E', 'I', 'O', 'U'];
+ var prob = faker.datatype.number(100);
+ return (
+ Helpers.replaceSymbols('???') +
+ faker.random.arrayElement(vowels) +
+ faker.random.arrayElement(ibanLib.iso3166) +
+ Helpers.replaceSymbols('?') +
+ '1' +
+ (prob < 10
+ ? Helpers.replaceSymbols('?' + faker.random.arrayElement(vowels) + '?')
+ : prob < 40
+ ? Helpers.replaceSymbols('###')
+ : '')
+ );
};
/**
@@ -336,7 +360,7 @@ self.litecoinAddress = function () {
*
* @method faker.finance.transactionDescription
*/
- self.transactionDescription = function() {
+ self.transactionDescription = function () {
var transaction = Helpers.createTransaction();
var account = transaction.account;
var amount = transaction.amount;
@@ -344,9 +368,20 @@ self.litecoinAddress = function () {
var company = transaction.business;
var card = faker.finance.mask();
var currency = faker.finance.currencyCode();
- return transactionType + " transaction at " + company + " using card ending with ***" + card + " for " + currency + " " + amount + " in account ***" + account
+ return (
+ transactionType +
+ ' transaction at ' +
+ company +
+ ' using card ending with ***' +
+ card +
+ ' for ' +
+ currency +
+ ' ' +
+ amount +
+ ' in account ***' +
+ account
+ );
};
-
};
module['exports'] = Finance;
diff --git a/lib/git.js b/lib/git.js
index e4a31a8e..0fe9d1b2 100644
--- a/lib/git.js
+++ b/lib/git.js
@@ -2,22 +2,39 @@
* @namespace faker.git
*/
-var Git = function(faker) {
+var Git = function (faker) {
var self = this;
var f = faker.fake;
- var hexChars = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
+ var hexChars = [
+ '0',
+ '1',
+ '2',
+ '3',
+ '4',
+ '5',
+ '6',
+ '7',
+ '8',
+ '9',
+ 'a',
+ 'b',
+ 'c',
+ 'd',
+ 'e',
+ 'f',
+ ];
/**
* branch
*
* @method faker.git.branch
*/
- self.branch = function() {
+ self.branch = function () {
var noun = faker.hacker.noun().replace(' ', '-');
var verb = faker.hacker.verb().replace(' ', '-');
return noun + '-' + verb;
- }
+ };
/**
* commitEntry
@@ -25,16 +42,17 @@ var Git = function(faker) {
* @method faker.git.commitEntry
* @param {object} options
*/
- self.commitEntry = function(options) {
+ self.commitEntry = function (options) {
options = options || {};
var entry = 'commit {{git.commitSha}}\r\n';
- if (options.merge || (faker.datatype.number({ min: 0, max: 4 }) === 0)) {
+ if (options.merge || faker.datatype.number({ min: 0, max: 4 }) === 0) {
entry += 'Merge: {{git.shortSha}} {{git.shortSha}}\r\n';
}
- entry += 'Author: {{name.firstName}} {{name.lastName}} <{{internet.email}}>\r\n';
+ entry +=
+ 'Author: {{name.firstName}} {{name.lastName}} <{{internet.email}}>\r\n';
entry += 'Date: ' + faker.date.recent().toString() + '\r\n';
entry += '\r\n\xa0\xa0\xa0\xa0{{git.commitMessage}}\r\n';
@@ -46,7 +64,7 @@ var Git = function(faker) {
*
* @method faker.git.commitMessage
*/
- self.commitMessage = function() {
+ self.commitMessage = function () {
var format = '{{hacker.verb}} {{hacker.adjective}} {{hacker.noun}}';
return f(format);
};
@@ -56,8 +74,8 @@ var Git = function(faker) {
*
* @method faker.git.commitSha
*/
- self.commitSha = function() {
- var commit = "";
+ self.commitSha = function () {
+ var commit = '';
for (var i = 0; i < 40; i++) {
commit += faker.random.arrayElement(hexChars);
@@ -71,8 +89,8 @@ var Git = function(faker) {
*
* @method faker.git.shortSha
*/
- self.shortSha = function() {
- var shortSha = "";
+ self.shortSha = function () {
+ var shortSha = '';
for (var i = 0; i < 7; i++) {
shortSha += faker.random.arrayElement(hexChars);
@@ -82,6 +100,6 @@ var Git = function(faker) {
};
return self;
-}
+};
module['exports'] = Git;
diff --git a/lib/hacker.js b/lib/hacker.js
index 9f32ee43..f2c5483a 100644
--- a/lib/hacker.js
+++ b/lib/hacker.js
@@ -4,7 +4,7 @@
*/
var Hacker = function (faker) {
var self = this;
-
+
/**
* abbreviation
*
@@ -56,20 +56,19 @@ var Hacker = function (faker) {
* @method faker.hacker.phrase
*/
self.phrase = function () {
-
var data = {
abbreviation: self.abbreviation,
adjective: self.adjective,
ingverb: self.ingverb,
noun: self.noun,
- verb: self.verb
+ verb: self.verb,
};
var phrase = faker.random.arrayElement(faker.definitions.hacker.phrase);
return faker.helpers.mustache(phrase, data);
};
-
+
return self;
};
-module['exports'] = Hacker; \ No newline at end of file
+module['exports'] = Hacker;
diff --git a/lib/helpers.js b/lib/helpers.js
index 4ecdaab3..998a18ea 100644
--- a/lib/helpers.js
+++ b/lib/helpers.js
@@ -3,7 +3,6 @@
* @namespace faker.helpers
*/
var Helpers = function (faker) {
-
var self = this;
/**
@@ -13,8 +12,8 @@ var Helpers = function (faker) {
* @param {array} array
*/
self.randomize = function (array) {
- array = array || ["a", "b", "c"];
- return faker.random.arrayElement(array);
+ array = array || ['a', 'b', 'c'];
+ return faker.random.arrayElement(array);
};
/**
@@ -24,8 +23,10 @@ var Helpers = function (faker) {
* @param {string} string
*/
self.slugify = function (string) {
- string = string || "";
- return string.replace(/ /g, '-').replace(/[^\一-龠\ぁ-ゔ\ァ-ヴー\w\.\-]+/g, '');
+ string = string || '';
+ return string
+ .replace(/ /g, '-')
+ .replace(/[^\一-龠\ぁ-ゔ\ァ-ヴー\w\.\-]+/g, '');
};
/**
@@ -36,23 +37,23 @@ var Helpers = function (faker) {
* @param {string} symbol defaults to `"#"`
*/
self.replaceSymbolWithNumber = function (string, symbol) {
- string = string || "";
- // default symbol is '#'
- if (symbol === undefined) {
- symbol = '#';
- }
+ string = string || '';
+ // default symbol is '#'
+ if (symbol === undefined) {
+ symbol = '#';
+ }
- var str = '';
- for (var i = 0; i < string.length; i++) {
- if (string.charAt(i) == symbol) {
- str += faker.datatype.number(9);
- } else if (string.charAt(i) == "!"){
- str += faker.datatype.number({min: 2, max: 9});
- } else {
- str += string.charAt(i);
- }
+ var str = '';
+ for (var i = 0; i < string.length; i++) {
+ if (string.charAt(i) == symbol) {
+ str += faker.datatype.number(9);
+ } else if (string.charAt(i) == '!') {
+ str += faker.datatype.number({ min: 2, max: 9 });
+ } else {
+ str += string.charAt(i);
}
- return str;
+ }
+ return str;
};
/**
@@ -63,22 +64,51 @@ var Helpers = function (faker) {
* @param {string} string
*/
self.replaceSymbols = function (string) {
- string = string || "";
- var alpha = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
- var str = '';
+ string = string || '';
+ var alpha = [
+ 'A',
+ 'B',
+ 'C',
+ 'D',
+ 'E',
+ 'F',
+ 'G',
+ 'H',
+ 'I',
+ 'J',
+ 'K',
+ 'L',
+ 'M',
+ 'N',
+ 'O',
+ 'P',
+ 'Q',
+ 'R',
+ 'S',
+ 'T',
+ 'U',
+ 'V',
+ 'W',
+ 'X',
+ 'Y',
+ 'Z',
+ ];
+ var str = '';
- for (var i = 0; i < string.length; i++) {
- if (string.charAt(i) == "#") {
- str += faker.datatype.number(9);
- } else if (string.charAt(i) == "?") {
- str += faker.random.arrayElement(alpha);
- } else if (string.charAt(i) == "*") {
- str += faker.datatype.boolean() ? faker.random.arrayElement(alpha) : faker.datatype.number(9);
- } else {
- str += string.charAt(i);
- }
+ for (var i = 0; i < string.length; i++) {
+ if (string.charAt(i) == '#') {
+ str += faker.datatype.number(9);
+ } else if (string.charAt(i) == '?') {
+ str += faker.random.arrayElement(alpha);
+ } else if (string.charAt(i) == '*') {
+ str += faker.datatype.boolean()
+ ? faker.random.arrayElement(alpha)
+ : faker.datatype.number(9);
+ } else {
+ str += string.charAt(i);
}
- return str;
+ }
+ return str;
};
/**
@@ -89,130 +119,143 @@ var Helpers = function (faker) {
* @param {string} symbol
*/
- self.replaceCreditCardSymbols = function(string, symbol) {
+ self.replaceCreditCardSymbols = function (string, symbol) {
+ // default values required for calling method without arguments
+ string = string || '6453-####-####-####-###L';
+ symbol = symbol || '#';
- // default values required for calling method without arguments
- string = string || "6453-####-####-####-###L";
- symbol = symbol || "#";
-
- // Function calculating the Luhn checksum of a number string
- var getCheckBit = function(number) {
- number.reverse();
- number = number.map(function(num, index){
- if (index%2 === 0) {
- num *= 2;
- if(num>9) {
- num -= 9;
- }
- }
- return num;
- });
- var sum = number.reduce(function(prev,curr){return prev + curr;});
- return sum % 10;
- };
+ // Function calculating the Luhn checksum of a number string
+ var getCheckBit = function (number) {
+ number.reverse();
+ number = number.map(function (num, index) {
+ if (index % 2 === 0) {
+ num *= 2;
+ if (num > 9) {
+ num -= 9;
+ }
+ }
+ return num;
+ });
+ var sum = number.reduce(function (prev, curr) {
+ return prev + curr;
+ });
+ return sum % 10;
+ };
- string = faker.helpers.regexpStyleStringParse(string); // replace [4-9] with a random number in range etc...
- string = faker.helpers.replaceSymbolWithNumber(string, symbol); // replace ### with random numbers
+ string = faker.helpers.regexpStyleStringParse(string); // replace [4-9] with a random number in range etc...
+ string = faker.helpers.replaceSymbolWithNumber(string, symbol); // replace ### with random numbers
- var numberList = string.replace(/\D/g,"").split("").map(function(num){return parseInt(num);});
- var checkNum = getCheckBit(numberList);
- return string.replace("L",checkNum);
- };
+ var numberList = string
+ .replace(/\D/g, '')
+ .split('')
+ .map(function (num) {
+ return parseInt(num);
+ });
+ var checkNum = getCheckBit(numberList);
+ return string.replace('L', checkNum);
+ };
- /** string repeat helper, alternative to String.prototype.repeat.... See PR #382
+ /** string repeat helper, alternative to String.prototype.repeat.... See PR #382
*
* @method faker.helpers.repeatString
* @param {string} string
* @param {number} num
*/
- self.repeatString = function(string, num) {
- if(typeof num ==="undefined") {
- num = 0;
- }
- var text = "";
- for(var i = 0; i < num; i++){
- text += string.toString();
- }
- return text;
- };
+ self.repeatString = function (string, num) {
+ if (typeof num === 'undefined') {
+ num = 0;
+ }
+ var text = '';
+ for (var i = 0; i < num; i++) {
+ text += string.toString();
+ }
+ return text;
+ };
- /**
- * parse string patterns in a similar way to RegExp
- *
- * e.g. "#{3}test[1-5]" -> "###test4"
- *
- * @method faker.helpers.regexpStyleStringParse
- * @param {string} string
- */
- self.regexpStyleStringParse = function(string){
- string = string || "";
- // Deal with range repeat `{min,max}`
- var RANGE_REP_REG = /(.)\{(\d+)\,(\d+)\}/;
- var REP_REG = /(.)\{(\d+)\}/;
- var RANGE_REG = /\[(\d+)\-(\d+)\]/;
- var min, max, tmp, repetitions;
- var token = string.match(RANGE_REP_REG);
- while(token !== null){
- min = parseInt(token[2]);
- max = parseInt(token[3]);
- // switch min and max
- if(min>max) {
- tmp = max;
- max = min;
- min = tmp;
- }
- repetitions = faker.datatype.number({min:min,max:max});
- string = string.slice(0,token.index) + faker.helpers.repeatString(token[1], repetitions) + string.slice(token.index+token[0].length);
- token = string.match(RANGE_REP_REG);
- }
- // Deal with repeat `{num}`
- token = string.match(REP_REG);
- while(token !== null){
- repetitions = parseInt(token[2]);
- string = string.slice(0,token.index)+ faker.helpers.repeatString(token[1], repetitions) + string.slice(token.index+token[0].length);
- token = string.match(REP_REG);
- }
- // Deal with range `[min-max]` (only works with numbers for now)
- //TODO: implement for letters e.g. [0-9a-zA-Z] etc.
+ /**
+ * parse string patterns in a similar way to RegExp
+ *
+ * e.g. "#{3}test[1-5]" -> "###test4"
+ *
+ * @method faker.helpers.regexpStyleStringParse
+ * @param {string} string
+ */
+ self.regexpStyleStringParse = function (string) {
+ string = string || '';
+ // Deal with range repeat `{min,max}`
+ var RANGE_REP_REG = /(.)\{(\d+)\,(\d+)\}/;
+ var REP_REG = /(.)\{(\d+)\}/;
+ var RANGE_REG = /\[(\d+)\-(\d+)\]/;
+ var min, max, tmp, repetitions;
+ var token = string.match(RANGE_REP_REG);
+ while (token !== null) {
+ min = parseInt(token[2]);
+ max = parseInt(token[3]);
+ // switch min and max
+ if (min > max) {
+ tmp = max;
+ max = min;
+ min = tmp;
+ }
+ repetitions = faker.datatype.number({ min: min, max: max });
+ string =
+ string.slice(0, token.index) +
+ faker.helpers.repeatString(token[1], repetitions) +
+ string.slice(token.index + token[0].length);
+ token = string.match(RANGE_REP_REG);
+ }
+ // Deal with repeat `{num}`
+ token = string.match(REP_REG);
+ while (token !== null) {
+ repetitions = parseInt(token[2]);
+ string =
+ string.slice(0, token.index) +
+ faker.helpers.repeatString(token[1], repetitions) +
+ string.slice(token.index + token[0].length);
+ token = string.match(REP_REG);
+ }
+ // Deal with range `[min-max]` (only works with numbers for now)
+ //TODO: implement for letters e.g. [0-9a-zA-Z] etc.
- token = string.match(RANGE_REG);
- while(token !== null){
- min = parseInt(token[1]); // This time we are not capturing the char before `[]`
- max = parseInt(token[2]);
- // switch min and max
- if(min>max) {
- tmp = max;
- max = min;
- min = tmp;
- }
- string = string.slice(0,token.index) +
- faker.datatype.number({min:min, max:max}).toString() +
- string.slice(token.index+token[0].length);
- token = string.match(RANGE_REG);
- }
- return string;
- };
+ token = string.match(RANGE_REG);
+ while (token !== null) {
+ min = parseInt(token[1]); // This time we are not capturing the char before `[]`
+ max = parseInt(token[2]);
+ // switch min and max
+ if (min > max) {
+ tmp = max;
+ max = min;
+ min = tmp;
+ }
+ string =
+ string.slice(0, token.index) +
+ faker.datatype.number({ min: min, max: max }).toString() +
+ string.slice(token.index + token[0].length);
+ token = string.match(RANGE_REG);
+ }
+ return string;
+ };
/**
* takes an array and randomizes it in place then returns it
- *
+ *
* uses the modern version of the Fisher–Yates algorithm
*
* @method faker.helpers.shuffle
* @param {array} o
*/
self.shuffle = function (o) {
- if (typeof o === 'undefined' || o.length === 0) {
- return o || [];
- }
- o = o || ["a", "b", "c"];
- for (var x, j, i = o.length - 1; i > 0; --i) {
- j = faker.datatype.number(i);
- x = o[i];
- o[i] = o[j];
- o[j] = x;
- }
- return o;
+ if (typeof o === 'undefined' || o.length === 0) {
+ return o || [];
+ }
+ o = o || ['a', 'b', 'c'];
+ for (var x, j, i = o.length - 1; i > 0; --i) {
+ j = faker.datatype.number(i);
+ x = o[i];
+ o[i] = o[j];
+ o[j] = x;
+ }
+ return o;
};
/**
@@ -225,8 +268,8 @@ var Helpers = function (faker) {
* @param {string[] | function => string} source
* @param {number} length
* @returns {string[]}
- */
- self.uniqueArray = function(source, length) {
+ */
+ self.uniqueArray = function (source, length) {
if (Array.isArray(source)) {
const set = new Set(source);
const array = Array.from(set);
@@ -234,7 +277,7 @@ var Helpers = function (faker) {
}
const set = new Set();
try {
- if (typeof source === "function") {
+ if (typeof source === 'function') {
while (set.size < length) {
set.add(source());
}
@@ -255,8 +298,8 @@ var Helpers = function (faker) {
if (typeof str === 'undefined') {
return '';
}
- for(var p in data) {
- var re = new RegExp('{{' + p + '}}', 'g')
+ for (var p in data) {
+ var re = new RegExp('{{' + p + '}}', 'g');
str = str.replace(re, data[p]);
}
return str;
@@ -268,53 +311,57 @@ var Helpers = function (faker) {
* @method faker.helpers.createCard
*/
self.createCard = function () {
- return {
- "name": faker.name.findName(),
- "username": faker.internet.userName(),
- "email": faker.internet.email(),
- "address": {
- "streetA": faker.address.streetName(),
- "streetB": faker.address.streetAddress(),
- "streetC": faker.address.streetAddress(true),
- "streetD": faker.address.secondaryAddress(),
- "city": faker.address.city(),
- "state": faker.address.state(),
- "country": faker.address.country(),
- "zipcode": faker.address.zipCode(),
- "geo": {
- "lat": faker.address.latitude(),
- "lng": faker.address.longitude()
- }
- },
- "phone": faker.phone.phoneNumber(),
- "website": faker.internet.domainName(),
- "company": {
- "name": faker.company.companyName(),
- "catchPhrase": faker.company.catchPhrase(),
- "bs": faker.company.bs()
- },
- "posts": [
- {
- "words": faker.lorem.words(),
- "sentence": faker.lorem.sentence(),
- "sentences": faker.lorem.sentences(),
- "paragraph": faker.lorem.paragraph()
- },
- {
- "words": faker.lorem.words(),
- "sentence": faker.lorem.sentence(),
- "sentences": faker.lorem.sentences(),
- "paragraph": faker.lorem.paragraph()
- },
- {
- "words": faker.lorem.words(),
- "sentence": faker.lorem.sentence(),
- "sentences": faker.lorem.sentences(),
- "paragraph": faker.lorem.paragraph()
- }
- ],
- "accountHistory": [faker.helpers.createTransaction(), faker.helpers.createTransaction(), faker.helpers.createTransaction()]
- };
+ return {
+ name: faker.name.findName(),
+ username: faker.internet.userName(),
+ email: faker.internet.email(),
+ address: {
+ streetA: faker.address.streetName(),
+ streetB: faker.address.streetAddress(),
+ streetC: faker.address.streetAddress(true),
+ streetD: faker.address.secondaryAddress(),
+ city: faker.address.city(),
+ state: faker.address.state(),
+ country: faker.address.country(),
+ zipcode: faker.address.zipCode(),
+ geo: {
+ lat: faker.address.latitude(),
+ lng: faker.address.longitude(),
+ },
+ },
+ phone: faker.phone.phoneNumber(),
+ website: faker.internet.domainName(),
+ company: {
+ name: faker.company.companyName(),
+ catchPhrase: faker.company.catchPhrase(),
+ bs: faker.company.bs(),
+ },
+ posts: [
+ {
+ words: faker.lorem.words(),
+ sentence: faker.lorem.sentence(),
+ sentences: faker.lorem.sentences(),
+ paragraph: faker.lorem.paragraph(),
+ },
+ {
+ words: faker.lorem.words(),
+ sentence: faker.lorem.sentence(),
+ sentences: faker.lorem.sentences(),
+ paragraph: faker.lorem.paragraph(),
+ },
+ {
+ words: faker.lorem.words(),
+ sentence: faker.lorem.sentence(),
+ sentences: faker.lorem.sentences(),
+ paragraph: faker.lorem.paragraph(),
+ },
+ ],
+ accountHistory: [
+ faker.helpers.createTransaction(),
+ faker.helpers.createTransaction(),
+ faker.helpers.createTransaction(),
+ ],
+ };
};
/**
@@ -324,62 +371,64 @@ var Helpers = function (faker) {
*/
self.contextualCard = function () {
var name = faker.name.firstName(),
- userName = faker.internet.userName(name);
+ userName = faker.internet.userName(name);
return {
- "name": name,
- "username": userName,
- "avatar": faker.internet.avatar(),
- "email": faker.internet.email(userName),
- "dob": faker.date.past(50, new Date("Sat Sep 20 1992 21:35:02 GMT+0200 (CEST)")),
- "phone": faker.phone.phoneNumber(),
- "address": {
- "street": faker.address.streetName(true),
- "suite": faker.address.secondaryAddress(),
- "city": faker.address.city(),
- "zipcode": faker.address.zipCode(),
- "geo": {
- "lat": faker.address.latitude(),
- "lng": faker.address.longitude()
- }
+ name: name,
+ username: userName,
+ avatar: faker.internet.avatar(),
+ email: faker.internet.email(userName),
+ dob: faker.date.past(
+ 50,
+ new Date('Sat Sep 20 1992 21:35:02 GMT+0200 (CEST)')
+ ),
+ phone: faker.phone.phoneNumber(),
+ address: {
+ street: faker.address.streetName(true),
+ suite: faker.address.secondaryAddress(),
+ city: faker.address.city(),
+ zipcode: faker.address.zipCode(),
+ geo: {
+ lat: faker.address.latitude(),
+ lng: faker.address.longitude(),
},
- "website": faker.internet.domainName(),
- "company": {
- "name": faker.company.companyName(),
- "catchPhrase": faker.company.catchPhrase(),
- "bs": faker.company.bs()
- }
+ },
+ website: faker.internet.domainName(),
+ company: {
+ name: faker.company.companyName(),
+ catchPhrase: faker.company.catchPhrase(),
+ bs: faker.company.bs(),
+ },
};
};
-
/**
* userCard
*
* @method faker.helpers.userCard
*/
self.userCard = function () {
- return {
- "name": faker.name.findName(),
- "username": faker.internet.userName(),
- "email": faker.internet.email(),
- "address": {
- "street": faker.address.streetName(true),
- "suite": faker.address.secondaryAddress(),
- "city": faker.address.city(),
- "zipcode": faker.address.zipCode(),
- "geo": {
- "lat": faker.address.latitude(),
- "lng": faker.address.longitude()
- }
- },
- "phone": faker.phone.phoneNumber(),
- "website": faker.internet.domainName(),
- "company": {
- "name": faker.company.companyName(),
- "catchPhrase": faker.company.catchPhrase(),
- "bs": faker.company.bs()
- }
- };
+ return {
+ name: faker.name.findName(),
+ username: faker.internet.userName(),
+ email: faker.internet.email(),
+ address: {
+ street: faker.address.streetName(true),
+ suite: faker.address.secondaryAddress(),
+ city: faker.address.city(),
+ zipcode: faker.address.zipCode(),
+ geo: {
+ lat: faker.address.latitude(),
+ lng: faker.address.longitude(),
+ },
+ },
+ phone: faker.phone.phoneNumber(),
+ website: faker.internet.domainName(),
+ company: {
+ name: faker.company.companyName(),
+ catchPhrase: faker.company.catchPhrase(),
+ bs: faker.company.bs(),
+ },
+ };
};
/**
@@ -387,22 +436,20 @@ var Helpers = function (faker) {
*
* @method faker.helpers.createTransaction
*/
- self.createTransaction = function(){
+ self.createTransaction = function () {
return {
- "amount" : faker.finance.amount(),
- "date" : new Date(2012, 1, 2), //TODO: add a ranged date method
- "business": faker.company.companyName(),
- "name": [faker.finance.accountName(), faker.finance.mask()].join(' '),
- "type" : self.randomize(faker.definitions.finance.transaction_type),
- "account" : faker.finance.account()
+ amount: faker.finance.amount(),
+ date: new Date(2012, 1, 2), //TODO: add a ranged date method
+ business: faker.company.companyName(),
+ name: [faker.finance.accountName(), faker.finance.mask()].join(' '),
+ type: self.randomize(faker.definitions.finance.transaction_type),
+ account: faker.finance.account(),
};
};
return self;
-
};
-
/*
String.prototype.capitalize = function () { //v1.0
return this.replace(/\w+/g, function (a) {
diff --git a/lib/iban.js b/lib/iban.js
index 6a0841d8..0eb3709d 100644
--- a/lib/iban.js
+++ b/lib/iban.js
@@ -1,70 +1,91 @@
-module["exports"] = {
+module['exports'] = {
alpha: [
- 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'
- ],
- pattern10: [
- "01", "02", "03", "04", "05", "06", "07", "08", "09"
- ],
- pattern100: [
- "001", "002", "003", "004", "005", "006", "007", "008", "009"
+ 'A',
+ 'B',
+ 'C',
+ 'D',
+ 'E',
+ 'F',
+ 'G',
+ 'H',
+ 'I',
+ 'J',
+ 'K',
+ 'L',
+ 'M',
+ 'N',
+ 'O',
+ 'P',
+ 'Q',
+ 'R',
+ 'S',
+ 'T',
+ 'U',
+ 'V',
+ 'W',
+ 'X',
+ 'Y',
+ 'Z',
],
+ pattern10: ['01', '02', '03', '04', '05', '06', '07', '08', '09'],
+ pattern100: ['001', '002', '003', '004', '005', '006', '007', '008', '009'],
toDigitString: function (str) {
- return str.replace(/[A-Z]/gi, function(match) {
+ return str.replace(/[A-Z]/gi, function (match) {
return match.toUpperCase().charCodeAt(0) - 55;
});
},
mod97: function (digitStr) {
var m = 0;
for (var i = 0; i < digitStr.length; i++) {
- m = ((m * 10) + (digitStr[i] |0)) % 97;
+ m = (m * 10 + (digitStr[i] | 0)) % 97;
}
return m;
},
formats: [
{
- country: "AL",
+ country: 'AL',
total: 28,
bban: [
{
- type: "n",
- count: 8
+ type: 'n',
+ count: 8,
},
{
- type: "c",
- count: 16
- }
+ type: 'c',
+ count: 16,
+ },
],
- format: "ALkk bbbs sssx cccc cccc cccc cccc"
+ format: 'ALkk bbbs sssx cccc cccc cccc cccc',
},
{
- country: "AD",
+ country: 'AD',
total: 24,
bban: [
{
- type: "n",
- count: 8
+ type: 'n',
+ count: 8,
},
{
- type: "c",
- count: 12
- }
+ type: 'c',
+ count: 12,
+ },
],
- format: "ADkk bbbb ssss cccc cccc cccc"
+ format: 'ADkk bbbb ssss cccc cccc cccc',
},
{
- country: "AT",
+ country: 'AT',
total: 20,
bban: [
{
- type: "n",
- count: 5
+ type: 'n',
+ count: 5,
},
{
- type: "n",
- count: 11
- }
+ type: 'n',
+ count: 11,
+ },
],
- format: "ATkk bbbb bccc cccc cccc"
+ format: 'ATkk bbbb bccc cccc cccc',
},
{
// Azerbaijan
@@ -75,1070 +96,1316 @@ module["exports"] = {
// b = National bank code (alpha)
// c = Account number
// example IBAN AZ21 NABZ 0000 0000 1370 1000 1944
- country: "AZ",
+ country: 'AZ',
total: 28,
bban: [
{
- type: "a",
- count: 4
+ type: 'a',
+ count: 4,
},
{
- type: "n",
- count: 20
- }
+ type: 'n',
+ count: 20,
+ },
],
- format: "AZkk bbbb cccc cccc cccc cccc cccc"
+ format: 'AZkk bbbb cccc cccc cccc cccc cccc',
},
{
- country: "BH",
+ country: 'BH',
total: 22,
bban: [
{
- type: "a",
- count: 4
+ type: 'a',
+ count: 4,
},
{
- type: "c",
- count: 14
- }
+ type: 'c',
+ count: 14,
+ },
],
- format: "BHkk bbbb cccc cccc cccc cc"
+ format: 'BHkk bbbb cccc cccc cccc cc',
},
{
- country: "BE",
+ country: 'BE',
total: 16,
bban: [
{
- type: "n",
- count: 3
+ type: 'n',
+ count: 3,
},
{
- type: "n",
- count: 9
- }
+ type: 'n',
+ count: 9,
+ },
],
- format: "BEkk bbbc cccc ccxx"
+ format: 'BEkk bbbc cccc ccxx',
},
{
- country: "BA",
+ country: 'BA',
total: 20,
bban: [
{
- type: "n",
- count: 6
+ type: 'n',
+ count: 6,
},
{
- type: "n",
- count: 10
- }
+ type: 'n',
+ count: 10,
+ },
],
- format: "BAkk bbbs sscc cccc ccxx"
+ format: 'BAkk bbbs sscc cccc ccxx',
},
{
- country: "BR",
+ country: 'BR',
total: 29,
bban: [
{
- type: "n",
- count: 13
+ type: 'n',
+ count: 13,
},
{
- type: "n",
- count: 10
+ type: 'n',
+ count: 10,
},
{
- type: "a",
- count: 1
+ type: 'a',
+ count: 1,
},
{
- type: "c",
- count: 1
- }
+ type: 'c',
+ count: 1,
+ },
],
- format: "BRkk bbbb bbbb ssss sccc cccc ccct n"
+ format: 'BRkk bbbb bbbb ssss sccc cccc ccct n',
},
{
- country: "BG",
+ country: 'BG',
total: 22,
bban: [
{
- type: "a",
- count: 4
+ type: 'a',
+ count: 4,
},
{
- type: "n",
- count: 6
+ type: 'n',
+ count: 6,
},
{
- type: "c",
- count: 8
- }
+ type: 'c',
+ count: 8,
+ },
],
- format: "BGkk bbbb ssss ddcc cccc cc"
+ format: 'BGkk bbbb ssss ddcc cccc cc',
},
{
- country: "CR",
+ country: 'CR',
total: 21,
bban: [
{
- type: "n",
- count: 3
+ type: 'n',
+ count: 3,
},
{
- type: "n",
- count: 14
- }
+ type: 'n',
+ count: 14,
+ },
],
- format: "CRkk bbbc cccc cccc cccc c"
+ format: 'CRkk bbbc cccc cccc cccc c',
},
{
- country: "HR",
+ country: 'HR',
total: 21,
bban: [
{
- type: "n",
- count: 7
+ type: 'n',
+ count: 7,
},
{
- type: "n",
- count: 10
- }
+ type: 'n',
+ count: 10,
+ },
],
- format: "HRkk bbbb bbbc cccc cccc c"
+ format: 'HRkk bbbb bbbc cccc cccc c',
},
{
- country: "CY",
+ country: 'CY',
total: 28,
bban: [
{
- type: "n",
- count: 8
+ type: 'n',
+ count: 8,
},
{
- type: "c",
- count: 16
- }
+ type: 'c',
+ count: 16,
+ },
],
- format: "CYkk bbbs ssss cccc cccc cccc cccc"
+ format: 'CYkk bbbs ssss cccc cccc cccc cccc',
},
{
- country: "CZ",
+ country: 'CZ',
total: 24,
bban: [
{
- type: "n",
- count: 10
+ type: 'n',
+ count: 10,
},
{
- type: "n",
- count: 10
- }
+ type: 'n',
+ count: 10,
+ },
],
- format: "CZkk bbbb ssss sscc cccc cccc"
+ format: 'CZkk bbbb ssss sscc cccc cccc',
},
{
- country: "DK",
+ country: 'DK',
total: 18,
bban: [
{
- type: "n",
- count: 4
+ type: 'n',
+ count: 4,
},
{
- type: "n",
- count: 10
- }
+ type: 'n',
+ count: 10,
+ },
],
- format: "DKkk bbbb cccc cccc cc"
+ format: 'DKkk bbbb cccc cccc cc',
},
{
- country: "DO",
+ country: 'DO',
total: 28,
bban: [
{
- type: "a",
- count: 4
+ type: 'a',
+ count: 4,
},
{
- type: "n",
- count: 20
- }
+ type: 'n',
+ count: 20,
+ },
],
- format: "DOkk bbbb cccc cccc cccc cccc cccc"
+ format: 'DOkk bbbb cccc cccc cccc cccc cccc',
},
{
- country: "TL",
+ country: 'TL',
total: 23,
bban: [
{
- type: "n",
- count: 3
+ type: 'n',
+ count: 3,
},
{
- type: "n",
- count: 16
- }
+ type: 'n',
+ count: 16,
+ },
],
- format: "TLkk bbbc cccc cccc cccc cxx"
+ format: 'TLkk bbbc cccc cccc cccc cxx',
},
{
- country: "EE",
+ country: 'EE',
total: 20,
bban: [
{
- type: "n",
- count: 4
+ type: 'n',
+ count: 4,
},
{
- type: "n",
- count: 12
- }
+ type: 'n',
+ count: 12,
+ },
],
- format: "EEkk bbss cccc cccc cccx"
+ format: 'EEkk bbss cccc cccc cccx',
},
{
- country: "FO",
+ country: 'FO',
total: 18,
bban: [
{
- type: "n",
- count: 4
+ type: 'n',
+ count: 4,
},
{
- type: "n",
- count: 10
- }
+ type: 'n',
+ count: 10,
+ },
],
- format: "FOkk bbbb cccc cccc cx"
+ format: 'FOkk bbbb cccc cccc cx',
},
{
- country: "FI",
+ country: 'FI',
total: 18,
bban: [
{
- type: "n",
- count: 6
+ type: 'n',
+ count: 6,
},
{
- type: "n",
- count: 8
- }
+ type: 'n',
+ count: 8,
+ },
],
- format: "FIkk bbbb bbcc cccc cx"
+ format: 'FIkk bbbb bbcc cccc cx',
},
{
- country: "FR",
+ country: 'FR',
total: 27,
bban: [
{
- type: "n",
- count: 10
+ type: 'n',
+ count: 10,
},
{
- type: "c",
- count: 11
+ type: 'c',
+ count: 11,
},
{
- type: "n",
- count: 2
- }
+ type: 'n',
+ count: 2,
+ },
],
- format: "FRkk bbbb bggg ggcc cccc cccc cxx"
+ format: 'FRkk bbbb bggg ggcc cccc cccc cxx',
},
{
- country: "GE",
+ country: 'GE',
total: 22,
bban: [
{
- type: "a",
- count: 2
+ type: 'a',
+ count: 2,
},
{
- type: "n",
- count: 16
- }
+ type: 'n',
+ count: 16,
+ },
],
- format: "GEkk bbcc cccc cccc cccc cc"
+ format: 'GEkk bbcc cccc cccc cccc cc',
},
{
- country: "DE",
+ country: 'DE',
total: 22,
bban: [
{
- type: "n",
- count: 8
+ type: 'n',
+ count: 8,
},
{
- type: "n",
- count: 10
- }
+ type: 'n',
+ count: 10,
+ },
],
- format: "DEkk bbbb bbbb cccc cccc cc"
+ format: 'DEkk bbbb bbbb cccc cccc cc',
},
{
- country: "GI",
+ country: 'GI',
total: 23,
bban: [
{
- type: "a",
- count: 4
+ type: 'a',
+ count: 4,
},
{
- type: "c",
- count: 15
- }
+ type: 'c',
+ count: 15,
+ },
],
- format: "GIkk bbbb cccc cccc cccc ccc"
+ format: 'GIkk bbbb cccc cccc cccc ccc',
},
{
- country: "GR",
+ country: 'GR',
total: 27,
bban: [
{
- type: "n",
- count: 7
+ type: 'n',
+ count: 7,
},
{
- type: "c",
- count: 16
- }
+ type: 'c',
+ count: 16,
+ },
],
- format: "GRkk bbbs sssc cccc cccc cccc ccc"
+ format: 'GRkk bbbs sssc cccc cccc cccc ccc',
},
{
- country: "GL",
+ country: 'GL',
total: 18,
bban: [
{
- type: "n",
- count: 4
+ type: 'n',
+ count: 4,
},
{
- type: "n",
- count: 10
- }
+ type: 'n',
+ count: 10,
+ },
],
- format: "GLkk bbbb cccc cccc cc"
+ format: 'GLkk bbbb cccc cccc cc',
},
{
- country: "GT",
+ country: 'GT',
total: 28,
bban: [
{
- type: "c",
- count: 4
+ type: 'c',
+ count: 4,
},
{
- type: "c",
- count: 4
+ type: 'c',
+ count: 4,
},
{
- type: "c",
- count: 16
- }
+ type: 'c',
+ count: 16,
+ },
],
- format: "GTkk bbbb mmtt cccc cccc cccc cccc"
+ format: 'GTkk bbbb mmtt cccc cccc cccc cccc',
},
{
- country: "HU",
+ country: 'HU',
total: 28,
bban: [
{
- type: "n",
- count: 8
+ type: 'n',
+ count: 8,
},
{
- type: "n",
- count: 16
- }
+ type: 'n',
+ count: 16,
+ },
],
- format: "HUkk bbbs sssk cccc cccc cccc cccx"
+ format: 'HUkk bbbs sssk cccc cccc cccc cccx',
},
{
- country: "IS",
+ country: 'IS',
total: 26,
bban: [
{
- type: "n",
- count: 6
+ type: 'n',
+ count: 6,
},
{
- type: "n",
- count: 16
- }
+ type: 'n',
+ count: 16,
+ },
],
- format: "ISkk bbbb sscc cccc iiii iiii ii"
+ format: 'ISkk bbbb sscc cccc iiii iiii ii',
},
{
- country: "IE",
+ country: 'IE',
total: 22,
bban: [
{
- type: "c",
- count: 4
+ type: 'c',
+ count: 4,
},
{
- type: "n",
- count: 6
+ type: 'n',
+ count: 6,
},
{
- type: "n",
- count: 8
- }
+ type: 'n',
+ count: 8,
+ },
],
- format: "IEkk aaaa bbbb bbcc cccc cc"
+ format: 'IEkk aaaa bbbb bbcc cccc cc',
},
{
- country: "IL",
+ country: 'IL',
total: 23,
bban: [
{
- type: "n",
- count: 6
+ type: 'n',
+ count: 6,
},
{
- type: "n",
- count: 13
- }
+ type: 'n',
+ count: 13,
+ },
],
- format: "ILkk bbbn nncc cccc cccc ccc"
+ format: 'ILkk bbbn nncc cccc cccc ccc',
},
{
- country: "IT",
+ country: 'IT',
total: 27,
bban: [
{
- type: "a",
- count: 1
+ type: 'a',
+ count: 1,
},
{
- type: "n",
- count: 10
+ type: 'n',
+ count: 10,
},
{
- type: "c",
- count: 12
- }
+ type: 'c',
+ count: 12,
+ },
],
- format: "ITkk xaaa aabb bbbc cccc cccc ccc"
+ format: 'ITkk xaaa aabb bbbc cccc cccc ccc',
},
{
- country: "JO",
+ country: 'JO',
total: 30,
bban: [
{
- type: "a",
- count: 4
+ type: 'a',
+ count: 4,
},
{
- type: "n",
- count: 4
+ type: 'n',
+ count: 4,
},
{
- type: "n",
- count: 18
- }
+ type: 'n',
+ count: 18,
+ },
],
- format: "JOkk bbbb nnnn cccc cccc cccc cccc cc"
+ format: 'JOkk bbbb nnnn cccc cccc cccc cccc cc',
},
{
- country: "KZ",
+ country: 'KZ',
total: 20,
bban: [
{
- type: "n",
- count: 3
+ type: 'n',
+ count: 3,
},
{
- type: "c",
- count: 13
- }
+ type: 'c',
+ count: 13,
+ },
],
- format: "KZkk bbbc cccc cccc cccc"
+ format: 'KZkk bbbc cccc cccc cccc',
},
{
- country: "XK",
+ country: 'XK',
total: 20,
bban: [
{
- type: "n",
- count: 4
+ type: 'n',
+ count: 4,
},
{
- type: "n",
- count: 12
- }
+ type: 'n',
+ count: 12,
+ },
],
- format: "XKkk bbbb cccc cccc cccc"
+ format: 'XKkk bbbb cccc cccc cccc',
},
{
- country: "KW",
+ country: 'KW',
total: 30,
bban: [
{
- type: "a",
- count: 4
+ type: 'a',
+ count: 4,
},
{
- type: "c",
- count: 22
- }
+ type: 'c',
+ count: 22,
+ },
],
- format: "KWkk bbbb cccc cccc cccc cccc cccc cc"
+ format: 'KWkk bbbb cccc cccc cccc cccc cccc cc',
},
{
- country: "LV",
+ country: 'LV',
total: 21,
bban: [
{
- type: "a",
- count: 4
+ type: 'a',
+ count: 4,
},
{
- type: "c",
- count: 13
- }
+ type: 'c',
+ count: 13,
+ },
],
- format: "LVkk bbbb cccc cccc cccc c"
+ format: 'LVkk bbbb cccc cccc cccc c',
},
{
- country: "LB",
+ country: 'LB',
total: 28,
bban: [
{
- type: "n",
- count: 4
+ type: 'n',
+ count: 4,
},
{
- type: "c",
- count: 20
- }
+ type: 'c',
+ count: 20,
+ },
],
- format: "LBkk bbbb cccc cccc cccc cccc cccc"
+ format: 'LBkk bbbb cccc cccc cccc cccc cccc',
},
{
- country: "LI",
+ country: 'LI',
total: 21,
bban: [
{
- type: "n",
- count: 5
+ type: 'n',
+ count: 5,
},
{
- type: "c",
- count: 12
- }
+ type: 'c',
+ count: 12,
+ },
],
- format: "LIkk bbbb bccc cccc cccc c"
+ format: 'LIkk bbbb bccc cccc cccc c',
},
{
- country: "LT",
+ country: 'LT',
total: 20,
bban: [
{
- type: "n",
- count: 5
+ type: 'n',
+ count: 5,
},
{
- type: "n",
- count: 11
- }
+ type: 'n',
+ count: 11,
+ },
],
- format: "LTkk bbbb bccc cccc cccc"
+ format: 'LTkk bbbb bccc cccc cccc',
},
{
- country: "LU",
+ country: 'LU',
total: 20,
bban: [
{
- type: "n",
- count: 3
+ type: 'n',
+ count: 3,
},
{
- type: "c",
- count: 13
- }
+ type: 'c',
+ count: 13,
+ },
],
- format: "LUkk bbbc cccc cccc cccc"
+ format: 'LUkk bbbc cccc cccc cccc',
},
{
- country: "MK",
+ country: 'MK',
total: 19,
bban: [
{
- type: "n",
- count: 3
+ type: 'n',
+ count: 3,
},
{
- type: "c",
- count: 10
+ type: 'c',
+ count: 10,
},
{
- type: "n",
- count: 2
- }
+ type: 'n',
+ count: 2,
+ },
],
- format: "MKkk bbbc cccc cccc cxx"
+ format: 'MKkk bbbc cccc cccc cxx',
},
{
- country: "MT",
+ country: 'MT',
total: 31,
bban: [
{
- type: "a",
- count: 4
+ type: 'a',
+ count: 4,
},
{
- type: "n",
- count: 5
+ type: 'n',
+ count: 5,
},
{
- type: "c",
- count: 18
- }
+ type: 'c',
+ count: 18,
+ },
],
- format: "MTkk bbbb ssss sccc cccc cccc cccc ccc"
+ format: 'MTkk bbbb ssss sccc cccc cccc cccc ccc',
},
{
- country: "MR",
+ country: 'MR',
total: 27,
bban: [
{
- type: "n",
- count: 10
+ type: 'n',
+ count: 10,
},
{
- type: "n",
- count: 13
- }
+ type: 'n',
+ count: 13,
+ },
],
- format: "MRkk bbbb bsss sscc cccc cccc cxx"
+ format: 'MRkk bbbb bsss sscc cccc cccc cxx',
},
{
- country: "MU",
+ country: 'MU',
total: 30,
bban: [
{
- type: "a",
- count: 4
+ type: 'a',
+ count: 4,
},
{
- type: "n",
- count: 4
+ type: 'n',
+ count: 4,
},
{
- type: "n",
- count: 15
+ type: 'n',
+ count: 15,
},
{
- type: "a",
- count: 3
- }
+ type: 'a',
+ count: 3,
+ },
],
- format: "MUkk bbbb bbss cccc cccc cccc 000d dd"
+ format: 'MUkk bbbb bbss cccc cccc cccc 000d dd',
},
{
- country: "MC",
+ country: 'MC',
total: 27,
bban: [
{
- type: "n",
- count: 10
+ type: 'n',
+ count: 10,
},
{
- type: "c",
- count: 11
+ type: 'c',
+ count: 11,
},
{
- type: "n",
- count: 2
- }
+ type: 'n',
+ count: 2,
+ },
],
- format: "MCkk bbbb bsss sscc cccc cccc cxx"
+ format: 'MCkk bbbb bsss sscc cccc cccc cxx',
},
{
- country: "MD",
+ country: 'MD',
total: 24,
bban: [
{
- type: "c",
- count: 2
+ type: 'c',
+ count: 2,
},
{
- type: "c",
- count: 18
- }
+ type: 'c',
+ count: 18,
+ },
],
- format: "MDkk bbcc cccc cccc cccc cccc"
+ format: 'MDkk bbcc cccc cccc cccc cccc',
},
{
- country: "ME",
+ country: 'ME',
total: 22,
bban: [
{
- type: "n",
- count: 3
+ type: 'n',
+ count: 3,
},
{
- type: "n",
- count: 15
- }
+ type: 'n',
+ count: 15,
+ },
],
- format: "MEkk bbbc cccc cccc cccc xx"
+ format: 'MEkk bbbc cccc cccc cccc xx',
},
{
- country: "NL",
+ country: 'NL',
total: 18,
bban: [
{
- type: "a",
- count: 4
+ type: 'a',
+ count: 4,
},
{
- type: "n",
- count: 10
- }
+ type: 'n',
+ count: 10,
+ },
],
- format: "NLkk bbbb cccc cccc cc"
+ format: 'NLkk bbbb cccc cccc cc',
},
{
- country: "NO",
+ country: 'NO',
total: 15,
bban: [
{
- type: "n",
- count: 4
+ type: 'n',
+ count: 4,
},
{
- type: "n",
- count: 7
- }
+ type: 'n',
+ count: 7,
+ },
],
- format: "NOkk bbbb cccc ccx"
+ format: 'NOkk bbbb cccc ccx',
},
{
- country: "PK",
+ country: 'PK',
total: 24,
bban: [
{
- type: "a",
- count: 4
+ type: 'a',
+ count: 4,
},
{
- type: "n",
- count: 16
- }
+ type: 'n',
+ count: 16,
+ },
],
- format: "PKkk bbbb cccc cccc cccc cccc"
+ format: 'PKkk bbbb cccc cccc cccc cccc',
},
{
- country: "PS",
+ country: 'PS',
total: 29,
bban: [
{
- type: "c",
- count: 4
+ type: 'c',
+ count: 4,
},
{
- type: "n",
- count: 9
+ type: 'n',
+ count: 9,
},
{
- type: "n",
- count: 12
- }
+ type: 'n',
+ count: 12,
+ },
],
- format: "PSkk bbbb xxxx xxxx xccc cccc cccc c"
+ format: 'PSkk bbbb xxxx xxxx xccc cccc cccc c',
},
{
- country: "PL",
+ country: 'PL',
total: 28,
bban: [
{
- type: "n",
- count: 8
+ type: 'n',
+ count: 8,
},
{
- type: "n",
- count: 16
- }
+ type: 'n',
+ count: 16,
+ },
],
- format: "PLkk bbbs sssx cccc cccc cccc cccc"
+ format: 'PLkk bbbs sssx cccc cccc cccc cccc',
},
{
- country: "PT",
+ country: 'PT',
total: 25,
bban: [
{
- type: "n",
- count: 8
+ type: 'n',
+ count: 8,
},
{
- type: "n",
- count: 13
- }
+ type: 'n',
+ count: 13,
+ },
],
- format: "PTkk bbbb ssss cccc cccc cccx x"
+ format: 'PTkk bbbb ssss cccc cccc cccx x',
},
{
- country: "QA",
+ country: 'QA',
total: 29,
bban: [
{
- type: "a",
- count: 4
+ type: 'a',
+ count: 4,
},
{
- type: "c",
- count: 21
- }
+ type: 'c',
+ count: 21,
+ },
],
- format: "QAkk bbbb cccc cccc cccc cccc cccc c"
+ format: 'QAkk bbbb cccc cccc cccc cccc cccc c',
},
{
- country: "RO",
+ country: 'RO',
total: 24,
bban: [
{
- type: "a",
- count: 4
+ type: 'a',
+ count: 4,
},
{
- type: "c",
- count: 16
- }
+ type: 'c',
+ count: 16,
+ },
],
- format: "ROkk bbbb cccc cccc cccc cccc"
+ format: 'ROkk bbbb cccc cccc cccc cccc',
},
{
- country: "SM",
+ country: 'SM',
total: 27,
bban: [
{
- type: "a",
- count: 1
+ type: 'a',
+ count: 1,
},
{
- type: "n",
- count: 10
+ type: 'n',
+ count: 10,
},
{
- type: "c",
- count: 12
- }
+ type: 'c',
+ count: 12,
+ },
],
- format: "SMkk xaaa aabb bbbc cccc cccc ccc"
+ format: 'SMkk xaaa aabb bbbc cccc cccc ccc',
},
{
- country: "SA",
+ country: 'SA',
total: 24,
bban: [
{
- type: "n",
- count: 2
+ type: 'n',
+ count: 2,
},
{
- type: "c",
- count: 18
- }
+ type: 'c',
+ count: 18,
+ },
],
- format: "SAkk bbcc cccc cccc cccc cccc"
+ format: 'SAkk bbcc cccc cccc cccc cccc',
},
{
- country: "RS",
+ country: 'RS',
total: 22,
bban: [
{
- type: "n",
- count: 3
+ type: 'n',
+ count: 3,
},
{
- type: "n",
- count: 15
- }
+ type: 'n',
+ count: 15,
+ },
],
- format: "RSkk bbbc cccc cccc cccc xx"
+ format: 'RSkk bbbc cccc cccc cccc xx',
},
{
- country: "SK",
+ country: 'SK',
total: 24,
bban: [
{
- type: "n",
- count: 10
+ type: 'n',
+ count: 10,
},
{
- type: "n",
- count: 10
- }
+ type: 'n',
+ count: 10,
+ },
],
- format: "SKkk bbbb ssss sscc cccc cccc"
+ format: 'SKkk bbbb ssss sscc cccc cccc',
},
{
- country: "SI",
+ country: 'SI',
total: 19,
bban: [
{
- type: "n",
- count: 5
+ type: 'n',
+ count: 5,
},
{
- type: "n",
- count: 10
- }
+ type: 'n',
+ count: 10,
+ },
],
- format: "SIkk bbss sccc cccc cxx"
+ format: 'SIkk bbss sccc cccc cxx',
},
{
- country: "ES",
+ country: 'ES',
total: 24,
bban: [
{
- type: "n",
- count: 10
+ type: 'n',
+ count: 10,
},
{
- type: "n",
- count: 10
- }
+ type: 'n',
+ count: 10,
+ },
],
- format: "ESkk bbbb gggg xxcc cccc cccc"
+ format: 'ESkk bbbb gggg xxcc cccc cccc',
},
{
- country: "SE",
+ country: 'SE',
total: 24,
bban: [
{
- type: "n",
- count: 3
+ type: 'n',
+ count: 3,
},
{
- type: "n",
- count: 17
- }
+ type: 'n',
+ count: 17,
+ },
],
- format: "SEkk bbbc cccc cccc cccc cccc"
+ format: 'SEkk bbbc cccc cccc cccc cccc',
},
{
- country: "CH",
+ country: 'CH',
total: 21,
bban: [
{
- type: "n",
- count: 5
+ type: 'n',
+ count: 5,
},
{
- type: "c",
- count: 12
- }
+ type: 'c',
+ count: 12,
+ },
],
- format: "CHkk bbbb bccc cccc cccc c"
+ format: 'CHkk bbbb bccc cccc cccc c',
},
{
- country: "TN",
+ country: 'TN',
total: 24,
bban: [
{
- type: "n",
- count: 5
+ type: 'n',
+ count: 5,
},
{
- type: "n",
- count: 15
- }
+ type: 'n',
+ count: 15,
+ },
],
- format: "TNkk bbss sccc cccc cccc cccc"
+ format: 'TNkk bbss sccc cccc cccc cccc',
},
{
- country: "TR",
+ country: 'TR',
total: 26,
bban: [
{
- type: "n",
- count: 5
+ type: 'n',
+ count: 5,
},
{
- type: "n",
- count: 1
+ type: 'n',
+ count: 1,
},
{
- type: "n",
- count: 16
- }
+ type: 'n',
+ count: 16,
+ },
],
- format: "TRkk bbbb bxcc cccc cccc cccc cc"
+ format: 'TRkk bbbb bxcc cccc cccc cccc cc',
},
{
- country: "AE",
+ country: 'AE',
total: 23,
bban: [
{
- type: "n",
- count: 3
+ type: 'n',
+ count: 3,
},
{
- type: "n",
- count: 16
- }
+ type: 'n',
+ count: 16,
+ },
],
- format: "AEkk bbbc cccc cccc cccc ccc"
+ format: 'AEkk bbbc cccc cccc cccc ccc',
},
{
- country: "GB",
+ country: 'GB',
total: 22,
bban: [
{
- type: "a",
- count: 4
+ type: 'a',
+ count: 4,
},
{
- type: "n",
- count: 6
+ type: 'n',
+ count: 6,
},
{
- type: "n",
- count: 8
- }
+ type: 'n',
+ count: 8,
+ },
],
- format: "GBkk bbbb ssss sscc cccc cc"
+ format: 'GBkk bbbb ssss sscc cccc cc',
},
{
- country: "VG",
+ country: 'VG',
total: 24,
bban: [
{
- type: "c",
- count: 4
+ type: 'c',
+ count: 4,
},
{
- type: "n",
- count: 16
- }
+ type: 'n',
+ count: 16,
+ },
],
- format: "VGkk bbbb cccc cccc cccc cccc"
- }
+ format: 'VGkk bbbb cccc cccc cccc cccc',
+ },
],
iso3166: [
- "AC", "AD", "AE", "AF", "AG", "AI", "AL", "AM", "AN", "AO", "AQ", "AR", "AS",
- "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI",
- "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BU", "BV", "BW", "BY",
- "BZ", "CA", "CC", "CD", "CE", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN",
- "CO", "CP", "CR", "CS", "CS", "CU", "CV", "CW", "CX", "CY", "CZ", "DD", "DE",
- "DG", "DJ", "DK", "DM", "DO", "DZ", "EA", "EC", "EE", "EG", "EH", "ER", "ES",
- "ET", "EU", "FI", "FJ", "FK", "FM", "FO", "FR", "FX", "GA", "GB", "GD", "GE",
- "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU",
- "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "IC", "ID", "IE", "IL", "IM",
- "IN", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH",
- "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK",
- "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH",
- "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW",
- "MX", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR",
- "NT", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN",
- "PR", "PS", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB",
- "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR",
- "SS", "ST", "SU", "SV", "SX", "SY", "SZ", "TA", "TC", "TD", "TF", "TG", "TH",
- "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG",
- "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", "WS",
- "YE", "YT", "YU", "ZA", "ZM", "ZR", "ZW"
- ]
-}
+ 'AC',
+ 'AD',
+ 'AE',
+ 'AF',
+ 'AG',
+ 'AI',
+ 'AL',
+ 'AM',
+ 'AN',
+ 'AO',
+ 'AQ',
+ 'AR',
+ 'AS',
+ 'AT',
+ 'AU',
+ 'AW',
+ 'AX',
+ 'AZ',
+ 'BA',
+ 'BB',
+ 'BD',
+ 'BE',
+ 'BF',
+ 'BG',
+ 'BH',
+ 'BI',
+ 'BJ',
+ 'BL',
+ 'BM',
+ 'BN',
+ 'BO',
+ 'BQ',
+ 'BR',
+ 'BS',
+ 'BT',
+ 'BU',
+ 'BV',
+ 'BW',
+ 'BY',
+ 'BZ',
+ 'CA',
+ 'CC',
+ 'CD',
+ 'CE',
+ 'CF',
+ 'CG',
+ 'CH',
+ 'CI',
+ 'CK',
+ 'CL',
+ 'CM',
+ 'CN',
+ 'CO',
+ 'CP',
+ 'CR',
+ 'CS',
+ 'CS',
+ 'CU',
+ 'CV',
+ 'CW',
+ 'CX',
+ 'CY',
+ 'CZ',
+ 'DD',
+ 'DE',
+ 'DG',
+ 'DJ',
+ 'DK',
+ 'DM',
+ 'DO',
+ 'DZ',
+ 'EA',
+ 'EC',
+ 'EE',
+ 'EG',
+ 'EH',
+ 'ER',
+ 'ES',
+ 'ET',
+ 'EU',
+ 'FI',
+ 'FJ',
+ 'FK',
+ 'FM',
+ 'FO',
+ 'FR',
+ 'FX',
+ 'GA',
+ 'GB',
+ 'GD',
+ 'GE',
+ 'GF',
+ 'GG',
+ 'GH',
+ 'GI',
+ 'GL',
+ 'GM',
+ 'GN',
+ 'GP',
+ 'GQ',
+ 'GR',
+ 'GS',
+ 'GT',
+ 'GU',
+ 'GW',
+ 'GY',
+ 'HK',
+ 'HM',
+ 'HN',
+ 'HR',
+ 'HT',
+ 'HU',
+ 'IC',
+ 'ID',
+ 'IE',
+ 'IL',
+ 'IM',
+ 'IN',
+ 'IO',
+ 'IQ',
+ 'IR',
+ 'IS',
+ 'IT',
+ 'JE',
+ 'JM',
+ 'JO',
+ 'JP',
+ 'KE',
+ 'KG',
+ 'KH',
+ 'KI',
+ 'KM',
+ 'KN',
+ 'KP',
+ 'KR',
+ 'KW',
+ 'KY',
+ 'KZ',
+ 'LA',
+ 'LB',
+ 'LC',
+ 'LI',
+ 'LK',
+ 'LR',
+ 'LS',
+ 'LT',
+ 'LU',
+ 'LV',
+ 'LY',
+ 'MA',
+ 'MC',
+ 'MD',
+ 'ME',
+ 'MF',
+ 'MG',
+ 'MH',
+ 'MK',
+ 'ML',
+ 'MM',
+ 'MN',
+ 'MO',
+ 'MP',
+ 'MQ',
+ 'MR',
+ 'MS',
+ 'MT',
+ 'MU',
+ 'MV',
+ 'MW',
+ 'MX',
+ 'MY',
+ 'MZ',
+ 'NA',
+ 'NC',
+ 'NE',
+ 'NF',
+ 'NG',
+ 'NI',
+ 'NL',
+ 'NO',
+ 'NP',
+ 'NR',
+ 'NT',
+ 'NU',
+ 'NZ',
+ 'OM',
+ 'PA',
+ 'PE',
+ 'PF',
+ 'PG',
+ 'PH',
+ 'PK',
+ 'PL',
+ 'PM',
+ 'PN',
+ 'PR',
+ 'PS',
+ 'PT',
+ 'PW',
+ 'PY',
+ 'QA',
+ 'RE',
+ 'RO',
+ 'RS',
+ 'RU',
+ 'RW',
+ 'SA',
+ 'SB',
+ 'SC',
+ 'SD',
+ 'SE',
+ 'SG',
+ 'SH',
+ 'SI',
+ 'SJ',
+ 'SK',
+ 'SL',
+ 'SM',
+ 'SN',
+ 'SO',
+ 'SR',
+ 'SS',
+ 'ST',
+ 'SU',
+ 'SV',
+ 'SX',
+ 'SY',
+ 'SZ',
+ 'TA',
+ 'TC',
+ 'TD',
+ 'TF',
+ 'TG',
+ 'TH',
+ 'TJ',
+ 'TK',
+ 'TL',
+ 'TM',
+ 'TN',
+ 'TO',
+ 'TR',
+ 'TT',
+ 'TV',
+ 'TW',
+ 'TZ',
+ 'UA',
+ 'UG',
+ 'UM',
+ 'US',
+ 'UY',
+ 'UZ',
+ 'VA',
+ 'VC',
+ 'VE',
+ 'VG',
+ 'VI',
+ 'VN',
+ 'VU',
+ 'WF',
+ 'WS',
+ 'YE',
+ 'YT',
+ 'YU',
+ 'ZA',
+ 'ZM',
+ 'ZR',
+ 'ZW',
+ ],
+};
diff --git a/lib/image.js b/lib/image.js
index f027a32d..68f90f8a 100644
--- a/lib/image.js
+++ b/lib/image.js
@@ -7,7 +7,6 @@
* @default Default provider is unsplash image provider
*/
var Image = function (faker) {
-
var self = this;
var Lorempixel = require('./image_providers/lorempixel');
var Unsplash = require('./image_providers/unsplash');
@@ -22,8 +21,26 @@ var Image = function (faker) {
* @method faker.image.image
*/
self.image = function (width, height, randomize) {
- var categories = ["abstract", "animals", "business", "cats", "city", "food", "nightlife", "fashion", "people", "nature", "sports", "technics", "transport"];
- return self[faker.random.arrayElement(categories)](width, height, randomize);
+ var categories = [
+ 'abstract',
+ 'animals',
+ 'business',
+ 'cats',
+ 'city',
+ 'food',
+ 'nightlife',
+ 'fashion',
+ 'people',
+ 'nature',
+ 'sports',
+ 'technics',
+ 'transport',
+ ];
+ return self[faker.random.arrayElement(categories)](
+ width,
+ height,
+ randomize
+ );
};
/**
* avatar
@@ -55,7 +72,7 @@ var Image = function (faker) {
}
if (randomize) {
- url += '?' + faker.datatype.number()
+ url += '?' + faker.datatype.number();
}
return url;
@@ -213,7 +230,22 @@ var Image = function (faker) {
*/
self.dataUri = function (width, height, color) {
color = color || 'grey';
- var svgString = '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" baseProfile="full" width="' + width + '" height="' + height + '"><rect width="100%" height="100%" fill="' + color + '"/><text x="' + width / 2 + '" y="' + height / 2 + '" font-size="20" alignment-baseline="middle" text-anchor="middle" fill="white">' + width + 'x' + height + '</text></svg>';
+ var svgString =
+ '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" baseProfile="full" width="' +
+ width +
+ '" height="' +
+ height +
+ '"><rect width="100%" height="100%" fill="' +
+ color +
+ '"/><text x="' +
+ width / 2 +
+ '" y="' +
+ height / 2 +
+ '" font-size="20" alignment-baseline="middle" text-anchor="middle" fill="white">' +
+ width +
+ 'x' +
+ height +
+ '</text></svg>';
var rawPrefix = 'data:image/svg+xml;charset=UTF-8,';
return rawPrefix + encodeURIComponent(svgString);
};
@@ -224,7 +256,6 @@ var Image = function (faker) {
// Object.assign(self, self.unsplash);
// How to set default as unsplash? should be image.default?
-}
-
+};
-module["exports"] = Image;
+module['exports'] = Image;
diff --git a/lib/image_providers/lorempicsum.js b/lib/image_providers/lorempicsum.js
index fbb6b65f..65639da7 100644
--- a/lib/image_providers/lorempicsum.js
+++ b/lib/image_providers/lorempicsum.js
@@ -4,105 +4,103 @@
* @memberof faker.image
*/
var LoremPicsum = function (faker) {
+ var self = this;
- var self = this;
+ /**
+ * image
+ *
+ * @param {number} width
+ * @param {number} height
+ * @param {boolean} grayscale
+ * @param {number} blur 1-10
+ * @method faker.image.lorempicsum.image
+ * @description search image from unsplash
+ */
+ self.image = function (width, height, grayscale, blur) {
+ return self.imageUrl(width, height, grayscale, blur);
+ };
+ /**
+ * imageGrayscaled
+ *
+ * @param {number} width
+ * @param {number} height
+ * @param {boolean} grayscale
+ * @method faker.image.lorempicsum.imageGrayscaled
+ * @description search grayscale image from unsplash
+ */
+ self.imageGrayscale = function (width, height, grayscale) {
+ return self.imageUrl(width, height, grayscale);
+ };
+ /**
+ * imageBlurred
+ *
+ * @param {number} width
+ * @param {number} height
+ * @param {number} blur 1-10
+ * @method faker.image.lorempicsum.imageBlurred
+ * @description search blurred image from unsplash
+ */
+ self.imageBlurred = function (width, height, blur) {
+ return self.imageUrl(width, height, undefined, blur);
+ };
+ /**
+ * imageRandomSeeded
+ *
+ * @param {number} width
+ * @param {number} height
+ * @param {boolean} grayscale
+ * @param {number} blur 1-10
+ * @param {string} seed
+ * @method faker.image.lorempicsum.imageRandomSeeded
+ * @description search same random image from unsplash, based on a seed
+ */
+ self.imageRandomSeeded = function (width, height, grayscale, blur, seed) {
+ return self.imageUrl(width, height, grayscale, blur, seed);
+ };
+ /**
+ * avatar
+ *
+ * @method faker.image.lorempicsum.avatar
+ */
+ self.avatar = function () {
+ return faker.internet.avatar();
+ };
+ /**
+ * imageUrl
+ *
+ * @param {number} width
+ * @param {number} height
+ * @param {boolean} grayscale
+ * @param {number} blur 1-10
+ * @param {string} seed
+ * @method faker.image.lorempicsum.imageUrl
+ */
+ self.imageUrl = function (width, height, grayscale, blur, seed) {
+ var width = width || 640;
+ var height = height || 480;
- /**
- * image
- *
- * @param {number} width
- * @param {number} height
- * @param {boolean} grayscale
- * @param {number} blur 1-10
- * @method faker.image.lorempicsum.image
- * @description search image from unsplash
- */
- self.image = function (width, height, grayscale, blur) {
- return self.imageUrl(width, height, grayscale, blur);
- };
- /**
- * imageGrayscaled
- *
- * @param {number} width
- * @param {number} height
- * @param {boolean} grayscale
- * @method faker.image.lorempicsum.imageGrayscaled
- * @description search grayscale image from unsplash
- */
- self.imageGrayscale = function (width, height, grayscale) {
- return self.imageUrl(width, height, grayscale);
- };
- /**
- * imageBlurred
- *
- * @param {number} width
- * @param {number} height
- * @param {number} blur 1-10
- * @method faker.image.lorempicsum.imageBlurred
- * @description search blurred image from unsplash
- */
- self.imageBlurred = function (width, height, blur) {
- return self.imageUrl(width, height, undefined, blur);
- };
- /**
- * imageRandomSeeded
- *
- * @param {number} width
- * @param {number} height
- * @param {boolean} grayscale
- * @param {number} blur 1-10
- * @param {string} seed
- * @method faker.image.lorempicsum.imageRandomSeeded
- * @description search same random image from unsplash, based on a seed
- */
- self.imageRandomSeeded = function (width, height, grayscale, blur, seed) {
- return self.imageUrl(width, height, grayscale, blur, seed);
- };
- /**
- * avatar
- *
- * @method faker.image.lorempicsum.avatar
- */
- self.avatar = function () {
- return faker.internet.avatar();
- };
- /**
- * imageUrl
- *
- * @param {number} width
- * @param {number} height
- * @param {boolean} grayscale
- * @param {number} blur 1-10
- * @param {string} seed
- * @method faker.image.lorempicsum.imageUrl
- */
- self.imageUrl = function (width, height, grayscale, blur, seed) {
- var width = width || 640;
- var height = height || 480;
-
- var url = 'https://picsum.photos';
-
- if (seed) {
- url += '/seed/' + seed;
- }
+ var url = 'https://picsum.photos';
- url += '/' + width + '/' + height;
-
- if (grayscale && blur) {
- return url + '?grayscale' + '&blur=' + blur;
- }
+ if (seed) {
+ url += '/seed/' + seed;
+ }
- if (grayscale) {
- return url + '?grayscale';
- }
+ url += '/' + width + '/' + height;
- if (blur) {
- return url + '?blur=' + blur;
- }
-
- return url;
- };
- }
-
- module["exports"] = LoremPicsum;
- \ No newline at end of file
+ if (grayscale && blur) {
+ return url + '?grayscale' + '&blur=' + blur;
+ }
+
+ if (grayscale) {
+ return url + '?grayscale';
+ }
+
+ if (blur) {
+ return url + '?blur=' + blur;
+ }
+
+ return url;
+ };
+};
+
+module['exports'] = LoremPicsum;
diff --git a/lib/image_providers/lorempixel.js b/lib/image_providers/lorempixel.js
index 40c4efb7..24ad4806 100644
--- a/lib/image_providers/lorempixel.js
+++ b/lib/image_providers/lorempixel.js
@@ -4,7 +4,6 @@
* @memberof faker.image
*/
var Lorempixel = function (faker) {
-
var self = this;
/**
@@ -16,8 +15,26 @@ var Lorempixel = function (faker) {
* @method faker.image.lorempixel.image
*/
self.image = function (width, height, randomize) {
- var categories = ["abstract", "animals", "business", "cats", "city", "food", "nightlife", "fashion", "people", "nature", "sports", "technics", "transport"];
- return self[faker.random.arrayElement(categories)](width, height, randomize);
+ var categories = [
+ 'abstract',
+ 'animals',
+ 'business',
+ 'cats',
+ 'city',
+ 'food',
+ 'nightlife',
+ 'fashion',
+ 'people',
+ 'nature',
+ 'sports',
+ 'technics',
+ 'transport',
+ ];
+ return self[faker.random.arrayElement(categories)](
+ width,
+ height,
+ randomize
+ );
};
/**
* avatar
@@ -37,19 +54,19 @@ var Lorempixel = function (faker) {
* @method faker.image.lorempixel.imageUrl
*/
self.imageUrl = function (width, height, category, randomize) {
- var width = width || 640;
- var height = height || 480;
+ var width = width || 640;
+ var height = height || 480;
- var url ='https://lorempixel.com/' + width + '/' + height;
- if (typeof category !== 'undefined') {
- url += '/' + category;
- }
+ var url = 'https://lorempixel.com/' + width + '/' + height;
+ if (typeof category !== 'undefined') {
+ url += '/' + category;
+ }
- if (randomize) {
- url += '?' + faker.datatype.number()
- }
+ if (randomize) {
+ url += '?' + faker.datatype.number();
+ }
- return url;
+ return url;
};
/**
* abstract
@@ -60,7 +77,12 @@ var Lorempixel = function (faker) {
* @method faker.image.lorempixel.abstract
*/
self.abstract = function (width, height, randomize) {
- return faker.image.lorempixel.imageUrl(width, height, 'abstract', randomize);
+ return faker.image.lorempixel.imageUrl(
+ width,
+ height,
+ 'abstract',
+ randomize
+ );
};
/**
* animals
@@ -82,7 +104,12 @@ var Lorempixel = function (faker) {
* @method faker.image.lorempixel.business
*/
self.business = function (width, height, randomize) {
- return faker.image.lorempixel.imageUrl(width, height, 'business', randomize);
+ return faker.image.lorempixel.imageUrl(
+ width,
+ height,
+ 'business',
+ randomize
+ );
};
/**
* cats
@@ -126,7 +153,12 @@ var Lorempixel = function (faker) {
* @method faker.image.lorempixel.nightlife
*/
self.nightlife = function (width, height, randomize) {
- return faker.image.lorempixel.imageUrl(width, height, 'nightlife', randomize);
+ return faker.image.lorempixel.imageUrl(
+ width,
+ height,
+ 'nightlife',
+ randomize
+ );
};
/**
* fashion
@@ -181,7 +213,12 @@ var Lorempixel = function (faker) {
* @method faker.image.lorempixel.technics
*/
self.technics = function (width, height, randomize) {
- return faker.image.lorempixel.imageUrl(width, height, 'technics', randomize);
+ return faker.image.lorempixel.imageUrl(
+ width,
+ height,
+ 'technics',
+ randomize
+ );
};
/**
* transport
@@ -192,8 +229,13 @@ var Lorempixel = function (faker) {
* @method faker.image.lorempixel.transport
*/
self.transport = function (width, height, randomize) {
- return faker.image.lorempixel.imageUrl(width, height, 'transport', randomize);
- }
-}
+ return faker.image.lorempixel.imageUrl(
+ width,
+ height,
+ 'transport',
+ randomize
+ );
+ };
+};
-module["exports"] = Lorempixel;
+module['exports'] = Lorempixel;
diff --git a/lib/image_providers/unsplash.js b/lib/image_providers/unsplash.js
index 514fe84c..e53f270a 100644
--- a/lib/image_providers/unsplash.js
+++ b/lib/image_providers/unsplash.js
@@ -4,9 +4,15 @@
* @memberof faker.image
*/
var Unsplash = function (faker) {
-
var self = this;
- var categories = ["food", "nature", "people", "technology", "objects", "buildings"];
+ var categories = [
+ 'food',
+ 'nature',
+ 'people',
+ 'technology',
+ 'objects',
+ 'buildings',
+ ];
/**
* image
@@ -38,25 +44,27 @@ var Unsplash = function (faker) {
* @method faker.image.unsplash.imageUrl
*/
self.imageUrl = function (width, height, category, keyword) {
- var width = width || 640;
- var height = height || 480;
+ var width = width || 640;
+ var height = height || 480;
- var url ='https://source.unsplash.com';
+ var url = 'https://source.unsplash.com';
- if (typeof category !== 'undefined') {
- url += '/category/' + category;
- }
+ if (typeof category !== 'undefined') {
+ url += '/category/' + category;
+ }
- url += '/' + width + 'x' + height;
+ url += '/' + width + 'x' + height;
- if (typeof keyword !== 'undefined') {
- var keywordFormat = new RegExp('^([A-Za-z0-9].+,[A-Za-z0-9]+)$|^([A-Za-z0-9]+)$');
- if (keywordFormat.test(keyword)) {
- url += '?' + keyword;
- }
+ if (typeof keyword !== 'undefined') {
+ var keywordFormat = new RegExp(
+ '^([A-Za-z0-9].+,[A-Za-z0-9]+)$|^([A-Za-z0-9]+)$'
+ );
+ if (keywordFormat.test(keyword)) {
+ url += '?' + keyword;
}
+ }
- return url;
+ return url;
};
/**
* food
@@ -124,6 +132,6 @@ var Unsplash = function (faker) {
self.buildings = function (width, height, keyword) {
return faker.image.unsplash.imageUrl(width, height, 'buildings', keyword);
};
-}
+};
-module["exports"] = Unsplash;
+module['exports'] = Unsplash;
diff --git a/lib/index.js b/lib/index.js
index d601fed3..c571e3cf 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -21,16 +21,15 @@
*
* @namespace faker
*/
-function Faker (opts) {
-
+function Faker(opts) {
var self = this;
opts = opts || {};
// assign options
var locales = self.locales || opts.locales || {};
- var locale = self.locale || opts.locale || "en";
- var localeFallback = self.localeFallback || opts.localeFallback || "en";
+ var locale = self.locale || opts.locale || 'en';
+ var localeFallback = self.localeFallback || opts.localeFallback || 'en';
self.locales = locales;
self.locale = locale;
@@ -39,41 +38,135 @@ function Faker (opts) {
self.definitions = {};
var _definitions = {
- "name": ["first_name", "last_name", "prefix", "suffix", "binary_gender", "gender", "title", "male_prefix", "female_prefix", "male_first_name", "female_first_name", "male_middle_name", "female_middle_name", "male_last_name", "female_last_name"],
- "address": ["city_name", "city_prefix", "city_suffix", "street_suffix", "county", "country", "country_code", "country_code_alpha_3", "state", "state_abbr", "street_prefix", "postcode", "postcode_by_state", "direction", "direction_abbr", "time_zone"],
- "animal": ["dog", "cat", "snake", "bear", "lion", "cetacean", "insect", "crocodilia", "cow", "bird", "fish", "rabbit", "horse", "type"],
- "company": ["adjective", "noun", "descriptor", "bs_adjective", "bs_noun", "bs_verb", "suffix"],
- "lorem": ["words"],
- "hacker": ["abbreviation", "adjective", "noun", "verb", "ingverb", "phrase"],
- "phone_number": ["formats"],
- "finance": ["account_type", "transaction_type", "currency", "iban", "credit_card"],
- "internet": ["avatar_uri", "domain_suffix", "free_email", "example_email", "password"],
- "commerce": ["color", "department", "product_name", "price", "categories", "product_description"],
- "database": ["collation", "column", "engine", "type"],
- "system": ["mimeTypes", "directoryPaths"],
- "date": ["month", "weekday"],
- "vehicle": ["vehicle", "manufacturer", "model", "type", "fuel", "vin", "color"],
- "music": ["genre"],
- "word": ["adjective", "adverb", "conjunction", "interjection", "noun", "preposition", "verb"],
- "title": "",
- "separator": ""
+ name: [
+ 'first_name',
+ 'last_name',
+ 'prefix',
+ 'suffix',
+ 'binary_gender',
+ 'gender',
+ 'title',
+ 'male_prefix',
+ 'female_prefix',
+ 'male_first_name',
+ 'female_first_name',
+ 'male_middle_name',
+ 'female_middle_name',
+ 'male_last_name',
+ 'female_last_name',
+ ],
+ address: [
+ 'city_name',
+ 'city_prefix',
+ 'city_suffix',
+ 'street_suffix',
+ 'county',
+ 'country',
+ 'country_code',
+ 'country_code_alpha_3',
+ 'state',
+ 'state_abbr',
+ 'street_prefix',
+ 'postcode',
+ 'postcode_by_state',
+ 'direction',
+ 'direction_abbr',
+ 'time_zone',
+ ],
+ animal: [
+ 'dog',
+ 'cat',
+ 'snake',
+ 'bear',
+ 'lion',
+ 'cetacean',
+ 'insect',
+ 'crocodilia',
+ 'cow',
+ 'bird',
+ 'fish',
+ 'rabbit',
+ 'horse',
+ 'type',
+ ],
+ company: [
+ 'adjective',
+ 'noun',
+ 'descriptor',
+ 'bs_adjective',
+ 'bs_noun',
+ 'bs_verb',
+ 'suffix',
+ ],
+ lorem: ['words'],
+ hacker: ['abbreviation', 'adjective', 'noun', 'verb', 'ingverb', 'phrase'],
+ phone_number: ['formats'],
+ finance: [
+ 'account_type',
+ 'transaction_type',
+ 'currency',
+ 'iban',
+ 'credit_card',
+ ],
+ internet: [
+ 'avatar_uri',
+ 'domain_suffix',
+ 'free_email',
+ 'example_email',
+ 'password',
+ ],
+ commerce: [
+ 'color',
+ 'department',
+ 'product_name',
+ 'price',
+ 'categories',
+ 'product_description',
+ ],
+ database: ['collation', 'column', 'engine', 'type'],
+ system: ['mimeTypes', 'directoryPaths'],
+ date: ['month', 'weekday'],
+ vehicle: [
+ 'vehicle',
+ 'manufacturer',
+ 'model',
+ 'type',
+ 'fuel',
+ 'vin',
+ 'color',
+ ],
+ music: ['genre'],
+ word: [
+ 'adjective',
+ 'adverb',
+ 'conjunction',
+ 'interjection',
+ 'noun',
+ 'preposition',
+ 'verb',
+ ],
+ title: '',
+ separator: '',
};
// Create a Getter for all definitions.foo.bar properties
- Object.keys(_definitions).forEach(function(d){
- if (typeof self.definitions[d] === "undefined") {
+ Object.keys(_definitions).forEach(function (d) {
+ if (typeof self.definitions[d] === 'undefined') {
self.definitions[d] = {};
}
- if (typeof _definitions[d] === "string") {
+ if (typeof _definitions[d] === 'string') {
self.definitions[d] = _definitions[d];
return;
}
- _definitions[d].forEach(function(p){
+ _definitions[d].forEach(function (p) {
Object.defineProperty(self.definitions[d], p, {
get: function () {
- if (typeof self.locales[self.locale][d] === "undefined" || typeof self.locales[self.locale][d][p] === "undefined") {
+ if (
+ typeof self.locales[self.locale][d] === 'undefined' ||
+ typeof self.locales[self.locale][d][p] === 'undefined'
+ ) {
// certain localization sets contain less data then others.
// in the case of a missing definition, use the default localeFallback to substitute the missing set data
// throw new Error('unknown property ' + d + p)
@@ -82,7 +175,7 @@ function Faker (opts) {
// return localized data
return self.locales[self.locale][d][p];
}
- }
+ },
});
});
});
@@ -161,17 +254,17 @@ function Faker (opts) {
var Word = require('./word');
self.word = new Word(self);
-};
+}
Faker.prototype.setLocale = function (locale) {
this.locale = locale;
-}
+};
-Faker.prototype.seed = function(value) {
+Faker.prototype.seed = function (value) {
var Random = require('./random');
var Datatype = require('./datatype');
this.seedValue = value;
this.random = new Random(this, this.seedValue);
this.datatype = new Datatype(this, this.seedValue);
-}
-module['exports'] = Faker; \ No newline at end of file
+};
+module['exports'] = Faker;
diff --git a/lib/internet.js b/lib/internet.js
index 7ade42d8..2734d554 100644
--- a/lib/internet.js
+++ b/lib/internet.js
@@ -12,12 +12,15 @@ var Internet = function (faker) {
* @method faker.internet.avatar
*/
self.avatar = function () {
- return 'https://cdn.fakercloud.com/avatars/' + faker.random.arrayElement(faker.definitions.internet.avatar_uri);
+ return (
+ 'https://cdn.fakercloud.com/avatars/' +
+ faker.random.arrayElement(faker.definitions.internet.avatar_uri)
+ );
};
self.avatar.schema = {
- "description": "Generates a URL for an avatar.",
- "sampleResults": ["https://cdn.fakercloud.com/avatars/sydlawrence_128.jpg"]
+ description: 'Generates a URL for an avatar.',
+ sampleResults: ['https://cdn.fakercloud.com/avatars/sydlawrence_128.jpg'],
};
/**
@@ -29,30 +32,37 @@ var Internet = function (faker) {
* @param {string} provider
*/
self.email = function (firstName, lastName, provider) {
- provider = provider || faker.random.arrayElement(faker.definitions.internet.free_email);
- return faker.helpers.slugify(faker.internet.userName(firstName, lastName)) + "@" + provider;
+ provider =
+ provider ||
+ faker.random.arrayElement(faker.definitions.internet.free_email);
+ return (
+ faker.helpers.slugify(faker.internet.userName(firstName, lastName)) +
+ '@' +
+ provider
+ );
};
self.email.schema = {
- "description": "Generates a valid email address based on optional input criteria",
- "sampleResults": ["[email protected]"],
- "properties": {
- "firstName": {
- "type": "string",
- "required": false,
- "description": "The first name of the user"
+ description:
+ 'Generates a valid email address based on optional input criteria',
+ sampleResults: ['[email protected]'],
+ properties: {
+ firstName: {
+ type: 'string',
+ required: false,
+ description: 'The first name of the user',
},
- "lastName": {
- "type": "string",
- "required": false,
- "description": "The last name of the user"
+ lastName: {
+ type: 'string',
+ required: false,
+ description: 'The last name of the user',
},
- "provider": {
- "type": "string",
- "required": false,
- "description": "The domain of the user"
- }
- }
+ provider: {
+ type: 'string',
+ required: false,
+ description: 'The domain of the user',
+ },
+ },
};
/**
* exampleEmail
@@ -62,7 +72,9 @@ var Internet = function (faker) {
* @param {string} lastName
*/
self.exampleEmail = function (firstName, lastName) {
- var provider = faker.random.arrayElement(faker.definitions.internet.example_email);
+ var provider = faker.random.arrayElement(
+ faker.definitions.internet.example_email
+ );
return self.email(firstName, lastName, provider);
};
@@ -82,38 +94,43 @@ var Internet = function (faker) {
result = firstName + faker.datatype.number(99);
break;
case 1:
- result = firstName + faker.random.arrayElement([".", "_"]) + lastName;
+ result = firstName + faker.random.arrayElement(['.', '_']) + lastName;
break;
case 2:
- result = firstName + faker.random.arrayElement([".", "_"]) + lastName + faker.datatype.number(99);
+ result =
+ firstName +
+ faker.random.arrayElement(['.', '_']) +
+ lastName +
+ faker.datatype.number(99);
break;
}
- result = result.toString().replace(/'/g, "");
- result = result.replace(/ /g, "");
+ result = result.toString().replace(/'/g, '');
+ result = result.replace(/ /g, '');
return result;
};
self.userName.schema = {
- "description": "Generates a username based on one of several patterns. The pattern is chosen randomly.",
- "sampleResults": [
- "Kirstin39",
- "Kirstin.Smith",
- "Kirstin.Smith39",
- "KirstinSmith",
- "KirstinSmith39",
+ description:
+ 'Generates a username based on one of several patterns. The pattern is chosen randomly.',
+ sampleResults: [
+ 'Kirstin39',
+ 'Kirstin.Smith',
+ 'Kirstin.Smith39',
+ 'KirstinSmith',
+ 'KirstinSmith39',
],
- "properties": {
- "firstName": {
- "type": "string",
- "required": false,
- "description": "The first name of the user"
+ properties: {
+ firstName: {
+ type: 'string',
+ required: false,
+ description: 'The first name of the user',
},
- "lastName": {
- "type": "string",
- "required": false,
- "description": "The last name of the user"
- }
- }
+ lastName: {
+ type: 'string',
+ required: false,
+ description: 'The last name of the user',
+ },
+ },
};
/**
@@ -122,13 +139,13 @@ var Internet = function (faker) {
* @method faker.internet.protocol
*/
self.protocol = function () {
- var protocols = ['http','https'];
+ var protocols = ['http', 'https'];
return faker.random.arrayElement(protocols);
};
self.protocol.schema = {
- "description": "Randomly generates http or https",
- "sampleResults": ["https", "http"]
+ description: 'Randomly generates http or https',
+ sampleResults: ['https', 'http'],
};
/**
@@ -137,13 +154,14 @@ var Internet = function (faker) {
* @method faker.internet.httpMethod
*/
self.httpMethod = function () {
- var httpMethods = ['GET','POST', 'PUT', 'DELETE', 'PATCH'];
+ var httpMethods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'];
return faker.random.arrayElement(httpMethods);
};
self.httpMethod.schema = {
- "description": "Randomly generates HTTP Methods (GET, POST, PUT, DELETE, PATCH)",
- "sampleResults": ["GET","POST", "PUT", "DELETE", "PATCH"]
+ description:
+ 'Randomly generates HTTP Methods (GET, POST, PUT, DELETE, PATCH)',
+ sampleResults: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'],
};
/**
@@ -156,11 +174,8 @@ var Internet = function (faker) {
};
self.url.schema = {
- "description": "Generates a random URL. The URL could be secure or insecure.",
- "sampleResults": [
- "http://rashawn.name",
- "https://rashawn.name"
- ]
+ description: 'Generates a random URL. The URL could be secure or insecure.',
+ sampleResults: ['http://rashawn.name', 'https://rashawn.name'],
};
/**
@@ -169,12 +184,12 @@ var Internet = function (faker) {
* @method faker.internet.domainName
*/
self.domainName = function () {
- return faker.internet.domainWord() + "." + faker.internet.domainSuffix();
+ return faker.internet.domainWord() + '.' + faker.internet.domainSuffix();
};
self.domainName.schema = {
- "description": "Generates a random domain name.",
- "sampleResults": ["marvin.org"]
+ description: 'Generates a random domain name.',
+ sampleResults: ['marvin.org'],
};
/**
@@ -187,8 +202,8 @@ var Internet = function (faker) {
};
self.domainSuffix.schema = {
- "description": "Generates a random domain suffix.",
- "sampleResults": ["net"]
+ description: 'Generates a random domain suffix.',
+ sampleResults: ['net'],
};
/**
@@ -197,12 +212,14 @@ var Internet = function (faker) {
* @method faker.internet.domainWord
*/
self.domainWord = function () {
- return (faker.word.adjective() + '-' + faker.word.noun()).replace(/([\\~#&*{}/:<>?|\"'])/ig, '').toLowerCase();
+ return (faker.word.adjective() + '-' + faker.word.noun())
+ .replace(/([\\~#&*{}/:<>?|\"'])/gi, '')
+ .toLowerCase();
};
self.domainWord.schema = {
- "description": "Generates a random domain word.",
- "sampleResults": ["alyce"]
+ description: 'Generates a random domain word.',
+ sampleResults: ['alyce'],
};
/**
@@ -212,7 +229,7 @@ var Internet = function (faker) {
*/
self.ip = function () {
var randNum = function () {
- return (faker.datatype.number(255)).toFixed(0);
+ return faker.datatype.number(255).toFixed(0);
};
var result = [];
@@ -220,12 +237,12 @@ var Internet = function (faker) {
result[i] = randNum();
}
- return result.join(".");
+ return result.join('.');
};
self.ip.schema = {
- "description": "Generates a random IP.",
- "sampleResults": ["97.238.241.11"]
+ description: 'Generates a random IP.',
+ sampleResults: ['97.238.241.11'],
};
/**
@@ -235,37 +252,54 @@ var Internet = function (faker) {
*/
self.ipv6 = function () {
var randHash = function () {
- var result = "";
+ var result = '';
for (var i = 0; i < 4; i++) {
- result += (faker.random.arrayElement(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"]));
+ result += faker.random.arrayElement([
+ '0',
+ '1',
+ '2',
+ '3',
+ '4',
+ '5',
+ '6',
+ '7',
+ '8',
+ '9',
+ 'a',
+ 'b',
+ 'c',
+ 'd',
+ 'e',
+ 'f',
+ ]);
}
- return result
+ return result;
};
var result = [];
for (var i = 0; i < 8; i++) {
result[i] = randHash();
}
- return result.join(":");
+ return result.join(':');
};
self.ipv6.schema = {
- "description": "Generates a random IPv6 address.",
- "sampleResults": ["2001:0db8:6276:b1a7:5213:22f1:25df:c8a0"]
+ description: 'Generates a random IPv6 address.',
+ sampleResults: ['2001:0db8:6276:b1a7:5213:22f1:25df:c8a0'],
};
/**
* port
- *
+ *
* @method faker.internet.port
*/
- self.port = function() {
+ self.port = function () {
return faker.datatype.number({ min: 0, max: 65535 });
};
self.port.schema = {
- "description": "Generates a random port number.",
- "sampleResults": ["4422"]
+ description: 'Generates a random port number.',
+ sampleResults: ['4422'],
};
/**
@@ -278,8 +312,10 @@ var Internet = function (faker) {
};
self.userAgent.schema = {
- "description": "Generates a random user agent.",
- "sampleResults": ["Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_7_5 rv:6.0; SL) AppleWebKit/532.0.1 (KHTML, like Gecko) Version/7.1.6 Safari/532.0.1"]
+ description: 'Generates a random user agent.',
+ sampleResults: [
+ 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_7_5 rv:6.0; SL) AppleWebKit/532.0.1 (KHTML, like Gecko) Version/7.1.6 Safari/532.0.1',
+ ],
};
/**
@@ -301,33 +337,37 @@ var Internet = function (faker) {
var redStr = red.toString(16);
var greenStr = green.toString(16);
var blueStr = blue.toString(16);
- return '#' +
- (redStr.length === 1 ? '0' : '') + redStr +
- (greenStr.length === 1 ? '0' : '') + greenStr +
- (blueStr.length === 1 ? '0': '') + blueStr;
-
+ return (
+ '#' +
+ (redStr.length === 1 ? '0' : '') +
+ redStr +
+ (greenStr.length === 1 ? '0' : '') +
+ greenStr +
+ (blueStr.length === 1 ? '0' : '') +
+ blueStr
+ );
};
self.color.schema = {
- "description": "Generates a random hexadecimal color.",
- "sampleResults": ["#06267f"],
- "properties": {
- "baseRed255": {
- "type": "number",
- "required": false,
- "description": "The red value. Valid values are 0 - 255."
+ description: 'Generates a random hexadecimal color.',
+ sampleResults: ['#06267f'],
+ properties: {
+ baseRed255: {
+ type: 'number',
+ required: false,
+ description: 'The red value. Valid values are 0 - 255.',
},
- "baseGreen255": {
- "type": "number",
- "required": false,
- "description": "The green value. Valid values are 0 - 255."
+ baseGreen255: {
+ type: 'number',
+ required: false,
+ description: 'The green value. Valid values are 0 - 255.',
},
- "baseBlue255": {
- "type": "number",
- "required": false,
- "description": "The blue value. Valid values are 0 - 255."
- }
- }
+ baseBlue255: {
+ type: 'number',
+ required: false,
+ description: 'The blue value. Valid values are 0 - 255.',
+ },
+ },
};
/**
@@ -336,29 +376,29 @@ var Internet = function (faker) {
* @method faker.internet.mac
* @param {string} sep
*/
- self.mac = function(sep){
- var i,
- mac = "",
+ self.mac = function (sep) {
+ var i,
+ mac = '',
validSep = ':';
- // if the client passed in a different separator than `:`,
+ // if the client passed in a different separator than `:`,
// we will use it if it is in the list of acceptable separators (dash or no separator)
if (['-', ''].indexOf(sep) !== -1) {
validSep = sep;
- }
+ }
- for (i=0; i < 12; i++) {
- mac+= faker.datatype.number(15).toString(16);
- if (i%2==1 && i != 11) {
- mac+=validSep;
+ for (i = 0; i < 12; i++) {
+ mac += faker.datatype.number(15).toString(16);
+ if (i % 2 == 1 && i != 11) {
+ mac += validSep;
}
}
return mac;
};
self.mac.schema = {
- "description": "Generates a random mac address.",
- "sampleResults": ["78:06:cc:ae:b3:81"]
+ description: 'Generates a random mac address.',
+ sampleResults: ['78:06:cc:ae:b3:81'],
};
/**
@@ -372,14 +412,14 @@ var Internet = function (faker) {
*/
self.password = function (len, memorable, pattern, prefix) {
len = len || 15;
- if (typeof memorable === "undefined") {
+ if (typeof memorable === 'undefined') {
memorable = false;
}
/*
- * password-generator ( function )
- * Copyright(c) 2011-2013 Bermi Ferrer <[email protected]>
- * MIT Licensed
- */
+ * password-generator ( function )
+ * Copyright(c) 2011-2013 Bermi Ferrer <[email protected]>
+ * MIT Licensed
+ */
var consonant, letter, vowel;
letter = /[a-zA-Z]$/;
vowel = /[aeiouAEIOU]$/;
@@ -416,42 +456,39 @@ var Internet = function (faker) {
if (!char.match(pattern)) {
return _password(length, memorable, pattern, prefix);
}
- return _password(length, memorable, pattern, "" + prefix + char);
+ return _password(length, memorable, pattern, '' + prefix + char);
};
return _password(len, memorable, pattern, prefix);
- }
+ };
self.password.schema = {
- "description": "Generates a random password.",
- "sampleResults": [
- "AM7zl6Mg",
- "susejofe"
- ],
- "properties": {
- "length": {
- "type": "number",
- "required": false,
- "description": "The number of characters in the password."
+ description: 'Generates a random password.',
+ sampleResults: ['AM7zl6Mg', 'susejofe'],
+ properties: {
+ length: {
+ type: 'number',
+ required: false,
+ description: 'The number of characters in the password.',
},
- "memorable": {
- "type": "boolean",
- "required": false,
- "description": "Whether a password should be easy to remember."
+ memorable: {
+ type: 'boolean',
+ required: false,
+ description: 'Whether a password should be easy to remember.',
},
- "pattern": {
- "type": "regex",
- "required": false,
- "description": "A regex to match each character of the password against. This parameter will be negated if the memorable setting is turned on."
+ pattern: {
+ type: 'regex',
+ required: false,
+ description:
+ 'A regex to match each character of the password against. This parameter will be negated if the memorable setting is turned on.',
},
- "prefix": {
- "type": "string",
- "required": false,
- "description": "A value to prepend to the generated password. The prefix counts towards the length of the password."
- }
- }
+ prefix: {
+ type: 'string',
+ required: false,
+ description:
+ 'A value to prepend to the generated password. The prefix counts towards the length of the password.',
+ },
+ },
};
-
};
-
-module["exports"] = Internet;
+module['exports'] = Internet;
diff --git a/lib/lorem.js b/lib/lorem.js
index 0569e866..481053ea 100644
--- a/lib/lorem.js
+++ b/lib/lorem.js
@@ -1,4 +1,3 @@
-
/**
*
* @namespace faker.lorem
@@ -14,9 +13,11 @@ var Lorem = function (faker) {
* @param {number} length length of the word that should be returned. Defaults to a random length
*/
self.word = function (length) {
- var hasRightLength = function(word) { return word.length === length; };
+ var hasRightLength = function (word) {
+ return word.length === length;
+ };
var properLengthWords;
- if(typeof length === 'undefined') {
+ if (typeof length === 'undefined') {
properLengthWords = faker.definitions.lorem.words;
} else {
properLengthWords = faker.definitions.lorem.words.filter(hasRightLength);
@@ -31,7 +32,9 @@ var Lorem = function (faker) {
* @param {number} num number of words, defaults to 3
*/
self.words = function (num) {
- if (typeof num == 'undefined') { num = 3; }
+ if (typeof num == 'undefined') {
+ num = 3;
+ }
var words = [];
for (var i = 0; i < num; i++) {
words.push(faker.lorem.word());
@@ -47,7 +50,9 @@ var Lorem = function (faker) {
* @param {number} range
*/
self.sentence = function (wordCount, range) {
- if (typeof wordCount == 'undefined') { wordCount = faker.datatype.number({ min: 3, max: 10 }); }
+ if (typeof wordCount == 'undefined') {
+ wordCount = faker.datatype.number({ min: 3, max: 10 });
+ }
// if (typeof range == 'undefined') { range = 7; }
// strange issue with the node_min_test failing for capitalize, please fix and add faker.lorem.back
@@ -76,8 +81,12 @@ var Lorem = function (faker) {
* @param {string} separator defaults to `' '`
*/
self.sentences = function (sentenceCount, separator) {
- if (typeof sentenceCount === 'undefined') { sentenceCount = faker.datatype.number({ min: 2, max: 6 });}
- if (typeof separator == 'undefined') { separator = " "; }
+ if (typeof sentenceCount === 'undefined') {
+ sentenceCount = faker.datatype.number({ min: 2, max: 6 });
+ }
+ if (typeof separator == 'undefined') {
+ separator = ' ';
+ }
var sentences = [];
for (sentenceCount; sentenceCount > 0; sentenceCount--) {
sentences.push(faker.lorem.sentence());
@@ -92,7 +101,9 @@ var Lorem = function (faker) {
* @param {number} sentenceCount defaults to 3
*/
self.paragraph = function (sentenceCount) {
- if (typeof sentenceCount == 'undefined') { sentenceCount = 3; }
+ if (typeof sentenceCount == 'undefined') {
+ sentenceCount = 3;
+ }
return faker.lorem.sentences(sentenceCount + faker.datatype.number(3));
};
@@ -104,16 +115,18 @@ var Lorem = function (faker) {
* @param {string} separator defaults to `'\n \r'`
*/
self.paragraphs = function (paragraphCount, separator) {
- if (typeof separator === "undefined") {
- separator = "\n \r";
+ if (typeof separator === 'undefined') {
+ separator = '\n \r';
+ }
+ if (typeof paragraphCount == 'undefined') {
+ paragraphCount = 3;
}
- if (typeof paragraphCount == 'undefined') { paragraphCount = 3; }
var paragraphs = [];
for (paragraphCount; paragraphCount > 0; paragraphCount--) {
paragraphs.push(faker.lorem.paragraph());
}
return paragraphs.join(separator);
- }
+ };
/**
* returns random text based on a random lorem method
@@ -121,8 +134,16 @@ var Lorem = function (faker) {
* @method faker.lorem.text
* @param {number} times
*/
- self.text = function loremText (times) {
- var loremMethods = ['lorem.word', 'lorem.words', 'lorem.sentence', 'lorem.sentences', 'lorem.paragraph', 'lorem.paragraphs', 'lorem.lines'];
+ self.text = function loremText(times) {
+ var loremMethods = [
+ 'lorem.word',
+ 'lorem.words',
+ 'lorem.sentence',
+ 'lorem.sentences',
+ 'lorem.paragraph',
+ 'lorem.paragraphs',
+ 'lorem.lines',
+ ];
var randomLoremMethod = faker.random.arrayElement(loremMethods);
return faker.fake('{{' + randomLoremMethod + '}}');
};
@@ -133,13 +154,14 @@ var Lorem = function (faker) {
* @method faker.lorem.lines
* @param {number} lineCount defaults to a random number between 1 and 5
*/
- self.lines = function lines (lineCount) {
- if (typeof lineCount === 'undefined') { lineCount = faker.datatype.number({ min: 1, max: 5 });}
- return faker.lorem.sentences(lineCount, '\n')
+ self.lines = function lines(lineCount) {
+ if (typeof lineCount === 'undefined') {
+ lineCount = faker.datatype.number({ min: 1, max: 5 });
+ }
+ return faker.lorem.sentences(lineCount, '\n');
};
return self;
};
-
-module["exports"] = Lorem;
+module['exports'] = Lorem;
diff --git a/lib/mersenne.js b/lib/mersenne.js
index 722ebc46..ad44eac0 100644
--- a/lib/mersenne.js
+++ b/lib/mersenne.js
@@ -2,30 +2,29 @@ var Gen = require('../vendor/mersenne').MersenneTwister19937;
function Mersenne() {
var gen = new Gen();
- gen.init_genrand((new Date).getTime() % 1000000000);
+ gen.init_genrand(new Date().getTime() % 1000000000);
- this.rand = function(max, min) {
- if (max === undefined)
- {
+ this.rand = function (max, min) {
+ if (max === undefined) {
min = 0;
max = 32768;
}
return Math.floor(gen.genrand_real2() * (max - min) + min);
- }
- this.seed = function(S) {
- if (typeof(S) != 'number')
- {
- throw new Error("seed(S) must take numeric argument; is " + typeof(S));
+ };
+ this.seed = function (S) {
+ if (typeof S != 'number') {
+ throw new Error('seed(S) must take numeric argument; is ' + typeof S);
}
gen.init_genrand(S);
- }
- this.seed_array = function(A) {
- if (typeof(A) != 'object')
- {
- throw new Error("seed_array(A) must take array of numbers; is " + typeof(A));
+ };
+ this.seed_array = function (A) {
+ if (typeof A != 'object') {
+ throw new Error(
+ 'seed_array(A) must take array of numbers; is ' + typeof A
+ );
}
gen.init_by_array(A, A.length);
- }
+ };
}
module.exports = Mersenne;
diff --git a/lib/music.js b/lib/music.js
index bad92d96..1dd5b03b 100644
--- a/lib/music.js
+++ b/lib/music.js
@@ -5,18 +5,18 @@
var Music = function (faker) {
var self = this;
/**
- * genre
- *
- * @method faker.music.genre
- */
+ * genre
+ *
+ * @method faker.music.genre
+ */
self.genre = function () {
return faker.random.arrayElement(faker.definitions.music.genre);
};
self.genre.schema = {
- "description": "Generates a genre.",
- "sampleResults": ["Rock", "Metal", "Pop"]
+ description: 'Generates a genre.',
+ sampleResults: ['Rock', 'Metal', 'Pop'],
};
};
-module["exports"] = Music;
+module['exports'] = Music;
diff --git a/lib/name.js b/lib/name.js
index a8ad32a7..480cd6c3 100644
--- a/lib/name.js
+++ b/lib/name.js
@@ -2,8 +2,7 @@
*
* @namespace faker.name
*/
-function Name (faker) {
-
+function Name(faker) {
/**
* firstName
*
@@ -12,32 +11,37 @@ function Name (faker) {
* @memberof faker.name
*/
this.firstName = function (gender) {
- if (typeof faker.definitions.name.male_first_name !== "undefined" && typeof faker.definitions.name.female_first_name !== "undefined") {
+ if (
+ typeof faker.definitions.name.male_first_name !== 'undefined' &&
+ typeof faker.definitions.name.female_first_name !== 'undefined'
+ ) {
// some locale datasets ( like ru ) have first_name split by gender. since the name.first_name field does not exist in these datasets,
// we must randomly pick a name from either gender array so faker.name.firstName will return the correct locale data ( and not fallback )
- if(typeof gender === 'string') {
- if(gender.toLowerCase() === 'male') {
+ if (typeof gender === 'string') {
+ if (gender.toLowerCase() === 'male') {
gender = 0;
- }
- else if(gender.toLowerCase() === 'female') {
+ } else if (gender.toLowerCase() === 'female') {
gender = 1;
}
}
if (typeof gender !== 'number') {
- if(typeof faker.definitions.name.first_name === "undefined") {
+ if (typeof faker.definitions.name.first_name === 'undefined') {
gender = faker.datatype.number(1);
- }
- else {
+ } else {
//Fall back to non-gendered names if they exist and gender wasn't specified
return faker.random.arrayElement(faker.definitions.name.first_name);
}
}
if (gender === 0) {
- return faker.random.arrayElement(faker.definitions.name.male_first_name)
+ return faker.random.arrayElement(
+ faker.definitions.name.male_first_name
+ );
} else {
- return faker.random.arrayElement(faker.definitions.name.female_first_name);
+ return faker.random.arrayElement(
+ faker.definitions.name.female_first_name
+ );
}
}
return faker.random.arrayElement(faker.definitions.name.first_name);
@@ -51,16 +55,23 @@ function Name (faker) {
* @memberof faker.name
*/
this.lastName = function (gender) {
- if (typeof faker.definitions.name.male_last_name !== "undefined" && typeof faker.definitions.name.female_last_name !== "undefined") {
+ if (
+ typeof faker.definitions.name.male_last_name !== 'undefined' &&
+ typeof faker.definitions.name.female_last_name !== 'undefined'
+ ) {
// some locale datasets ( like ru ) have last_name split by gender. i have no idea how last names can have genders, but also i do not speak russian
// see above comment of firstName method
if (typeof gender !== 'number') {
gender = faker.datatype.number(1);
}
if (gender === 0) {
- return faker.random.arrayElement(faker.locales[faker.locale].name.male_last_name);
+ return faker.random.arrayElement(
+ faker.locales[faker.locale].name.male_last_name
+ );
} else {
- return faker.random.arrayElement(faker.locales[faker.locale].name.female_last_name);
+ return faker.random.arrayElement(
+ faker.locales[faker.locale].name.female_last_name
+ );
}
}
return faker.random.arrayElement(faker.definitions.name.last_name);
@@ -74,14 +85,21 @@ function Name (faker) {
* @memberof faker.name
*/
this.middleName = function (gender) {
- if (typeof faker.definitions.name.male_middle_name !== "undefined" && typeof faker.definitions.name.female_middle_name !== "undefined") {
+ if (
+ typeof faker.definitions.name.male_middle_name !== 'undefined' &&
+ typeof faker.definitions.name.female_middle_name !== 'undefined'
+ ) {
if (typeof gender !== 'number') {
gender = faker.datatype.number(1);
}
if (gender === 0) {
- return faker.random.arrayElement(faker.locales[faker.locale].name.male_middle_name);
+ return faker.random.arrayElement(
+ faker.locales[faker.locale].name.male_middle_name
+ );
} else {
- return faker.random.arrayElement(faker.locales[faker.locale].name.female_middle_name);
+ return faker.random.arrayElement(
+ faker.locales[faker.locale].name.female_middle_name
+ );
}
}
return faker.random.arrayElement(faker.definitions.name.middle_name);
@@ -110,16 +128,16 @@ function Name (faker) {
case 0:
prefix = faker.name.prefix(gender);
if (prefix) {
- return prefix + " " + firstName + " " + lastName;
+ return prefix + ' ' + firstName + ' ' + lastName;
}
case 1:
suffix = faker.name.suffix(gender);
if (suffix) {
- return firstName + " " + lastName + " " + suffix;
+ return firstName + ' ' + lastName + ' ' + suffix;
}
}
- return firstName + " " + lastName;
+ return firstName + ' ' + lastName;
};
/**
@@ -129,9 +147,13 @@ function Name (faker) {
* @memberof faker.name
*/
this.jobTitle = function () {
- return faker.name.jobDescriptor() + " " +
- faker.name.jobArea() + " " +
- faker.name.jobType();
+ return (
+ faker.name.jobDescriptor() +
+ ' ' +
+ faker.name.jobArea() +
+ ' ' +
+ faker.name.jobType()
+ );
};
/**
@@ -146,8 +168,8 @@ function Name (faker) {
} else {
return faker.random.arrayElement(faker.definitions.name.gender);
}
- }
-
+ };
+
/**
* prefix
*
@@ -156,14 +178,21 @@ function Name (faker) {
* @memberof faker.name
*/
this.prefix = function (gender) {
- if (typeof faker.definitions.name.male_prefix !== "undefined" && typeof faker.definitions.name.female_prefix !== "undefined") {
+ if (
+ typeof faker.definitions.name.male_prefix !== 'undefined' &&
+ typeof faker.definitions.name.female_prefix !== 'undefined'
+ ) {
if (typeof gender !== 'number') {
gender = faker.datatype.number(1);
}
if (gender === 0) {
- return faker.random.arrayElement(faker.locales[faker.locale].name.male_prefix);
+ return faker.random.arrayElement(
+ faker.locales[faker.locale].name.male_prefix
+ );
} else {
- return faker.random.arrayElement(faker.locales[faker.locale].name.female_prefix);
+ return faker.random.arrayElement(
+ faker.locales[faker.locale].name.female_prefix
+ );
}
}
return faker.random.arrayElement(faker.definitions.name.prefix);
@@ -185,12 +214,14 @@ function Name (faker) {
* @method title
* @memberof faker.name
*/
- this.title = function() {
- var descriptor = faker.random.arrayElement(faker.definitions.name.title.descriptor),
- level = faker.random.arrayElement(faker.definitions.name.title.level),
- job = faker.random.arrayElement(faker.definitions.name.title.job);
+ this.title = function () {
+ var descriptor = faker.random.arrayElement(
+ faker.definitions.name.title.descriptor
+ ),
+ level = faker.random.arrayElement(faker.definitions.name.title.level),
+ job = faker.random.arrayElement(faker.definitions.name.title.job);
- return descriptor + " " + level + " " + job;
+ return descriptor + ' ' + level + ' ' + job;
};
/**
@@ -222,7 +253,6 @@ function Name (faker) {
this.jobType = function () {
return faker.random.arrayElement(faker.definitions.name.title.job);
};
-
}
module['exports'] = Name;
diff --git a/lib/phone_number.js b/lib/phone_number.js
index d0b97a72..891c3933 100644
--- a/lib/phone_number.js
+++ b/lib/phone_number.js
@@ -27,7 +27,9 @@ var Phone = function (faker) {
*/
self.phoneNumberFormat = function (phoneFormatsArrayIndex) {
phoneFormatsArrayIndex = phoneFormatsArrayIndex || 0;
- return faker.helpers.replaceSymbolWithNumber(faker.definitions.phone_number.formats[phoneFormatsArrayIndex]);
+ return faker.helpers.replaceSymbolWithNumber(
+ faker.definitions.phone_number.formats[phoneFormatsArrayIndex]
+ );
};
/**
@@ -38,9 +40,8 @@ var Phone = function (faker) {
self.phoneFormats = function () {
return faker.random.arrayElement(faker.definitions.phone_number.formats);
};
-
- return self;
+ return self;
};
module['exports'] = Phone;
diff --git a/lib/random.js b/lib/random.js
index 4443c555..0e43a338 100644
--- a/lib/random.js
+++ b/lib/random.js
@@ -5,8 +5,8 @@
* @return {*} new array without banned characters
*/
var arrayRemove = function (arr, values) {
- values.forEach(function(value){
- arr = arr.filter(function(ele){
+ values.forEach(function (value) {
+ arr = arr.filter(function (ele) {
return ele !== value;
});
});
@@ -17,12 +17,11 @@ var arrayRemove = function (arr, values) {
*
* @namespace faker.random
*/
-function Random (faker, seed) {
+function Random(faker, seed) {
// Use a user provided seed if it is an array or number
if (Array.isArray(seed) && seed.length) {
faker.mersenne.seed_array(seed);
- }
- else if(!isNaN(seed)) {
+ } else if (!isNaN(seed)) {
faker.mersenne.seed(seed);
}
@@ -34,7 +33,9 @@ function Random (faker, seed) {
* @param {mixed} options {min, max, precision}
*/
this.number = function (options) {
- console.log("Deprecation Warning: faker.random.number is now located in faker.datatype.number");
+ console.log(
+ 'Deprecation Warning: faker.random.number is now located in faker.datatype.number'
+ );
return faker.datatype.number(options);
};
@@ -46,7 +47,9 @@ function Random (faker, seed) {
* @param {mixed} options
*/
this.float = function (options) {
- console.log("Deprecation Warning: faker.random.float is now located in faker.datatype.float");
+ console.log(
+ 'Deprecation Warning: faker.random.float is now located in faker.datatype.float'
+ );
return faker.datatype.float(options);
};
@@ -57,7 +60,7 @@ function Random (faker, seed) {
* @param {array} array
*/
this.arrayElement = function (array) {
- array = array || ["a", "b", "c"];
+ array = array || ['a', 'b', 'c'];
var r = faker.datatype.number({ max: array.length - 1 });
return array[r];
};
@@ -70,7 +73,7 @@ function Random (faker, seed) {
* @param {number} count number of elements to pick
*/
this.arrayElements = function (array, count) {
- array = array || ["a", "b", "c"];
+ array = array || ['a', 'b', 'c'];
if (typeof count !== 'number') {
count = faker.datatype.number({ min: 1, max: array.length });
@@ -104,11 +107,11 @@ function Random (faker, seed) {
* @param {mixed} field
*/
this.objectElement = function (object, field) {
- object = object || { "foo": "bar", "too": "car" };
+ object = object || { foo: 'bar', too: 'car' };
var array = Object.keys(object);
var key = faker.random.arrayElement(array);
- return field === "key" ? key : object[key];
+ return field === 'key' ? key : object[key];
};
/**
@@ -118,7 +121,9 @@ function Random (faker, seed) {
* @method faker.random.uuid
*/
this.uuid = function () {
- console.log("Deprecation Warning: faker.random.uuid is now located in faker.datatype.uuid");
+ console.log(
+ 'Deprecation Warning: faker.random.uuid is now located in faker.datatype.uuid'
+ );
return faker.datatype.uuid();
};
@@ -128,7 +133,9 @@ function Random (faker, seed) {
* @method faker.random.boolean
*/
this.boolean = function () {
- console.log("Deprecation Warning: faker.random.boolean is now located in faker.datatype.boolean");
+ console.log(
+ 'Deprecation Warning: faker.random.boolean is now located in faker.datatype.boolean'
+ );
return faker.datatype.boolean();
};
@@ -139,8 +146,7 @@ function Random (faker, seed) {
* @method faker.random.word
* @param {string} type
*/
- this.word = function randomWord (type) {
-
+ this.word = function randomWord(type) {
var wordMethods = [
'commerce.department',
'commerce.productName',
@@ -172,7 +178,8 @@ function Random (faker, seed) {
'name.jobDescriptor',
'name.jobArea',
- 'name.jobType'];
+ 'name.jobType',
+ ];
// randomly pick from the many faker methods that can generate words
var randomWordMethod = faker.random.arrayElement(wordMethods);
@@ -186,12 +193,12 @@ function Random (faker, seed) {
* @method faker.random.words
* @param {number} count defaults to a random value between 1 and 3
*/
- this.words = function randomWords (count) {
+ this.words = function randomWords(count) {
var words = [];
- if (typeof count === "undefined") {
- count = faker.datatype.number({min:1, max: 3});
+ if (typeof count === 'undefined') {
+ count = faker.datatype.number({ min: 1, max: 3 });
}
- for (var i = 0; i<count; i++) {
+ for (var i = 0; i < count; i++) {
words.push(faker.random.word());
}
return words.join(' ');
@@ -202,7 +209,7 @@ function Random (faker, seed) {
*
* @method faker.random.image
*/
- this.image = function randomImage () {
+ this.image = function randomImage() {
return faker.image.image();
};
@@ -211,7 +218,7 @@ function Random (faker, seed) {
*
* @method faker.random.locale
*/
- this.locale = function randomLocale () {
+ this.locale = function randomLocale() {
return faker.random.arrayElement(Object.keys(faker.locales));
};
@@ -222,36 +229,63 @@ function Random (faker, seed) {
* @param {mixed} options // defaults to { count: 1, upcase: false, bannedChars: [] }
*/
this.alpha = function alpha(options) {
- if (typeof options === "undefined") {
+ if (typeof options === 'undefined') {
options = {
- count: 1
+ count: 1,
};
- } else if (typeof options === "number") {
+ } else if (typeof options === 'number') {
options = {
count: options,
};
- } else if (typeof options.count === "undefined") {
+ } else if (typeof options.count === 'undefined') {
options.count = 1;
}
- if (typeof options.upcase === "undefined") {
+ if (typeof options.upcase === 'undefined') {
options.upcase = false;
}
- if (typeof options.bannedChars ==="undefined"){
+ if (typeof options.bannedChars === 'undefined') {
options.bannedChars = [];
}
- var wholeString = "";
- var charsArray = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
- if(options.bannedChars){
- charsArray = arrayRemove(charsArray,options.bannedChars);
+ var wholeString = '';
+ var charsArray = [
+ 'a',
+ 'b',
+ 'c',
+ 'd',
+ 'e',
+ 'f',
+ 'g',
+ 'h',
+ 'i',
+ 'j',
+ 'k',
+ 'l',
+ 'm',
+ 'n',
+ 'o',
+ 'p',
+ 'q',
+ 'r',
+ 's',
+ 't',
+ 'u',
+ 'v',
+ 'w',
+ 'x',
+ 'y',
+ 'z',
+ ];
+ if (options.bannedChars) {
+ charsArray = arrayRemove(charsArray, options.bannedChars);
}
- for(var i = 0; i < options.count; i++) {
+ for (var i = 0; i < options.count; i++) {
wholeString += faker.random.arrayElement(charsArray);
}
return options.upcase ? wholeString.toUpperCase() : wholeString;
- }
+ };
/**
* alphaNumeric
@@ -262,24 +296,61 @@ function Random (faker, seed) {
* options.bannedChars - array of characters which should be banned in new string
*/
this.alphaNumeric = function alphaNumeric(count, options) {
- if (typeof count === "undefined") {
+ if (typeof count === 'undefined') {
count = 1;
}
- if (typeof options ==="undefined"){
+ if (typeof options === 'undefined') {
options = {};
}
- if (typeof options.bannedChars ==="undefined"){
+ if (typeof options.bannedChars === 'undefined') {
options.bannedChars = [];
}
- var wholeString = "";
- var charsArray = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
- if(options) {
+ var wholeString = '';
+ var charsArray = [
+ '0',
+ '1',
+ '2',
+ '3',
+ '4',
+ '5',
+ '6',
+ '7',
+ '8',
+ '9',
+ 'a',
+ 'b',
+ 'c',
+ 'd',
+ 'e',
+ 'f',
+ 'g',
+ 'h',
+ 'i',
+ 'j',
+ 'k',
+ 'l',
+ 'm',
+ 'n',
+ 'o',
+ 'p',
+ 'q',
+ 'r',
+ 's',
+ 't',
+ 'u',
+ 'v',
+ 'w',
+ 'x',
+ 'y',
+ 'z',
+ ];
+ if (options) {
if (options.bannedChars) {
charsArray = arrayRemove(charsArray, options.bannedChars);
}
}
- for(var i = 0; i < count; i++) {
+ for (var i = 0; i < count; i++) {
wholeString += faker.random.arrayElement(charsArray);
}
@@ -294,12 +365,13 @@ function Random (faker, seed) {
* @param {number} count defaults to 1
*/
this.hexaDecimal = function hexaDecimal(count) {
- console.log("Deprecation Warning: faker.random.hexaDecimal is now located in faker.datatype.hexaDecimal");
+ console.log(
+ 'Deprecation Warning: faker.random.hexaDecimal is now located in faker.datatype.hexaDecimal'
+ );
return faker.datatype.hexaDecimal(count);
};
return this;
-
}
module['exports'] = Random;
diff --git a/lib/system.js b/lib/system.js
index 7d9552e5..0d2969dd 100644
--- a/lib/system.js
+++ b/lib/system.js
@@ -1,28 +1,24 @@
// generates fake data for many computer systems properties
-var commonFileTypes = [
- "video",
- "audio",
- "image",
- "text",
- "application"
-];
+var commonFileTypes = ['video', 'audio', 'image', 'text', 'application'];
var commonMimeTypes = [
- "application/pdf",
- "audio/mpeg",
- "audio/wav",
- "image/png",
- "image/jpeg",
- "image/gif",
- "video/mp4",
- "video/mpeg",
- "text/html"
+ 'application/pdf',
+ 'audio/mpeg',
+ 'audio/wav',
+ 'image/png',
+ 'image/jpeg',
+ 'image/gif',
+ 'video/mp4',
+ 'video/mpeg',
+ 'text/html',
];
function setToArray(set) {
// shortcut if Array.from is available
- if (Array.from) { return Array.from(set); }
+ if (Array.from) {
+ return Array.from(set);
+ }
var array = [];
set.forEach(function (item) {
@@ -36,17 +32,14 @@ function setToArray(set) {
* @namespace faker.system
*/
function System(faker) {
-
/**
* generates a file name
*
* @method faker.system.fileName
*/
this.fileName = function () {
- var str = faker.random.words();
- str = str
- .toLowerCase()
- .replace(/\W/g, "_") + "." + faker.system.fileExt();;
+ var str = faker.random.words();
+ str = str.toLowerCase().replace(/\W/g, '_') + '.' + faker.system.fileExt();
return str;
};
@@ -58,10 +51,8 @@ function System(faker) {
*/
this.commonFileName = function (ext) {
var str = faker.random.words();
- str = str
- .toLowerCase()
- .replace(/\W/g, "_");
- str += "." + (ext || faker.system.commonFileExt());
+ str = str.toLowerCase().replace(/\W/g, '_');
+ str += '.' + (ext || faker.system.commonFileExt());
return str;
};
@@ -76,7 +67,7 @@ function System(faker) {
var mimeTypes = faker.definitions.system.mimeTypes;
Object.keys(mimeTypes).forEach(function (m) {
- var type = m.split("/")[0];
+ var type = m.split('/')[0];
typeSet.add(type);
@@ -112,7 +103,6 @@ function System(faker) {
return faker.system.fileExt(faker.random.arrayElement(commonMimeTypes));
};
-
/**
* returns any file type available as mime-type
*
@@ -124,7 +114,7 @@ function System(faker) {
var mimeTypes = faker.definitions.system.mimeTypes;
Object.keys(mimeTypes).forEach(function (m) {
- var type = m.split("/")[0];
+ var type = m.split('/')[0];
typeSet.add(type);
@@ -139,7 +129,6 @@ function System(faker) {
var extensions = setToArray(extensionSet);
var mimeTypeKeys = Object.keys(faker.definitions.system.mimeTypes);
return faker.random.arrayElement(types);
-
};
/**
@@ -154,7 +143,7 @@ function System(faker) {
var mimeTypes = faker.definitions.system.mimeTypes;
Object.keys(mimeTypes).forEach(function (m) {
- var type = m.split("/")[0];
+ var type = m.split('/')[0];
typeSet.add(type);
@@ -183,7 +172,7 @@ function System(faker) {
* @method faker.system.directoryPath
*/
this.directoryPath = function () {
- var paths = faker.definitions.system.directoryPaths
+ var paths = faker.definitions.system.directoryPaths;
return faker.random.arrayElement(paths);
};
@@ -193,7 +182,9 @@ function System(faker) {
* @method faker.system.filePath
*/
this.filePath = function () {
- return faker.fake("{{system.directoryPath}}/{{system.fileName}}.{{system.fileExt}}");
+ return faker.fake(
+ '{{system.directoryPath}}/{{system.fileName}}.{{system.fileExt}}'
+ );
};
/**
@@ -202,11 +193,12 @@ function System(faker) {
* @method faker.system.semver
*/
this.semver = function () {
- return [faker.datatype.number(9),
+ return [
faker.datatype.number(9),
- faker.datatype.number(9)].join('.');
- }
-
+ faker.datatype.number(9),
+ faker.datatype.number(9),
+ ].join('.');
+ };
}
module['exports'] = System;
diff --git a/lib/time.js b/lib/time.js
index 1739c237..b3e5bfe7 100644
--- a/lib/time.js
+++ b/lib/time.js
@@ -2,7 +2,7 @@
*
* @namespace faker.time
*/
-var _Time = function(faker) {
+var _Time = function (faker) {
var self = this;
/**
@@ -11,20 +11,20 @@ var _Time = function(faker) {
* @method faker.time.recent
* @param {string} outputType - 'abbr' || 'wide' || 'unix' (default choice)
*/
- self.recent = function(outputType) {
- if (typeof outputType === "undefined") {
+ self.recent = function (outputType) {
+ if (typeof outputType === 'undefined') {
outputType = 'unix';
}
var date = new Date();
switch (outputType) {
- case "abbr":
+ case 'abbr':
date = date.toLocaleTimeString();
break;
- case "wide":
+ case 'wide':
date = date.toTimeString();
break;
- case "unix":
+ case 'unix':
date = date.getTime();
break;
}
@@ -34,4 +34,4 @@ var _Time = function(faker) {
return self;
};
-module["exports"] = _Time;
+module['exports'] = _Time;
diff --git a/lib/unique.js b/lib/unique.js
index 10b02bd5..b78629d1 100644
--- a/lib/unique.js
+++ b/lib/unique.js
@@ -3,8 +3,7 @@ var uniqueExec = require('../vendor/unique');
*
* @namespace faker.unique
*/
-function Unique (faker) {
-
+function Unique(faker) {
// initialize unique module class variables
// maximum time unique.exec will attempt to run before aborting
@@ -21,7 +20,7 @@ function Unique (faker) {
*
* @method unique
*/
- this.unique = function unique (method, args, opts) {
+ this.unique = function unique(method, args, opts) {
opts = opts || {};
opts.startTime = new Date().getTime();
if (typeof opts.maxTime !== 'number') {
@@ -32,7 +31,7 @@ function Unique (faker) {
}
opts.currentIterations = 0;
return uniqueExec.exec(method, args, opts);
- }
+ };
}
-module['exports'] = Unique; \ No newline at end of file
+module['exports'] = Unique;
diff --git a/lib/vehicle.js b/lib/vehicle.js
index 848ac209..816d620e 100644
--- a/lib/vehicle.js
+++ b/lib/vehicle.js
@@ -16,8 +16,8 @@ var Vehicle = function (faker) {
};
self.vehicle.schema = {
- "description": "Generates a random vehicle.",
- "sampleResults": ["BMW Explorer", "Ford Camry", "Lamborghini Ranchero"]
+ description: 'Generates a random vehicle.',
+ sampleResults: ['BMW Explorer', 'Ford Camry', 'Lamborghini Ranchero'],
};
/**
@@ -30,11 +30,10 @@ var Vehicle = function (faker) {
};
self.manufacturer.schema = {
- "description": "Generates a manufacturer name.",
- "sampleResults": ["Ford", "Jeep", "Tesla"]
+ description: 'Generates a manufacturer name.',
+ sampleResults: ['Ford', 'Jeep', 'Tesla'],
};
-
/**
* model
*
@@ -45,8 +44,8 @@ var Vehicle = function (faker) {
};
self.model.schema = {
- "description": "Generates a vehicle model.",
- "sampleResults": ["Explorer", "Camry", "Ranchero"]
+ description: 'Generates a vehicle model.',
+ sampleResults: ['Explorer', 'Camry', 'Ranchero'],
};
/**
@@ -59,8 +58,8 @@ var Vehicle = function (faker) {
};
self.type.schema = {
- "description": "Generates a vehicle type.",
- "sampleResults": ["Coupe", "Convertable", "Sedan", "SUV"]
+ description: 'Generates a vehicle type.',
+ sampleResults: ['Coupe', 'Convertable', 'Sedan', 'SUV'],
};
/**
@@ -73,8 +72,8 @@ var Vehicle = function (faker) {
};
self.fuel.schema = {
- "description": "Generates a fuel type.",
- "sampleResults": ["Electric", "Gasoline", "Diesel"]
+ description: 'Generates a fuel type.',
+ sampleResults: ['Electric', 'Gasoline', 'Diesel'],
};
/**
@@ -83,18 +82,19 @@ var Vehicle = function (faker) {
* @method faker.vehicle.vin
*/
self.vin = function () {
- var bannedChars=['o','i','q'];
+ var bannedChars = ['o', 'i', 'q'];
return (
- faker.random.alphaNumeric(10, {bannedChars:bannedChars}) +
- faker.random.alpha({ count: 1, upcase: true ,bannedChars:bannedChars}) +
- faker.random.alphaNumeric(1, {bannedChars:bannedChars}) +
- faker.datatype.number({ min: 10000, max: 100000}) // return five digit #
- ).toUpperCase();
+ faker.random.alphaNumeric(10, { bannedChars: bannedChars }) +
+ faker.random.alpha({ count: 1, upcase: true, bannedChars: bannedChars }) +
+ faker.random.alphaNumeric(1, { bannedChars: bannedChars }) +
+ faker.datatype.number({ min: 10000, max: 100000 })
+ ) // return five digit #
+ .toUpperCase();
};
self.vin.schema = {
- "description": "Generates a valid VIN number.",
- "sampleResults": ["YV1MH682762184654", "3C7WRMBJ2EG208836"]
+ description: 'Generates a valid VIN number.',
+ sampleResults: ['YV1MH682762184654', '3C7WRMBJ2EG208836'],
};
/**
@@ -107,42 +107,46 @@ var Vehicle = function (faker) {
};
self.color.schema = {
- "description": "Generates a color",
- "sampleResults": ["red", "white", "black"]
+ description: 'Generates a color',
+ sampleResults: ['red', 'white', 'black'],
};
/**
- * vrm
- *
- * @method faker.vehicle.vrm
- */
+ * vrm
+ *
+ * @method faker.vehicle.vrm
+ */
self.vrm = function () {
return (
faker.random.alpha({ count: 2, upcase: true }) +
- faker.datatype.number({ min: 0, max: 9 }) +
- faker.datatype.number({ min: 0, max: 9 }) +
- faker.random.alpha({ count: 3, upcase: true })
+ faker.datatype.number({ min: 0, max: 9 }) +
+ faker.datatype.number({ min: 0, max: 9 }) +
+ faker.random.alpha({ count: 3, upcase: true })
).toUpperCase();
};
self.vrm.schema = {
- "description": "Generates a vehicle vrm",
- "sampleResults": ["MF56UPA", "GL19AAQ", "SF20TTA"]
+ description: 'Generates a vehicle vrm',
+ sampleResults: ['MF56UPA', 'GL19AAQ', 'SF20TTA'],
};
/**
- * bicycle
- *
- * @method faker.vehicle.bicycle
- */
+ * bicycle
+ *
+ * @method faker.vehicle.bicycle
+ */
self.bicycle = function () {
return faker.random.arrayElement(faker.definitions.vehicle.bicycle_type);
};
self.bicycle.schema = {
- "description": "Generates a type of bicycle",
- "sampleResults": ["Adventure Road Bicycle", "City Bicycle", "Recumbent Bicycle"]
+ description: 'Generates a type of bicycle',
+ sampleResults: [
+ 'Adventure Road Bicycle',
+ 'City Bicycle',
+ 'Recumbent Bicycle',
+ ],
};
};
-module["exports"] = Vehicle;
+module['exports'] = Vehicle;
diff --git a/lib/word.js b/lib/word.js
index 0040ae4a..ea89f4ad 100644
--- a/lib/word.js
+++ b/lib/word.js
@@ -168,4 +168,4 @@ var Word = function (faker) {
return self;
};
-module["exports"] = Word;
+module['exports'] = Word;