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

faker

Package Overview
Dependencies
Maintainers
2
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

faker - npm Package Compare versions

Comparing version 1.1.0 to 2.0.1

bower.json

33

CHANGELOG.md

@@ -1,5 +0,34 @@

=CHANGELOG
#CHANGELOG
==v1.1.1
## v2.0.0
* Adds i18n internalization of fake data sets
- contributed by Marak
* Reduces surface of API, removes redundant API calls
- contributed by Marak
* Replaces legacy build system with GulpJS
- contributed by Marak
* Replaces legacy browserifying system with Browserify
- contributed by Marak
* Adds basic financial generators
- contributed by josefsalyer
* Adds internet.userAgent using `random-ua` library
- contributed by Marak
* Adds currency codes and symbols using `random-ua` library
- contributed by MQuy
* Replaces use of Math.random in favor of `node-mersenne` package
- contributed by Marak
* Adds bower support
- contributed by daytonn
* avatarUrl optimization
- contributed by MQuy
* Fix - Remove `this` scope
- contributed by goliatone
* Fix - IE9 charAt() bug
- contributed by beastlike
* Fix - faker.date now returns a Date object instead of JSON
- contributed by Marak
##v1.1.0
* Fixes random date functions that did not distribute results.

@@ -6,0 +35,0 @@ - contributed by pmalouin

2

examples/library_test.js

@@ -7,4 +7,4 @@ var util = require('util');

var card = faker.Helpers.createCard();
var card = faker.helpers.createCard();
util.puts(JSON.stringify(card));

@@ -8,3 +8,3 @@ var sys = require('sys')

// generate dataSet as example
fs.writeFile('../examples/dataSet.json', JSON.stringify(faker.Helpers.userCard()), function() {
fs.writeFile('../examples/dataSet.json', JSON.stringify(faker.helpers.userCard()), function() {
sys.puts("dataSet generated successfully!");

@@ -16,3 +16,3 @@ });

for(i = 20; i >= 0; i--){
bigSet.push(faker.Helpers.userCard());
bigSet.push(faker.helpers.userCard());
};

@@ -19,0 +19,0 @@

@@ -5,6 +5,65 @@ #!/usr/bin/env node

var faker = require('../faker');
var faker = require('../index');
var card = faker.Helpers.createCard();
// console.log(faker.definitions.name.suffix)
util.puts(JSON.stringify(card));
//util.puts(JSON.stringify(card));
faker.locale = "en_CA";
console.log(faker.address.zipCode())
return;
var image = faker.image.image();
console.log(image);
return;
var first = faker.name.firstName(),
last = faker.name.lastName();
console.log(first, last)
console.log(faker.name.findName(first, last))
console.log(faker.internet.userName(first, last))
return;
var phone_number = faker.phone.phoneNumber("(###) ###-####");
console.log(phone_number)
return;
console.log(faker.address.state_abbr())
return;
console.log(faker.helpers.contextualCard())
console.log(faker.helpers.createCard())
return;
console.log(faker.lorem.words())
console.log(faker.name.firstName() + " " + faker.name.lastName())
console.log(faker.name.firstName() + " " + faker.name.lastName())
console.log(faker.name.firstName() + " " + faker.name.lastName())
return;
/*
faker.locale = "zh_CN";
console.log(faker.name.firstName() + " " + faker.name.lastName())
console.log(faker.name.firstName() + " " + faker.name.lastName())
console.log(faker.name.firstName() + " " + faker.name.lastName())
*/
return;
var phone_number = faker.finance.transactionType();
console.log(phone_number)
console.log(faker.definitions)
var phone_number = faker.company.catchPhrase();

@@ -8,3 +8,3 @@ /*

var faker = require(./faker);
var randomName = faker.Name.findName();
var randomName = faker.name.findName();

@@ -14,3 +14,3 @@ you can also simply include the "faker.js" file which is the auto-generated bundled version of the faker library

var faker = require(./customAppPath/faker);
var randomName = faker.Name.findName();
var randomName = faker.name.findName();

@@ -22,13 +22,55 @@

exports.Name = require('./lib/name');
exports.Address = require('./lib/address');
exports.PhoneNumber = require('./lib/phone_number');
exports.Internet = require('./lib/internet');
exports.Company = require('./lib/company');
exports.Image = require('./lib/image');
exports.Lorem = require('./lib/lorem');
exports.Helpers = require('./lib/helpers');
exports.Tree = require('./lib/tree');
exports.Date = require('./lib/date');
exports.name = require('./lib/name');
exports.address = require('./lib/address');
exports.phone = require('./lib/phone_number');
exports.internet = require('./lib/internet');
exports.company = require('./lib/company');
exports.image = require('./lib/image');
exports.lorem = require('./lib/lorem');
exports.helpers = require('./lib/helpers');
exports.date = require('./lib/date');
exports.random = require('./lib/random');
exports.definitions = require('./lib/definitions');
exports.finance = require('./lib/finance');
exports.hacker = require('./lib/hacker');
var locales = exports.locales = require('./lib/locales');
// default locale
exports.locale = "en";
// in case a locale is missing a definition, fallback to this locale
exports.localeFallback = "en";
exports.definitions = {};
var _definitions = {
"name": ["first_name", "last_name", "prefix", "suffix"],
"address": ["city_prefix", "city_suffix", "street_suffix", "county", "country", "state", "state_abbr"],
"company": ["adjective", "noun", "descriptor", "bs_adjective", "bs_noun", "bs_verb"],
"lorem": ["words"],
"hacker": ["abbreviation", "adjective", "noun", "verb", "ingverb"],
"phone_number": ["formats"],
"finance": ["account_type", "transaction_type", "currency"],
"internet": ["avatar_uri", "domain_suffix", "free_email", "password"]
};
// Create a Getter for all definitions.foo.bar propetries
Object.keys(_definitions).forEach(function(d){
if (typeof exports.definitions[d] === "undefined") {
exports.definitions[d] = {};
}
_definitions[d].forEach(function(p){
Object.defineProperty(exports.definitions[d], p, {
get: function () {
if (typeof locales[exports.locale][d] === "undefined" || typeof locales[exports.locale][d][p] === "undefined") {
// certain localization sets contain less data then others.
// in the case of a missing defintion, use the default localeFallback to substitute the missing set data
return locales[exports.localeFallback][d][p];
} else {
// return localized data
return locales[exports.locale][d][p];
}
}
});
});
});
var Helpers = require('./helpers');
var faker = require('../index');
var definitions = require('../lib/definitions');

@@ -10,20 +9,16 @@ var address = {

zipCodeFormat: function (format) {
return Helpers.replaceSymbolWithNumber(["#####", '#####-####'][format]);
},
city: function () {
var result;
switch (faker.random.number(4)) {
switch (faker.random.number(3)) {
case 0:
result = faker.random.city_prefix() + " " + faker.random.first_name() + faker.random.city_suffix();
result = faker.address.cityPrefix() + " " + faker.name.firstName() + faker.address.citySuffix();
break;
case 1:
result = faker.random.city_prefix() + " " + faker.random.first_name();
result = faker.address.cityPrefix() + " " + faker.name.firstName();
break;
case 2:
result = faker.random.first_name() + faker.random.city_suffix();
result = faker.name.firstName() + faker.address.citySuffix();
break;
case 3:
result = faker.random.last_name() + faker.random.city_suffix();
result = faker.name.lastName() + faker.address.citySuffix();
break;

@@ -34,10 +29,18 @@ }

cityPrefix: function () {
return faker.random.array_element(faker.definitions.address.city_prefix);
},
citySuffix: function () {
return faker.random.array_element(faker.definitions.address.city_suffix);
},
streetName: function () {
var result;
switch (faker.random.number(2)) {
switch (faker.random.number(1)) {
case 0:
result = faker.random.last_name() + " " + faker.random.street_suffix();
result = faker.name.lastName() + " " + faker.address.streetSuffix();
break;
case 1:
result = faker.random.first_name() + " " + faker.random.street_suffix();
result = faker.name.firstName() + " " + faker.address.streetSuffix();
break;

@@ -54,16 +57,20 @@ }

var address = "";
switch (faker.random.number(3)) {
switch (faker.random.number(2)) {
case 0:
address = Helpers.replaceSymbolWithNumber("#####") + " " + this.streetName();
address = Helpers.replaceSymbolWithNumber("#####") + " " + faker.address.streetName();
break;
case 1:
address = Helpers.replaceSymbolWithNumber("####") + " " + this.streetName();
address = Helpers.replaceSymbolWithNumber("####") + " " + faker.address.streetName();
break;
case 2:
address = Helpers.replaceSymbolWithNumber("###") + " " + this.streetName();
address = Helpers.replaceSymbolWithNumber("###") + " " + faker.address.streetName();
break;
}
return useFullAddress ? (address + " " + this.secondaryAddress()) : address;
return useFullAddress ? (address + " " + faker.address.secondaryAddress()) : address;
},
streetSuffix: function () {
return faker.random.array_element(faker.definitions.address.street_suffix);
},
secondaryAddress: function () {

@@ -78,16 +85,16 @@ return Helpers.replaceSymbolWithNumber(faker.random.array_element(

brState: function (useAbbr) {
return useAbbr ? faker.random.br_state_abbr() : faker.random.br_state();
county: function () {
return faker.random.array_element(faker.definitions.address.county);
},
ukCounty: function () {
return faker.random.uk_county();
country: function () {
return faker.random.array_element(faker.definitions.address.country);
},
ukCountry: function () {
return faker.random.uk_country();
state: function (useAbbr) {
return faker.random.array_element(faker.definitions.address.state);
},
usState: function (useAbbr) {
return useAbbr ? faker.random.us_state_abbr() : faker.random.us_state();
stateAbbr: function () {
return faker.random.array_element(faker.definitions.address.state_abbr);
},

@@ -94,0 +101,0 @@

var faker = require('../index');
var company = {
suffixes: function () {

@@ -9,9 +10,9 @@ return ["Inc", "and Sons", "LLC", "Group", "and Daughters"];

companyName: function (format) {
switch ((format ? format : faker.random.number(3))) {
switch ((format ? format : faker.random.number(2))) {
case 0:
return faker.Name.lastName() + " " + this.companySuffix();
return faker.name.lastName() + " " + faker.company.companySuffix();
case 1:
return faker.Name.lastName() + "-" + faker.Name.lastName();
return faker.name.lastName() + "-" + faker.name.lastName();
case 2:
return faker.Name.lastName() + ", " + faker.Name.lastName() + " and " + faker.Name.lastName();
return faker.name.lastName() + ", " + faker.name.lastName() + " and " + faker.name.lastName();
}

@@ -21,18 +22,43 @@ },

companySuffix: function () {
return faker.random.array_element(this.suffixes());
return faker.random.array_element(faker.company.suffixes());
},
catchPhrase: function () {
return faker.random.catch_phrase_adjective() + " " +
faker.random.catch_phrase_descriptor() + " " +
faker.random.catch_phrase_noun();
return faker.company.catchPhraseAdjective() + " " +
faker.company.catchPhraseDescriptor() + " " +
faker.company.catchPhraseNoun();
},
bs: function () {
return faker.random.bs_adjective() + " " +
faker.random.bs_buzz() + " " +
faker.random.bs_noun();
return faker.company.bsAdjective() + " " +
faker.company.bsBuzz() + " " +
faker.company.bsNoun();
},
catchPhraseAdjective: function () {
return faker.random.array_element(faker.definitions.company.adjective);
},
catchPhraseDescriptor: function () {
return faker.random.array_element(faker.definitions.company.descriptor);
},
catchPhraseNoun: function () {
return faker.random.array_element(faker.definitions.company.noun);
},
bsAdjective: function () {
return faker.random.array_element(faker.definitions.company.bs_adjective);
},
bsBuzz: function () {
return faker.random.array_element(faker.definitions.company.bs_verb);
},
bsNoun: function () {
return faker.random.array_element(faker.definitions.company.bs_noun);
}
};
module.exports = company;

@@ -9,6 +9,6 @@ var faker = require("../index");

var past = date.getTime();
past -= faker.random.number(years) * 365 * 3600 * 1000; // some time from now to N years ago, in milliseconds
past -= faker.random.number(years) * 365 * 24 * 3600 * 1000; // some time from now to N years ago, in milliseconds
date.setTime(past);
return date.toJSON();
return date;
},

@@ -22,6 +22,6 @@

return date.toJSON();
return date;
},
between: function(from, to) {
between: function (from, to) {
var fromMilli = Date.parse(from);

@@ -32,3 +32,3 @@ var dateOffset = faker.random.number(Date.parse(to) - fromMilli);

return newDate.toJSON();
return newDate;
},

@@ -42,5 +42,5 @@

return date.toJSON();
return date;
}
};
module.exports = date;

@@ -10,2 +10,3 @@ var faker = require('../index');

exports.randomize = function (array) {
array = array || ["a", "b", "c"];
return faker.random.array_element(array);

@@ -16,2 +17,3 @@ };

exports.slugify = function (string) {
string = string || "";
return string.replace(/ /g, '-').replace(/[^\w\.\-]+/g, '');

@@ -22,2 +24,3 @@ };

exports.replaceSymbolWithNumber = function (string, symbol) {
string = string || "";
// default symbol is '#'

@@ -30,6 +33,6 @@ if (symbol === undefined) {

for (var i = 0; i < string.length; i++) {
if (string[i] == symbol) {
str += Math.floor(Math.random() * 10);
if (string.charAt(i) == symbol) {
str += faker.random.number(9);
} else {
str += string[i];
str += string.charAt(i);
}

@@ -42,77 +45,116 @@ }

exports.shuffle = function (o) {
for (var j, x, i = o.length; i; j = parseInt(Math.random() * i, 10), x = o[--i], o[i] = o[j], o[j] = x);
o = o || ["a", "b", "c"];
for (var j, x, i = o.length; i; j = faker.random.number(i), x = o[--i], o[i] = o[j], o[j] = x);
return o;
};
exports.mustache = function (str, data) {
for(var p in data) {
var re = new RegExp('{{' + p + '}}', 'g')
str = str.replace(re, data[p]);
}
return str;
};
exports.createCard = function () {
return {
"name": faker.Name.findName(),
"username": faker.Internet.userName(),
"email": faker.Internet.email(),
"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(),
"ukCounty": faker.Address.ukCounty(),
"ukCountry": faker.Address.ukCountry(),
"zipcode": faker.Address.zipCode(),
"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()
"lat": faker.address.latitude(),
"lng": faker.address.longitude()
}
},
"phone": faker.PhoneNumber.phoneNumber(),
"website": faker.Internet.domainName(),
"phone": faker.phone.phoneNumber(),
"website": faker.internet.domainName(),
"company": {
"name": faker.Company.companyName(),
"catchPhrase": faker.Company.catchPhrase(),
"bs": faker.Company.bs()
"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()
"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()]
};
};
exports.contextualCard = function () {
var name = faker.name.firstName(),
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()
}
},
"website": faker.internet.domainName(),
"company": {
"name": faker.company.companyName(),
"catchPhrase": faker.company.catchPhrase(),
"bs": faker.company.bs()
}
};
};
exports.userCard = function () {
return {
"name": faker.Name.findName(),
"username": faker.Internet.userName(),
"email": faker.Internet.email(),
"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(),
"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()
"lat": faker.address.latitude(),
"lng": faker.address.longitude()
}
},
"phone": faker.PhoneNumber.phoneNumber(),
"website": faker.Internet.domainName(),
"phone": faker.phone.phoneNumber(),
"website": faker.internet.domainName(),
"company": {
"name": faker.Company.companyName(),
"catchPhrase": faker.Company.catchPhrase(),
"bs": faker.Company.bs()
"name": faker.company.companyName(),
"catchPhrase": faker.company.catchPhrase(),
"bs": faker.company.bs()
}

@@ -122,2 +164,12 @@ };

exports.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" : exports.randomize(faker.definitions.finance.transaction_type),
"account" : faker.finance.account()
};
};

@@ -131,1 +183,2 @@ /*

*/
var faker = require('../index');
var image = {
image: function () {
var categories = ["abstract", "animals", "business", "cats", "city", "food", "nightlife", "fashion", "people", "nature", "sports", "technics", "transport"];
return image[faker.random.array_element(categories)]();
},
avatar: function () {
return faker.random.avatar_uri();
return faker.internet.avatar();
},

@@ -17,40 +21,40 @@ imageUrl: function (width, height, category) {

},
abstractImage: function (width, height) {
return this.imageUrl(width, height, 'abstract');
abstract: function (width, height) {
return faker.image.imageUrl(width, height, 'abstract');
},
animals: function (width, height) {
return this.imageUrl(width, height, 'animals');
return faker.image.imageUrl(width, height, 'animals');
},
business: function (width, height) {
return this.imageUrl(width, height, 'business');
return faker.image.imageUrl(width, height, 'business');
},
cats: function (width, height) {
return this.imageUrl(width, height, 'cats');
return faker.image.imageUrl(width, height, 'cats');
},
city: function (width, height) {
return this.imageUrl(width, height, 'city');
return faker.image.imageUrl(width, height, 'city');
},
food: function (width, height) {
return this.imageUrl(width, height, 'food');
return faker.image.imageUrl(width, height, 'food');
},
nightlife: function (width, height) {
return this.imageUrl(width, height, 'nightlife');
return faker.image.imageUrl(width, height, 'nightlife');
},
fashion: function (width, height) {
return this.imageUrl(width, height, 'fashion');
return faker.image.imageUrl(width, height, 'fashion');
},
people: function (width, height) {
return this.imageUrl(width, height, 'people');
return faker.image.imageUrl(width, height, 'people');
},
nature: function (width, height) {
return this.imageUrl(width, height, 'nature');
return faker.image.imageUrl(width, height, 'nature');
},
sports: function (width, height) {
return this.imageUrl(width, height, 'sports');
return faker.image.imageUrl(width, height, 'sports');
},
technics: function (width, height) {
return this.imageUrl(width, height, 'technics');
return faker.image.imageUrl(width, height, 'technics');
},
transport: function (width, height) {
return this.imageUrl(width, height, 'transport');
return faker.image.imageUrl(width, height, 'transport');
}

@@ -57,0 +61,0 @@ };

@@ -1,18 +0,33 @@

var faker = require('../index');
var faker = require('../index'),
password_generator = require('../vendor/password-generator.js'),
random_ua = require('../vendor/user-agent');
var internet = {
email: function () {
return faker.Helpers.slugify(this.userName()) + "@" + faker.Helpers.slugify(this.domainName());
avatar: function () {
return faker.random.array_element(faker.definitions.internet.avatar_uri);
},
userName: function () {
email: function (firstName, lastName, provider) {
provider = provider || faker.random.array_element(faker.definitions.internet.free_email);
return faker.helpers.slugify(faker.internet.userName(firstName, lastName)) + "@" + provider;
},
userName: function (firstName, lastName) {
var result;
firstName = firstName || faker.name.firstName();
lastName = lastName || faker.name.lastName();
switch (faker.random.number(2)) {
case 0:
result = faker.random.first_name();
result = firstName + faker.random.number(99);
break;
case 1:
result = faker.random.first_name() + faker.random.array_element([".", "_"]) + faker.random.last_name();
result = firstName + faker.random.array_element([".", "_"]) + lastName;
break;
case 2:
result = firstName + faker.random.array_element([".", "_"]) + lastName + faker.random.number(99);
break;
}
result = result.replace(/'/g, "");
result = result.replace(/ /g, "");
return result;

@@ -22,7 +37,11 @@ },

domainName: function () {
return this.domainWord() + "." + faker.random.domain_suffix();
return faker.internet.domainWord() + "." + faker.internet.domainSuffix();
},
domainSuffix: function () {
return faker.random.array_element(faker.definitions.internet.domain_suffix);
},
domainWord: function () {
return faker.random.first_name().toLowerCase();
return faker.name.firstName().replace(/([^A-Z0-9._%+-])/ig, '').toLowerCase();
},

@@ -32,3 +51,3 @@

var randNum = function () {
return (Math.random() * 254 + 1).toFixed(0);
return (faker.random.number(255)).toFixed(0);
};

@@ -44,4 +63,10 @@

userAgent: function () {
return random_ua.generate();
},
color: function (baseRed255, baseGreen255, baseBlue255) {
baseRed255 = baseRed255 || 0;
baseGreen255 = baseGreen255 || 0;
baseBlue255 = baseBlue255 || 0;
// based on awesome response : http://stackoverflow.com/questions/43044/algorithm-to-randomly-generate-an-aesthetically-pleasing-color-palette

@@ -51,4 +76,12 @@ var red = Math.floor((faker.random.number(256) + baseRed255) / 2);

var blue = Math.floor((faker.random.number(256) + baseRed255) / 2);
return '#' + red.toString(16) + green.toString(16) + blue.toString(16);
return '#' + red.toString(16) + green.toString(16) + blue.toString(16);
},
password: function (len, memorable, pattern, prefix) {
len = len || 15;
if (typeof memorable === "undefined") {
memorable = false;
}
return password_generator(len, memorable, pattern, prefix);
}

@@ -55,0 +88,0 @@ };

var faker = require('../index');
var Helpers = require('./helpers');
var definitions = require('../lib/definitions');

@@ -8,3 +7,3 @@ var lorem = {

if (typeof num == 'undefined') { num = 3; }
return Helpers.shuffle(definitions.lorem).slice(0, num);
return Helpers.shuffle(faker.definitions.lorem.words).slice(0, num);
},

@@ -16,6 +15,6 @@

// strange issue with the node_min_test failing for captialize, please fix and add this back
//return this.words(wordCount + Helpers.randomNumber(range)).join(' ').capitalize();
// strange issue with the node_min_test failing for captialize, please fix and add faker.lorem.back
//return faker.lorem.words(wordCount + Helpers.randomNumber(range)).join(' ').capitalize();
return this.words(wordCount + faker.random.number(7)).join(' ');
return faker.lorem.words(wordCount + faker.random.number(range)).join(' ');
},

@@ -27,3 +26,3 @@

for (sentenceCount; sentenceCount > 0; sentenceCount--) {
sentences.push(this.sentence());
sentences.push(faker.lorem.sentence());
}

@@ -35,3 +34,3 @@ return sentences.join("\n");

if (typeof sentenceCount == 'undefined') { sentenceCount = 3; }
return this.sentences(sentenceCount + faker.random.number(3));
return faker.lorem.sentences(sentenceCount + faker.random.number(3));
},

@@ -43,3 +42,3 @@

for (paragraphCount; paragraphCount > 0; paragraphCount--) {
paragraphs.push(this.paragraph());
paragraphs.push(faker.lorem.paragraph());
}

@@ -46,0 +45,0 @@ return paragraphs.join("\n \r\t");

@@ -5,31 +5,33 @@ var faker = require('../index');

firstName: function () {
return faker.random.first_name();
return faker.random.array_element(faker.definitions.name.first_name)
},
//Working as intended
firstNameFemale: function () {
return faker.random.first_name();
},
//Working as intended
firstNameMale: function () {
return faker.random.first_name();
},
lastName: function () {
return faker.random.last_name();
return faker.random.array_element(faker.definitions.name.last_name)
},
findName: function () {
findName: function (firstName, lastName) {
var r = faker.random.number(8);
firstName = firstName || faker.name.firstName();
lastName = lastName || faker.name.lastName();
switch (r) {
case 0:
return faker.random.name_prefix() + " " + _name.firstName() + " " + _name.lastName();
return faker.name.prefix() + " " + firstName + " " + lastName;
case 1:
return _name.firstName() + " " + _name.lastName() + " " + faker.random.name_suffix();
return firstName + " " + lastName + " " + faker.name.suffix();
}
return _name.firstName() + " " + _name.lastName();
}
return firstName + " " + lastName;
},
prefix: function () {
return faker.random.array_element(faker.definitions.name.prefix);
},
suffix: function () {
return faker.random.array_element(faker.definitions.name.suffix);
},
};
module.exports = _name;
var faker = require('../index');
var Helpers = require('./helpers');
var definitions = require('./definitions');
var phone = {
phoneNumber: function () {
return Helpers.replaceSymbolWithNumber(faker.random.phone_formats());
phoneNumber: function (format) {
format = format || faker.phone.phoneFormats();
return faker.helpers.replaceSymbolWithNumber(format);
},

@@ -12,6 +11,12 @@

phoneNumberFormat: function (phoneFormatsArrayIndex) {
return Helpers.replaceSymbolWithNumber(definitions.phone_formats[phoneFormatsArrayIndex]);
phoneFormatsArrayIndex = phoneFormatsArrayIndex || 0;
return faker.helpers.replaceSymbolWithNumber(faker.definitions.phone_number.formats[phoneFormatsArrayIndex]);
},
phoneFormats: function () {
return faker.random.array_element(faker.definitions.phone_number.formats);
}
};
module.exports = phone;

@@ -1,109 +0,55 @@

var definitions = require('./definitions');
var mersenne = require('../vendor/mersenne');
var faker = require('../index');
var random = {
// returns a single random number based on a max number or range
number: function (min, max) {
if (max === undefined) {
max = min;
min = 0;
number: function (options) {
if (typeof options === "number") {
var options = {
max: options
};
}
return Math.floor((Math.random() * max) + min);
},
// takes an array and returns the array randomly sorted
array_element: function (array) {
var r = Math.floor(Math.random() * array.length);
return array[r];
},
options = options || {
min: 0,
max: 1,
precision: 1
};
city_prefix: function () {
return this.array_element(definitions.city_prefix);
},
if (typeof options.min === "undefined") {
options.min = 0;
}
city_suffix: function () {
return this.array_element(definitions.city_suffix);
},
if (typeof options.max === "undefined") {
options.max = 1;
}
street_suffix: function () {
return this.array_element(definitions.street_suffix);
},
// by incrementing max by 1, max becomes inclusive of the range
if (options.max > 0) {
options.max++;
}
br_state: function () {
return this.array_element(definitions.br_state);
},
var randomNumber = mersenne.rand(options.max, options.min);
return randomNumber;
br_state_abbr: function () {
return this.array_element(definitions.br_state_abbr);
},
us_state: function () {
return this.array_element(definitions.us_state);
// takes an array and returns the array randomly sorted
array_element: function (array) {
array = array || ["a", "b", "c"];
var r = faker.random.number({ max: array.length - 1 });
return array[r];
},
us_state_abbr: function () {
return this.array_element(definitions.us_state_abbr);
},
// takes an object and returns the randomly key or value
object_element: function (object, field) {
object = object || {};
var array = Object.keys(object);
var key = faker.random.array_element(array);
uk_county: function () {
return this.array_element(definitions.uk_county);
},
uk_country: function () {
return this.array_element(definitions.uk_country);
},
first_name: function () {
return this.array_element(definitions.first_name);
},
last_name: function () {
return this.array_element(definitions.last_name);
},
name_prefix: function () {
return this.array_element(definitions.name_prefix);
},
name_suffix: function () {
return this.array_element(definitions.name_suffix);
},
catch_phrase_adjective: function () {
return this.array_element(definitions.catch_phrase_adjective);
},
catch_phrase_descriptor: function () {
return this.array_element(definitions.catch_phrase_descriptor);
},
catch_phrase_noun: function () {
return this.array_element(definitions.catch_phrase_noun);
},
bs_adjective: function () {
return this.array_element(definitions.bs_adjective);
},
bs_buzz: function () {
return this.array_element(definitions.bs_buzz);
},
bs_noun: function () {
return this.array_element(definitions.bs_noun);
},
phone_formats: function () {
return this.array_element(definitions.phone_formats);
},
domain_suffix: function () {
return this.array_element(definitions.domain_suffix);
},
avatar_uri: function () {
return this.array_element(definitions.avatar_uri);
return field === "key" ? key : object[key];
}
};
module.exports = random;

@@ -1,3 +0,11 @@

Copyright (c) 2014 Matthew Bergman & Marak Squires http://github.com/marak/faker.js/
faker.js - Copyright (c) 2014 Matthew Bergman & Marak Squires http://github.com/marak/faker.js/
faker.js was inspired by and has used data definitions from
https://github.com/stympy/faker/ - Copyright (c) 2007-2010 Benjamin Curtis
http://search.cpan.org/~jasonk/Data-Faker-0.07/ - Copyright 2004-2005 by Jason Kohles
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Permission is hereby granted, free of charge, to any person obtaining

@@ -4,0 +12,0 @@ a copy of this software and associated documentation files (the

{
"name": "faker",
"description": "Generate massive amounts of fake contextual data",
"version": "1.1.0",
"version": "2.0.1",
"contributors": [

@@ -11,3 +11,3 @@ "Marak Squires <marak.squires@gmail.com>",

"type": "git",
"url": "http://github.com/FotoVerite/faker.js.git"
"url": "http://github.com/Marak/Faker.js.git"
},

@@ -20,8 +20,14 @@ "scripts": {

"istanbul": "0.1.25",
"mocha": "1.7.4",
"mocha": "1.8.x",
"node-minify": "*",
"optimist" : "0.3.5",
"sinon": "1.4.2"
"sinon": "1.4.2",
"gulp": "3.8.8",
"browserify": "5.11.1",
"gulp-uglify": "1.0.1",
"gulp-rename": "1.2.0",
"gulp-mustache": "0.4.0",
"vinyl-transform": "0.0.1"
},
"main": "index.js"
}
# faker.js - generate massive amounts of fake data in the browser and node.js
<img src = "http://imgur.com/KiinQ.png" border = "0">
[![Build Status](https://travis-ci.org/Marak/faker.js.svg?branch=master)](https://travis-ci.org/Marak/Faker.js)
## Demo
<a href="http://marak.com/faker.js/">http://marak.com/faker.js/</a>
## USAGE
### browser -
<script src = "faker.js" type = "text/javascript"></script>
<script>
var randomName = faker.Name.findName(); // Caitlyn Kerluke
var randomEmail = faker.Internet.email(); // Rusty@arne.info
var randomCard = faker.Helpers.createCard(); // random contact card containing many properties
var randomName = faker.name.findName(); // Caitlyn Kerluke
var randomEmail = faker.internet.email(); // Rusty@arne.info
var randomCard = faker.helpers.createCard(); // random contact card containing many properties
</script>
### node.js -
### usage
var faker = require('./faker');
var randomName = faker.Name.findName(); // Rowan Nikolaus
var randomEmail = faker.Internet.email(); // Kassandra.Haley@erich.biz
var randomCard = faker.Helpers.createCard(); // random contact card containing many properties
var randomName = faker.name.findName(); // Rowan Nikolaus
var randomEmail = faker.internet.email(); // Kassandra.Haley@erich.biz
var randomCard = faker.helpers.createCard(); // random contact card containing many properties
### Localization
As of version `v2.0.0` faker.js supports 27 different language definition packs.
The default language is set to English.
Setting a new locale is simple:
```js
// sets locale to de
faker.locale = "de";
```
Read further for complete list of locales.
## API
<ul><li>Name<ul><li>firstName</li><li>firstNameFemale</li><li>firstNameMale</li><li>lastName</li><li>findName</li></ul></li><li>Address<ul><li>zipCode</li><li>zipCodeFormat</li><li>city</li><li>streetName</li><li>streetAddress</li><li>secondaryAddress</li><li>brState</li><li>ukCounty</li><li>ukCountry</li><li>usState</li><li>latitude</li><li>longitude</li></ul></li><li>PhoneNumber<ul><li>phoneNumber</li><li>phoneNumberFormat</li></ul></li><li>Internet<ul><li>email</li><li>userName</li><li>domainName</li><li>domainWord</li><li>ip</li><li>color</li></ul></li><li>Company<ul><li>suffixes</li><li>companyName</li><li>companySuffix</li><li>catchPhrase</li><li>bs</li></ul></li><li>Image<ul><li>avatar</li><li>imageUrl</li><li>abstractImage</li><li>animals</li><li>business</li><li>cats</li><li>city</li><li>food</li><li>nightlife</li><li>fashion</li><li>people</li><li>nature</li><li>sports</li><li>technics</li><li>transport</li></ul></li><li>Lorem<ul><li>words</li><li>sentence</li><li>sentences</li><li>paragraph</li><li>paragraphs</li></ul></li><li>Helpers<ul><li>randomNumber</li><li>randomize</li><li>slugify</li><li>replaceSymbolWithNumber</li><li>shuffle</li><li>createCard</li><li>userCard</li></ul></li><li>Tree<ul><li>clone</li><li>createTree</li></ul></li><li>Date<ul><li>past</li><li>future</li><li>between</li><li>recent</li></ul></li><li>random<ul><li>number</li><li>array_element</li><li>city_prefix</li><li>city_suffix</li><li>street_suffix</li><li>br_state</li><li>br_state_abbr</li><li>us_state</li><li>us_state_abbr</li><li>uk_county</li><li>uk_country</li><li>first_name</li><li>last_name</li><li>name_prefix</li><li>name_suffix</li><li>catch_phrase_adjective</li><li>catch_phrase_descriptor</li><li>catch_phrase_noun</li><li>bs_adjective</li><li>bs_buzz</li><li>bs_noun</li><li>phone_formats</li><li>domain_suffix</li><li>avatar_uri</li></ul></li><li>definitions<ul><li>first_name</li><li>last_name</li><li>name_prefix</li><li>name_suffix</li><li>br_state</li><li>br_state_abbr</li><li>us_state</li><li>us_state_abbr</li><li>city_prefix</li><li>city_suffix</li><li>street_suffix</li><li>uk_county</li><li>uk_country</li><li>catch_phrase_adjective</li><li>catch_phrase_descriptor</li><li>catch_phrase_noun</li><li>bs_adjective</li><li>bs_buzz</li><li>bs_noun</li><li>domain_suffix</li><li>lorem</li><li>phone_formats</li><li>avatar_uri</li></ul></li></ul>
<ul><li>name<ul><li>firstName</li><li>lastName</li><li>findName</li><li>prefix</li><li>suffix</li></ul></li><li>address<ul><li>zipCode</li><li>city</li><li>cityPrefix</li><li>citySuffix</li><li>streetName</li><li>streetAddress</li><li>streetSuffix</li><li>secondaryAddress</li><li>county</li><li>country</li><li>state</li><li>stateAbbr</li><li>latitude</li><li>longitude</li></ul></li><li>phone<ul><li>phoneNumber</li><li>phoneNumberFormat</li><li>phoneFormats</li></ul></li><li>internet<ul><li>avatar</li><li>email</li><li>userName</li><li>domainName</li><li>domainSuffix</li><li>domainWord</li><li>ip</li><li>userAgent</li><li>color</li><li>password</li></ul></li><li>company<ul><li>suffixes</li><li>companyName</li><li>companySuffix</li><li>catchPhrase</li><li>bs</li><li>catchPhraseAdjective</li><li>catchPhraseDescriptor</li><li>catchPhraseNoun</li><li>bsAdjective</li><li>bsBuzz</li><li>bsNoun</li></ul></li><li>image<ul><li>image</li><li>avatar</li><li>imageUrl</li><li>abstract</li><li>animals</li><li>business</li><li>cats</li><li>city</li><li>food</li><li>nightlife</li><li>fashion</li><li>people</li><li>nature</li><li>sports</li><li>technics</li><li>transport</li></ul></li><li>lorem<ul><li>words</li><li>sentence</li><li>sentences</li><li>paragraph</li><li>paragraphs</li></ul></li><li>helpers<ul><li>randomNumber</li><li>randomize</li><li>slugify</li><li>replaceSymbolWithNumber</li><li>shuffle</li><li>mustache</li><li>createCard</li><li>contextualCard</li><li>userCard</li><li>createTransaction</li></ul></li><li>date<ul><li>past</li><li>future</li><li>between</li><li>recent</li></ul></li><li>random<ul><li>number</li><li>array_element</li><li>object_element</li></ul></li><li>finance<ul><li>account</li><li>accountName</li><li>mask</li><li>amount</li><li>transactionType</li><li>currencyCode</li><li>currencyName</li><li>currencySymbol</li></ul></li><li>hacker<ul><li>abbreviation</li><li>adjective</li><li>noun</li><li>verb</li><li>ingverb</li><li>phrase</li></ul></li><li>locales<ul><li>de</li><li>de_AT</li><li>de_CH</li><li>en</li><li>en_AU</li><li>en_BORK</li><li>en_CA</li><li>en_GB</li><li>en_IND</li><li>en_US</li><li>en_au_ocker</li><li>es</li><li>fa</li><li>fr</li><li>it</li><li>ja</li><li>ko</li><li>nb_NO</li><li>nep</li><li>nl</li><li>pl</li><li>pt_BR</li><li>ru</li><li>sk</li><li>sv</li><li>vi</li><li>zh_CN</li></ul></li><li>locale<ul><li>0</li><li>1</li></ul></li><li>localeFallback<ul><li>0</li><li>1</li></ul></li><li>definitions<ul><li>name</li><li>address</li><li>company</li><li>lorem</li><li>hacker</li><li>phone_number</li><li>finance</li><li>internet</li></ul></li></ul>
## Tests
npm install .
make test
You can view a code coverage report generated in coverage/lcov-report/index.html.
## Authors
####Matthew Bergman & Marak Squires
Heavily inspired by Benjamin Curtis's Ruby Gem [faker](http://faker.rubyforge.org/) and Perl's [Data::faker](http://search.cpan.org/~jasonk/Data-faker-0.07/lib/Data/faker.pm)
<br/>
Copyright (c) 2014 Matthew Bergman & Marak Squires http://github.com/marak/faker.js/
<br/>
faker.js was inspired by and has used data definitions from
<br/>
https://github.com/stympy/faker/ - Copyright (c) 2007-2010 Benjamin Curtis <br/>
http://search.cpan.org/~jasonk/Data-Faker-0.07/ - Copyright 2004-2005 by Jason Kohles <br/>
Permission is hereby granted, free of charge, to any person obtaining

@@ -46,2 +85,2 @@ a copy of this software and associated documentation files (the

OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@@ -10,6 +10,6 @@ if (typeof module !== 'undefined') {

beforeEach(function () {
sinon.spy(faker.random, 'city_prefix');
sinon.spy(faker.random, 'first_name');
sinon.spy(faker.random, 'last_name');
sinon.spy(faker.random, 'city_suffix');
sinon.spy(faker.address, 'cityPrefix');
sinon.spy(faker.name, 'firstName');
sinon.spy(faker.name, 'lastName');
sinon.spy(faker.address, 'citySuffix');
});

@@ -19,6 +19,6 @@

faker.random.number.restore();
faker.random.city_prefix.restore();
faker.random.first_name.restore();
faker.random.last_name.restore();
faker.random.city_suffix.restore();
faker.address.cityPrefix.restore();
faker.name.firstName.restore();
faker.name.lastName.restore();
faker.address.citySuffix.restore();
});

@@ -29,8 +29,8 @@

var city = faker.Address.city();
var city = faker.address.city();
assert.ok(city);
assert.ok(faker.random.city_prefix.calledOnce);
assert.ok(faker.random.first_name.calledOnce);
assert.ok(faker.random.city_suffix.calledOnce);
assert.ok(faker.address.cityPrefix.calledOnce);
assert.ok(faker.name.firstName.calledOnce);
assert.ok(faker.address.citySuffix.calledOnce);
});

@@ -41,8 +41,7 @@

var city = faker.Address.city();
var city = faker.address.city();
assert.ok(city);
assert.ok(faker.random.city_prefix.calledOnce);
assert.ok(faker.random.first_name.calledOnce);
assert.ok(!faker.random.city_suffix.called);
assert.ok(faker.address.cityPrefix.calledOnce);
assert.ok(faker.name.firstName.calledOnce);
});

@@ -53,8 +52,6 @@

var city = faker.Address.city();
var city = faker.address.city();
assert.ok(city);
assert.ok(!faker.random.city_prefix.called);
assert.ok(faker.random.first_name.calledOnce);
assert.ok(faker.random.city_suffix.calledOnce);
assert.ok(faker.address.citySuffix.calledOnce);
});

@@ -65,17 +62,18 @@

var city = faker.Address.city();
var city = faker.address.city();
assert.ok(city);
assert.ok(!faker.random.city_prefix.called);
assert.ok(!faker.random.first_name.called);
assert.ok(faker.random.last_name.calledOnce);
assert.ok(faker.random.city_suffix.calledOnce);
assert.ok(!faker.address.cityPrefix.called);
assert.ok(!faker.name.firstName.called);
assert.ok(faker.name.lastName.calledOnce);
assert.ok(faker.address.citySuffix.calledOnce);
});
});
describe("streetName()", function () {
beforeEach(function () {
sinon.spy(faker.random, 'first_name');
sinon.spy(faker.random, 'last_name');
sinon.spy(faker.random, 'street_suffix');
sinon.spy(faker.name, 'firstName');
sinon.spy(faker.name, 'lastName');
sinon.spy(faker.address, 'streetSuffix');
});

@@ -85,5 +83,5 @@

faker.random.number.restore();
faker.random.first_name.restore();
faker.random.last_name.restore();
faker.random.street_suffix.restore();
faker.name.firstName.restore();
faker.name.lastName.restore();
faker.address.streetSuffix.restore();
});

@@ -94,8 +92,7 @@

var street_name = faker.Address.streetName();
var street_name = faker.address.streetName();
assert.ok(street_name);
assert.ok(!faker.random.first_name.called);
assert.ok(faker.random.last_name.calledOnce);
assert.ok(faker.random.street_suffix.calledOnce);
assert.ok(!faker.name.firstName.called);
assert.ok(faker.name.lastName.calledOnce);
assert.ok(faker.address.streetSuffix.calledOnce);
});

@@ -106,20 +103,22 @@

var street_name = faker.Address.streetName();
var street_name = faker.address.streetName();
assert.ok(street_name);
assert.ok(faker.random.first_name.calledOnce);
assert.ok(!faker.random.last_name.called);
assert.ok(faker.random.street_suffix.calledOnce);
assert.ok(faker.name.firstName.calledOnce);
assert.ok(!faker.name.lastName.called);
assert.ok(faker.address.streetSuffix.calledOnce);
});
});
describe("streetAddress()", function () {
beforeEach(function () {
sinon.spy(faker.Address, 'streetName');
sinon.spy(faker.Address, 'secondaryAddress');
sinon.spy(faker.address, 'streetName');
sinon.spy(faker.address, 'secondaryAddress');
});
afterEach(function () {
faker.Address.streetName.restore();
faker.Address.secondaryAddress.restore();
faker.address.streetName.restore();
faker.address.secondaryAddress.restore();
});

@@ -129,7 +128,7 @@

sinon.stub(faker.random, 'number').returns(0);
var address = faker.Address.streetAddress();
var address = faker.address.streetAddress();
var parts = address.split(' ');
assert.equal(parts[0].length, 5);
assert.ok(faker.Address.streetName.called);
assert.ok(faker.address.streetName.called);

@@ -141,7 +140,7 @@ faker.random.number.restore();

sinon.stub(faker.random, 'number').returns(1);
var address = faker.Address.streetAddress();
var address = faker.address.streetAddress();
var parts = address.split(' ');
assert.equal(parts[0].length, 4);
assert.ok(faker.Address.streetName.called);
assert.ok(faker.address.streetName.called);

@@ -153,8 +152,8 @@ faker.random.number.restore();

sinon.stub(faker.random, 'number').returns(2);
var address = faker.Address.streetAddress();
var address = faker.address.streetAddress();
var parts = address.split(' ');
assert.equal(parts[0].length, 3);
assert.ok(faker.Address.streetName.called);
assert.ok(!faker.Address.secondaryAddress.called);
assert.ok(faker.address.streetName.called);
assert.ok(!faker.address.secondaryAddress.called);

@@ -166,9 +165,10 @@ faker.random.number.restore();

it("adds a secondary address to the result", function () {
var address = faker.Address.streetAddress(true);
var address = faker.address.streetAddress(true);
var parts = address.split(' ');
assert.ok(faker.Address.secondaryAddress.called);
assert.ok(faker.address.secondaryAddress.called);
});
});
});

@@ -179,3 +179,3 @@ describe("secondaryAddress()", function () {

var address = faker.Address.secondaryAddress();
var address = faker.address.secondaryAddress();

@@ -193,84 +193,30 @@ var expected_array = [

describe("brState()", function () {
beforeEach(function () {
sinon.spy(faker.random, 'br_state_abbr');
sinon.spy(faker.random, 'br_state');
});
afterEach(function () {
faker.random.br_state_abbr.restore();
faker.random.br_state.restore();
});
context("when useAbbr is true", function () {
it("returns a br_state_abbr", function () {
var state = faker.Address.brState(true);
assert.ok(state);
assert.ok(faker.random.br_state_abbr.called);
assert.ok(!faker.random.br_state.called);
});
});
context("when useAbbr is not set", function () {
it("returns a br_state", function () {
var state = faker.Address.brState();
assert.ok(state);
assert.ok(!faker.random.br_state_abbr.called);
assert.ok(faker.random.br_state.called);
});
});
});
describe("ukCounty()", function () {
it("returns random uk_county", function () {
sinon.spy(faker.random, 'uk_county');
var county = faker.Address.ukCounty();
describe("county()", function () {
it("returns random county", function () {
sinon.spy(faker.address, 'county');
var county = faker.address.county();
assert.ok(county);
assert.ok(faker.random.uk_county.called);
faker.random.uk_county.restore();
assert.ok(faker.address.county.called);
faker.address.county.restore();
});
});
describe("ukCountry()", function () {
it("returns random uk_country", function () {
sinon.spy(faker.random, 'uk_country');
var country = faker.Address.ukCountry();
describe("country()", function () {
it("returns random country", function () {
sinon.spy(faker.address, 'country');
var country = faker.address.country();
assert.ok(country);
assert.ok(faker.random.uk_country.called);
faker.random.uk_country.restore();
assert.ok(faker.address.country.called);
faker.address.country.restore();
});
});
describe("usState()", function () {
beforeEach(function () {
sinon.spy(faker.random, 'us_state_abbr');
sinon.spy(faker.random, 'us_state');
describe("state()", function () {
it("returns random state", function () {
sinon.spy(faker.address, 'state');
var state = faker.address.state();
assert.ok(state);
assert.ok(faker.address.state.called);
faker.address.state.restore();
});
afterEach(function () {
faker.random.us_state_abbr.restore();
faker.random.us_state.restore();
});
context("when useAbus is true", function () {
it("returns a us_state_abbr", function () {
var state = faker.Address.usState(true);
assert.ok(state);
assert.ok(faker.random.us_state_abbr.called);
assert.ok(!faker.random.us_state.called);
});
});
context("when useAbus is not set", function () {
it("returns a us_state", function () {
var state = faker.Address.usState();
assert.ok(state);
assert.ok(!faker.random.us_state_abbr.called);
assert.ok(faker.random.us_state.called);
});
});
});

@@ -282,3 +228,3 @@

sinon.spy(faker.random, 'number');
var latitude = faker.Address.latitude();
var latitude = faker.address.latitude();
assert.ok(typeof latitude === 'string');

@@ -298,3 +244,3 @@ var latitude_float = parseFloat(latitude);

sinon.spy(faker.random, 'number');
var longitude = faker.Address.longitude();
var longitude = faker.address.longitude();
assert.ok(typeof longitude === 'string');

@@ -301,0 +247,0 @@ var longitude_float = parseFloat(longitude);

@@ -10,39 +10,36 @@ if (typeof module !== 'undefined') {

var modules = {
Address: [
address: [
'city', 'streetName', 'streetAddress', 'secondaryAddress',
'brState', 'ukCountry', 'ukCounty', 'usState', 'zipCode'
'country', 'county', 'state', 'zipCode'
],
Company: ['companyName', 'companySuffix', 'catchPhrase', 'bs'],
company: ['companyName', 'companySuffix', 'catchPhrase', 'bs'],
Internet: ['email', 'userName', 'domainName', 'domainWord', 'ip'],
internet: ['email', 'userName', 'domainName', 'domainWord', 'ip'],
Lorem: ['words', 'sentence', 'sentences', 'paragraph', 'paragraphs'],
lorem: ['words', 'sentence', 'sentences', 'paragraph', 'paragraphs'],
Name: ['firstName', 'lastName', 'findName'],
name: ['firstName', 'lastName', 'findName'],
PhoneNumber: ['phoneNumber']
phone: ['phoneNumber'],
finance: ['account', 'accountName', 'mask', 'amount', 'transactionType', 'currencyCode', 'currencyName', 'currencySymbol']
};
describe("functional tests", function () {
Object.keys(modules).forEach(function (module) {
describe(module, function () {
modules[module].forEach(function (meth) {
it(meth + "()", function () {
var result = faker[module][meth]();
assert.ok(result);
});
});
});
});
describe("Address", function () {
it("zipCodeFormat()", function () {
var result = faker.Address.zipCodeFormat(0);
assert.ok(!result.match(/-/));
for(var locale in faker.locales) {
faker.locale = locale;
Object.keys(modules).forEach(function (module) {
describe(module, function () {
modules[module].forEach(function (meth) {
it(meth + "()", function () {
var result = faker[module][meth]();
assert.ok(result);
});
});
});
});
}
result = faker.Address.zipCodeFormat(1);
assert.ok(result.match(/-/));
});
});
});
});

@@ -9,52 +9,43 @@ if (typeof module !== 'undefined') {

describe("companyName()", function () {
it("lets you specify the type of name to return", function () {
sinon.spy(faker.random, 'number');
var name = faker.Company.companyName(1);
assert.ok(name.match(/-/));
assert.ok(!faker.random.number.called);
faker.random.number.restore();
});
it("sometimes returns three last names", function () {
sinon.spy(faker.random, 'last_name');
sinon.spy(faker.name, 'lastName');
sinon.stub(faker.random, 'number').returns(2);
var name = faker.Company.companyName();
var name = faker.company.companyName();
var parts = name.split(' ');
assert.strictEqual(parts.length, 4); // account for word 'and'
assert.ok(faker.random.last_name.calledThrice);
assert.ok(faker.name.lastName.calledThrice);
faker.random.number.restore();
faker.random.last_name.restore();
faker.name.lastName.restore();
});
it("sometimes returns two last names separated by a hyphen", function () {
sinon.spy(faker.random, 'last_name');
sinon.spy(faker.name, 'lastName');
sinon.stub(faker.random, 'number').returns(1);
var name = faker.Company.companyName();
var name = faker.company.companyName();
var parts = name.split('-');
assert.ok(parts.length >= 2);
assert.ok(faker.random.last_name.calledTwice);
assert.ok(faker.name.lastName.calledTwice);
faker.random.number.restore();
faker.random.last_name.restore();
faker.name.lastName.restore();
});
it("sometimes returns a last name with a company suffix", function () {
sinon.spy(faker.Company, 'companySuffix');
sinon.spy(faker.random, 'last_name');
sinon.spy(faker.company, 'companySuffix');
sinon.spy(faker.name, 'lastName');
sinon.stub(faker.random, 'number').returns(0);
var name = faker.Company.companyName();
var name = faker.company.companyName();
var parts = name.split(' ');
assert.ok(parts.length >= 2);
assert.ok(faker.random.last_name.calledOnce);
assert.ok(faker.Company.companySuffix.calledOnce);
assert.ok(faker.name.lastName.calledOnce);
assert.ok(faker.company.companySuffix.calledOnce);
faker.random.number.restore();
faker.random.last_name.restore();
faker.Company.companySuffix.restore();
faker.name.lastName.restore();
faker.company.companySuffix.restore();
});

@@ -65,4 +56,4 @@ });

it("returns random value from company.suffixes array", function () {
var suffix = faker.Company.companySuffix();
assert.ok(faker.Company.suffixes().indexOf(suffix) !== -1);
var suffix = faker.company.companySuffix();
assert.ok(faker.company.suffixes().indexOf(suffix) !== -1);
});

@@ -74,17 +65,17 @@ });

sinon.spy(faker.random, 'array_element');
sinon.spy(faker.random, 'catch_phrase_adjective');
sinon.spy(faker.random, 'catch_phrase_descriptor');
sinon.spy(faker.random, 'catch_phrase_noun');
var phrase = faker.Company.catchPhrase();
sinon.spy(faker.company, 'catchPhraseAdjective');
sinon.spy(faker.company, 'catchPhraseDescriptor');
sinon.spy(faker.company, 'catchPhraseNoun');
var phrase = faker.company.catchPhrase();
assert.ok(phrase.split(' ').length >= 3);
assert.ok(faker.random.array_element.calledThrice);
assert.ok(faker.random.catch_phrase_adjective.calledOnce);
assert.ok(faker.random.catch_phrase_descriptor.calledOnce);
assert.ok(faker.random.catch_phrase_noun.calledOnce);
assert.ok(faker.company.catchPhraseAdjective.calledOnce);
assert.ok(faker.company.catchPhraseDescriptor.calledOnce);
assert.ok(faker.company.catchPhraseNoun.calledOnce);
faker.random.array_element.restore();
faker.random.catch_phrase_adjective.restore();
faker.random.catch_phrase_descriptor.restore();
faker.random.catch_phrase_noun.restore();
faker.company.catchPhraseAdjective.restore();
faker.company.catchPhraseDescriptor.restore();
faker.company.catchPhraseNoun.restore();
});

@@ -96,19 +87,19 @@ });

sinon.spy(faker.random, 'array_element');
sinon.spy(faker.random, 'bs_adjective');
sinon.spy(faker.random, 'bs_buzz');
sinon.spy(faker.random, 'bs_noun');
var bs = faker.Company.bs();
sinon.spy(faker.company, 'bsAdjective');
sinon.spy(faker.company, 'bsBuzz');
sinon.spy(faker.company, 'bsNoun');
var bs = faker.company.bs();
assert.ok(typeof bs === 'string');
assert.ok(faker.random.array_element.calledThrice);
assert.ok(faker.random.bs_adjective.calledOnce);
assert.ok(faker.random.bs_buzz.calledOnce);
assert.ok(faker.random.bs_noun.calledOnce);
assert.ok(faker.company.bsAdjective.calledOnce);
assert.ok(faker.company.bsBuzz.calledOnce);
assert.ok(faker.company.bsNoun.calledOnce);
faker.random.array_element.restore();
faker.random.bs_adjective.restore();
faker.random.bs_buzz.restore();
faker.random.bs_noun.restore();
faker.company.bsAdjective.restore();
faker.company.bsBuzz.restore();
faker.company.bsNoun.restore();
});
});
});

@@ -11,4 +11,4 @@ if (typeof module !== 'undefined') {

var date = faker.Date.past(75);
assert.ok(Date.parse(date) < new Date());
var date = faker.date.past(75);
assert.ok(date < new Date());
});

@@ -20,3 +20,3 @@

var date = Date.parse(faker.Date.past(75, refDate.toJSON()));
var date = faker.date.past(75, refDate.toJSON());

@@ -31,5 +31,5 @@ assert.ok(date < refDate && date > new Date()); // date should be before date given but after the current time

var date = faker.Date.future(75);
var date = faker.date.future(75);
assert.ok(Date.parse(date) > new Date());
assert.ok(date > new Date());
});

@@ -40,3 +40,3 @@

var refDate = new Date();
var date = Date.parse(faker.Date.future(0), refDate.toJSON());
var date = faker.date.future(0, refDate.toJSON());

@@ -50,3 +50,3 @@ assert.ok(date > refDate); // date should be after the date given, but before the current time

var date = Date.parse(faker.Date.future(75, refDate.toJSON()));
var date = faker.date.future(75, refDate.toJSON());

@@ -60,5 +60,5 @@ assert.ok(date > refDate && date < new Date()); // date should be after the date given, but before the current time

var date = faker.Date.recent(30);
var date = faker.date.recent(30);
assert.ok(Date.parse(date) <= new Date());
assert.ok(date <= new Date());
});

@@ -74,3 +74,3 @@

var date = Date.parse(faker.Date.between(from, to));
var date = faker.date.between(from, to);

@@ -77,0 +77,0 @@ assert.ok(date > from && date < to);

@@ -11,3 +11,3 @@ if (typeof module !== 'undefined') {

it("uses '#' by default", function () {
var num = faker.Helpers.replaceSymbolWithNumber('#AB');
var num = faker.helpers.replaceSymbolWithNumber('#AB');
assert.ok(num.match(/\dAB/));

@@ -19,3 +19,3 @@ });

it("replaces that symbol with integers", function () {
var num = faker.Helpers.replaceSymbolWithNumber('#AB', 'A');
var num = faker.helpers.replaceSymbolWithNumber('#AB', 'A');
assert.ok(num.match(/#\dB/));

@@ -28,4 +28,4 @@ });

it("removes unwanted characters from URI string", function () {
assert.equal(faker.Helpers.slugify("Aiden.Harªann"), "Aiden.Harann");
assert.equal(faker.Helpers.slugify("d'angelo.net"), "dangelo.net");
assert.equal(faker.helpers.slugify("Aiden.Harªann"), "Aiden.Harann");
assert.equal(faker.helpers.slugify("d'angelo.net"), "dangelo.net");
});

@@ -36,3 +36,3 @@ });

it("returns an object", function () {
var card = faker.Helpers.createCard();
var card = faker.helpers.createCard();
assert.ok(typeof card === 'object');

@@ -44,3 +44,3 @@ });

it("returns an object", function () {
var card = faker.Helpers.userCard();
var card = faker.helpers.userCard();
assert.ok(typeof card === 'object');

@@ -53,3 +53,3 @@ });

it("returns an integer", function () {
var num = faker.Helpers.randomNumber();
var num = faker.helpers.randomNumber();
assert.ok(typeof num === 'number');

@@ -63,3 +63,3 @@ });

var arr = ['a', 'b', 'c'];
var elem = faker.Helpers.randomize(arr);
var elem = faker.helpers.randomize(arr);
assert.ok(elem);

@@ -69,2 +69,15 @@ assert.ok(arr.indexOf(elem) !== -1);

});
describe("createTransaction()", function() {
it("should create a random transaction", function() {
var transaction = faker.helpers.createTransaction();
assert.ok(transaction);
assert.ok(transaction.amount);
assert.ok(transaction.date);
assert.ok(transaction.business);
assert.ok(transaction.name);
assert.ok(transaction.type);
assert.ok(transaction.account);
});
});
});

@@ -10,3 +10,3 @@ if (typeof module !== 'undefined') {

it("returns a random image url from lorempixel", function () {
var imageUrl = faker.Image.imageUrl();
var imageUrl = faker.image.imageUrl();

@@ -16,3 +16,3 @@ assert.equal(imageUrl, 'http://lorempixel.com/640/480');

it("returns a random image url from lorempixel with width and height", function () {
var imageUrl = faker.Image.imageUrl(100, 100);
var imageUrl = faker.image.imageUrl(100, 100);

@@ -22,3 +22,3 @@ assert.equal(imageUrl, 'http://lorempixel.com/100/100');

it("returns a random image url for a specified category", function () {
var imageUrl = faker.Image.imageUrl(100, 100, 'abstract');
var imageUrl = faker.image.imageUrl(100, 100, 'abstract');

@@ -30,8 +30,8 @@ assert.equal(imageUrl, 'http://lorempixel.com/100/100/abstract');

it("return a random avatar from UIFaces", function () {
assert.notEqual(-1, faker.Image.avatar().indexOf('s3.amazonaws.com/uifaces/faces'));
assert.notEqual(-1, faker.image.avatar().indexOf('s3.amazonaws.com/uifaces/faces'));
})
});
describe("abstractImage()", function () {
describe("abstract()", function () {
it("returns a random abstract image url", function () {
var abstract = faker.Image.abstractImage();
var abstract = faker.image.abstract();
assert.equal(abstract, 'http://lorempixel.com/640/480/abstract');

@@ -42,3 +42,3 @@ });

it("returns a random animals image url", function () {
var animals = faker.Image.animals();
var animals = faker.image.animals();
assert.equal(animals, 'http://lorempixel.com/640/480/animals');

@@ -49,3 +49,3 @@ });

it("returns a random business image url", function () {
var business = faker.Image.business();
var business = faker.image.business();
assert.equal(business, 'http://lorempixel.com/640/480/business');

@@ -56,3 +56,3 @@ });

it("returns a random cats image url", function () {
var cats = faker.Image.cats();
var cats = faker.image.cats();
assert.equal(cats, 'http://lorempixel.com/640/480/cats');

@@ -63,3 +63,3 @@ });

it("returns a random city image url", function () {
var city = faker.Image.city();
var city = faker.image.city();
assert.equal(city, 'http://lorempixel.com/640/480/city');

@@ -70,3 +70,3 @@ });

it("returns a random food image url", function () {
var food = faker.Image.food();
var food = faker.image.food();
assert.equal(food, 'http://lorempixel.com/640/480/food');

@@ -77,3 +77,3 @@ });

it("returns a random nightlife image url", function () {
var nightlife = faker.Image.nightlife();
var nightlife = faker.image.nightlife();
assert.equal(nightlife, 'http://lorempixel.com/640/480/nightlife');

@@ -84,3 +84,3 @@ });

it("returns a random fashion image url", function () {
var fashion = faker.Image.fashion();
var fashion = faker.image.fashion();
assert.equal(fashion, 'http://lorempixel.com/640/480/fashion');

@@ -91,3 +91,3 @@ });

it("returns a random people image url", function () {
var people = faker.Image.people();
var people = faker.image.people();
assert.equal(people, 'http://lorempixel.com/640/480/people');

@@ -98,3 +98,3 @@ });

it("returns a random nature image url", function () {
var nature = faker.Image.nature();
var nature = faker.image.nature();
assert.equal(nature, 'http://lorempixel.com/640/480/nature');

@@ -105,3 +105,3 @@ });

it("returns a random sports image url", function () {
var sports = faker.Image.sports();
var sports = faker.image.sports();
assert.equal(sports, 'http://lorempixel.com/640/480/sports');

@@ -112,3 +112,3 @@ });

it("returns a random technics image url", function () {
var technics = faker.Image.technics();
var technics = faker.image.technics();
assert.equal(technics, 'http://lorempixel.com/640/480/technics');

@@ -119,3 +119,3 @@ });

it("returns a random transport image url", function () {
var transport = faker.Image.transport();
var transport = faker.image.transport();
assert.equal(transport, 'http://lorempixel.com/640/480/transport');

@@ -122,0 +122,0 @@ });

@@ -9,11 +9,9 @@ if (typeof module !== 'undefined') {

describe("email()", function () {
it("returns a userName@domainName", function () {
sinon.stub(faker.Internet, 'userName').returns('Aiden.Harªann');
sinon.stub(faker.Internet, 'domainName').returns("ex'ample.net");
var email = faker.Internet.email();
assert.equal(email, 'Aiden.Harann@example.net');
faker.Internet.userName.restore();
faker.Internet.domainName.restore();
it("returns an email", function () {
sinon.stub(faker.internet, 'userName').returns('Aiden.Harann55');
var email = faker.internet.email("Aiden.Harann55");
var res = email.split("@");
res = res[0];
assert.equal(res, 'Aiden.Harann55');
faker.internet.userName.restore();
});

@@ -25,10 +23,10 @@ });

sinon.stub(faker.random, 'number').returns(0);
sinon.spy(faker.random, 'first_name');
var username = faker.Internet.userName();
sinon.spy(faker.name, 'firstName');
var username = faker.internet.userName();
assert.ok(username);
assert.ok(faker.random.first_name.called);
assert.ok(faker.name.firstName.called);
faker.random.number.restore();
faker.random.first_name.restore();
faker.name.firstName.restore();
});

@@ -38,15 +36,15 @@

sinon.stub(faker.random, 'number').returns(1);
sinon.spy(faker.random, 'first_name');
sinon.spy(faker.random, 'last_name');
sinon.spy(faker.name, 'firstName');
sinon.spy(faker.name, 'lastName');
sinon.spy(faker.random, 'array_element');
var username = faker.Internet.userName();
var username = faker.internet.userName();
assert.ok(username);
assert.ok(faker.random.first_name.called);
assert.ok(faker.random.last_name.called);
assert.ok(faker.name.firstName.called);
assert.ok(faker.name.lastName.called);
assert.ok(faker.random.array_element.calledWith(['.', '_']));
faker.random.number.restore();
faker.random.first_name.restore();
faker.random.last_name.restore();
faker.name.firstName.restore();
faker.name.lastName.restore();
});

@@ -57,11 +55,11 @@ });

it("returns a domainWord plus a random suffix", function () {
sinon.stub(faker.Internet, 'domainWord').returns('bar');
sinon.stub(faker.random, 'domain_suffix').returns('net');
sinon.stub(faker.internet, 'domainWord').returns('bar');
sinon.stub(faker.internet, 'domainSuffix').returns('net');
var domain_name = faker.Internet.domainName();
var domain_name = faker.internet.domainName();
assert.equal(domain_name, 'bar.net');
faker.Internet.domainWord.restore();
faker.random.domain_suffix.restore();
faker.internet.domainWord.restore();
faker.internet.domainSuffix.restore();
});

@@ -72,4 +70,4 @@ });

it("returns a lower-case firstName", function () {
sinon.stub(faker.random, 'first_name').returns('FOO');
var domain_word = faker.Internet.domainWord();
sinon.stub(faker.name, 'firstName').returns('FOO');
var domain_word = faker.internet.domainWord();

@@ -79,3 +77,3 @@ assert.ok(domain_word);

faker.random.first_name.restore();
faker.name.firstName.restore();
});

@@ -86,3 +84,3 @@ });

it("returns a random IP address with four parts", function () {
var ip = faker.Internet.ip();
var ip = faker.internet.ip();
var parts = ip.split('.');

@@ -93,5 +91,12 @@ assert.equal(parts.length, 4);

describe("userAgent()", function () {
it("returns a valid user-agent", function () {
var ua = faker.internet.userAgent();
assert.ok(ua);
});
});
describe("color()", function () {
it("returns a valid hex value (like #ffffff)", function () {
var color = faker.Internet.color(100, 100, 100);
var color = faker.internet.color(100, 100, 100);
assert.ok(color.match(/^#[a-f0-9]{6}$/));

@@ -98,0 +103,0 @@ });

@@ -10,7 +10,7 @@ if (typeof module !== 'undefined') {

beforeEach(function () {
sinon.spy(faker.Helpers, 'shuffle');
sinon.spy(faker.helpers, 'shuffle');
});
afterEach(function () {
faker.Helpers.shuffle.restore();
faker.helpers.shuffle.restore();
});

@@ -20,7 +20,7 @@

it("returns three words", function () {
var words = faker.Lorem.words();
var words = faker.lorem.words();
assert.ok(Array.isArray(words));
assert.equal(words.length, 3);
assert.ok(faker.Helpers.shuffle.called);
assert.ok(faker.helpers.shuffle.called);
});

@@ -31,3 +31,3 @@ });

it("returns requested number of words", function () {
var words = faker.Lorem.words(7);
var words = faker.lorem.words(7);

@@ -43,5 +43,5 @@ assert.ok(Array.isArray(words));

it("returns a string of at least three words", function () {
sinon.spy(faker.Lorem, 'words');
sinon.spy(faker.lorem, 'words');
sinon.stub(faker.random, 'number').returns(2);
var sentence = faker.Lorem.sentence();
var sentence = faker.lorem.sentence();

@@ -51,5 +51,5 @@ assert.ok(typeof sentence === 'string');

assert.equal(parts.length, 5); // default 3 plus stubbed 2.
assert.ok(faker.Lorem.words.calledWith(5));
assert.ok(faker.lorem.words.calledWith(5));
faker.Lorem.words.restore();
faker.lorem.words.restore();
faker.random.number.restore();

@@ -61,5 +61,5 @@ });

it("returns a string of at least the requested number of words", function () {
sinon.spy(faker.Lorem, 'words');
sinon.stub(faker.random, 'number').returns(2);
var sentence = faker.Lorem.sentence(10);
sinon.spy(faker.lorem, 'words');
sinon.stub(faker.random, 'number').withArgs(7).returns(2);
var sentence = faker.lorem.sentence(10);

@@ -69,5 +69,5 @@ assert.ok(typeof sentence === 'string');

assert.equal(parts.length, 12); // requested 10 plus stubbed 2.
assert.ok(faker.Lorem.words.calledWith(12));
assert.ok(faker.lorem.words.calledWith(12));
faker.Lorem.words.restore();
faker.lorem.words.restore();
faker.random.number.restore();

@@ -79,14 +79,18 @@ });

it("returns a string of at least the requested number of words", function () {
sinon.spy(faker.Lorem, 'words');
sinon.stub(faker.random, 'number').returns(4);
var sentence = faker.Lorem.sentence(10, 4);
sinon.spy(faker.lorem, 'words');
sinon.stub(faker.random, 'number').withArgs(4).returns(4);
var sentence = faker.lorem.sentence(10, 4);
assert.ok(typeof sentence === 'string');
var parts = sentence.split(' ');
assert.equal(parts.length, 14); // requested 10 plus stubbed 4.
assert.ok(faker.Lorem.words.calledWith(14));
assert.ok(faker.random.number.calledWith(4)); // random.number should be called with the 'range' we passed.
assert.ok(faker.lorem.words.calledWith(14));
faker.Lorem.words.restore();
faker.lorem.words.restore();
faker.random.number.restore();
});
});

@@ -98,4 +102,4 @@ });

it("returns newline-separated string of three sentences", function () {
sinon.spy(faker.Lorem, 'sentence');
var sentences = faker.Lorem.sentences();
sinon.spy(faker.lorem, 'sentence');
var sentences = faker.lorem.sentences();

@@ -105,5 +109,5 @@ assert.ok(typeof sentences === 'string');

assert.equal(parts.length, 3);
assert.ok(faker.Lorem.sentence.calledThrice);
assert.ok(faker.lorem.sentence.calledThrice);
faker.Lorem.sentence.restore();
faker.lorem.sentence.restore();
});

@@ -114,4 +118,4 @@ });

it("returns newline-separated string of requested number of sentences", function () {
sinon.spy(faker.Lorem, 'sentence');
var sentences = faker.Lorem.sentences(5);
sinon.spy(faker.lorem, 'sentence');
var sentences = faker.lorem.sentences(5);

@@ -122,3 +126,3 @@ assert.ok(typeof sentences === 'string');

faker.Lorem.sentence.restore();
faker.lorem.sentence.restore();
});

@@ -131,5 +135,5 @@ });

it("returns a string of at least three sentences", function () {
sinon.spy(faker.Lorem, 'sentences');
sinon.spy(faker.lorem, 'sentences');
sinon.stub(faker.random, 'number').returns(2);
var paragraph = faker.Lorem.paragraph();
var paragraph = faker.lorem.paragraph();

@@ -139,5 +143,5 @@ assert.ok(typeof paragraph === 'string');

assert.equal(parts.length, 5); // default 3 plus stubbed 2.
assert.ok(faker.Lorem.sentences.calledWith(5));
assert.ok(faker.lorem.sentences.calledWith(5));
faker.Lorem.sentences.restore();
faker.lorem.sentences.restore();
faker.random.number.restore();

@@ -149,5 +153,5 @@ });

it("returns a string of at least the requested number of sentences", function () {
sinon.spy(faker.Lorem, 'sentences');
sinon.spy(faker.lorem, 'sentences');
sinon.stub(faker.random, 'number').returns(2);
var paragraph = faker.Lorem.paragraph(10);
var paragraph = faker.lorem.paragraph(10);

@@ -157,5 +161,5 @@ assert.ok(typeof paragraph === 'string');

assert.equal(parts.length, 12); // requested 10 plus stubbed 2.
assert.ok(faker.Lorem.sentences.calledWith(12));
assert.ok(faker.lorem.sentences.calledWith(12));
faker.Lorem.sentences.restore();
faker.lorem.sentences.restore();
faker.random.number.restore();

@@ -169,4 +173,4 @@ });

it("returns newline-separated string of three paragraphs", function () {
sinon.spy(faker.Lorem, 'paragraph');
var paragraphs = faker.Lorem.paragraphs();
sinon.spy(faker.lorem, 'paragraph');
var paragraphs = faker.lorem.paragraphs();

@@ -176,5 +180,5 @@ assert.ok(typeof paragraphs === 'string');

assert.equal(parts.length, 3);
assert.ok(faker.Lorem.paragraph.calledThrice);
assert.ok(faker.lorem.paragraph.calledThrice);
faker.Lorem.paragraph.restore();
faker.lorem.paragraph.restore();
});

@@ -185,4 +189,4 @@ });

it("returns newline-separated string of requested number of paragraphs", function () {
sinon.spy(faker.Lorem, 'paragraph');
var paragraphs = faker.Lorem.paragraphs(5);
sinon.spy(faker.lorem, 'paragraph');
var paragraphs = faker.lorem.paragraphs(5);

@@ -193,3 +197,3 @@ assert.ok(typeof paragraphs === 'string');

faker.Lorem.paragraph.restore();
faker.lorem.paragraph.restore();
});

@@ -196,0 +200,0 @@ });

@@ -11,43 +11,20 @@ if (typeof module !== 'undefined') {

it("returns a random name", function () {
sinon.stub(faker.random, 'first_name').returns('foo');
var first_name = faker.Name.firstName();
sinon.stub(faker.name, 'firstName').returns('foo');
var first_name = faker.name.firstName();
assert.equal(first_name, 'foo');
faker.random.first_name.restore();
faker.name.firstName.restore();
});
});
describe("firstNameFemale()", function () {
it("returns a random name", function () {
sinon.stub(faker.random, 'first_name').returns('foo');
var first_name = faker.Name.firstNameFemale();
assert.equal(first_name, 'foo');
faker.random.first_name.restore();
});
});
describe("firstNameMale()", function () {
it("returns a random name", function () {
sinon.stub(faker.random, 'first_name').returns('foo');
var first_name = faker.Name.firstNameMale();
assert.equal(first_name, 'foo');
faker.random.first_name.restore();
});
});
describe("lastName()", function () {
it("returns a random name", function () {
sinon.stub(faker.random, 'last_name').returns('foo');
sinon.stub(faker.name, 'lastName').returns('foo');
var last_name = faker.Name.lastName();
var last_name = faker.name.lastName();
assert.equal(last_name, 'foo');
faker.random.last_name.restore();
faker.name.lastName.restore();
});

@@ -59,3 +36,3 @@ });

sinon.stub(faker.random, 'number').returns(5);
var name = faker.Name.findName();
var name = faker.name.findName();
assert.ok(name);

@@ -71,3 +48,3 @@ var parts = name.split(' ');

sinon.stub(faker.random, 'number').returns(0);
var name = faker.Name.findName();
var name = faker.name.findName();
var parts = name.split(' ');

@@ -82,3 +59,3 @@

sinon.stub(faker.random, 'number').returns(1);
var name = faker.Name.findName();
var name = faker.name.findName();
var parts = name.split(' ');

@@ -85,0 +62,0 @@

@@ -10,12 +10,9 @@ if (typeof module !== 'undefined') {

it("returns a random phoneNumber with a random format", function () {
sinon.spy(faker.random, 'phone_formats');
sinon.spy(faker.Helpers, 'replaceSymbolWithNumber');
var phone_number = faker.PhoneNumber.phoneNumber();
sinon.spy(faker.helpers, 'replaceSymbolWithNumber');
var phone_number = faker.phone.phoneNumber();
assert.ok(phone_number.match(/\d/));
assert.ok(faker.random.phone_formats.called);
assert.ok(faker.Helpers.replaceSymbolWithNumber.called);
assert.ok(faker.helpers.replaceSymbolWithNumber.called);
faker.random.phone_formats.restore();
faker.Helpers.replaceSymbolWithNumber.restore();
faker.helpers.replaceSymbolWithNumber.restore();
});

@@ -25,7 +22,12 @@ });

describe("phoneNumberFormat()", function () {
faker.locale = "en";
it("returns phone number with requested format (Array index)", function () {
var phone_number = faker.PhoneNumber.phoneNumberFormat(5);
assert.ok(phone_number.match(/\(\d\d\d\)\d\d\d-\d\d\d\d/));
for (var i = 0; i < 10; i++) {
var phone_number = faker.phone.phoneNumberFormat(1);
assert.ok(phone_number.match(/\(\d\d\d\) \d\d\d-\d\d\d\d/));
}
});
});
});

@@ -9,14 +9,24 @@ if (typeof module !== 'undefined') {

describe("number", function() {
it("returns a random number given a maximum value", function() {
it("returns a random number given a maximum value as Number", function() {
var max = 10;
assert.ok(faker.random.number(max) < max);
assert.ok(faker.random.number(max) <= max);
});
it("returns a random number given a maximum value as Object", function() {
var options = { max: 10 };
assert.ok(faker.random.number(options) < options.max);
});
it("returns a random number between a range", function() {
var min = 1;
var max = 10;
var randomNumber = faker.random.number(1, 10);
assert.ok( randomNumber >= min);
assert.ok( randomNumber <= max);
var options = { min: 22, max: 33 };
for(var i = 0; i < 100; i++) {
var randomNumber = faker.random.number(options);
assert.ok(randomNumber >= options.min);
assert.ok(randomNumber <= options.max);
}
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc