Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
# Conflicts:
#	lib/finance.js
  • Loading branch information
alexpts committed Feb 11, 2017
2 parents 434b317 + fe2c0fd commit 53520a7
Show file tree
Hide file tree
Showing 63 changed files with 2,572 additions and 96 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* -crlf
21 changes: 19 additions & 2 deletions build/src/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,23 @@ In a production environment, you may only want to include the locale data for a
var faker = require('faker/locale/de');
```

## Setting a randomness seed

If you want consistent results, you can set your own seed:

```js
faker.random.seed(123);

var firstRandom = faker.random.number();

// Setting the seed again resets the sequence.
faker.random.seed(123);

var secondRandom = faker.random.number();

console.log(firstRandom === secondRandom);
```

## Tests

npm install .
Expand Down Expand Up @@ -155,8 +172,8 @@ If you require the absolute latest version of `faker.js` the `master` branch @ h

#### Marak Squires

faker.js - Copyright (c) 2016
Matthew Bergman & Marak Squires
faker.js - Copyright (c) 2017
Marak Squires
http://github.com/marak/faker.js/

faker.js was inspired by and has used data definitions from:
Expand Down
64 changes: 64 additions & 0 deletions lib/database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
*
* @namespace faker.database
*/
var Database = function (faker) {
var self = this;
/**
* column
*
* @method faker.database.column
*/
self.column = function () {
return faker.random.arrayElement(faker.definitions.database.column);
};

self.column.schema = {
"description": "Generates a column name.",
"sampleResults": ["id", "title", "createdAt"]
};

/**
* type
*
* @method faker.database.type
*/
self.type = function () {
return faker.random.arrayElement(faker.definitions.database.type);
};

self.type.schema = {
"description": "Generates a column type.",
"sampleResults": ["byte", "int", "varchar", "timestamp"]
};

/**
* collation
*
* @method faker.database.collation
*/
self.collation = function () {
return faker.random.arrayElement(faker.definitions.database.collation);
};

self.collation.schema = {
"description": "Generates a collation.",
"sampleResults": ["utf8_unicode_ci", "utf8_bin"]
};

/**
* engine
*
* @method faker.database.engine
*/
self.engine = function () {
return faker.random.arrayElement(faker.definitions.database.engine);
};

self.engine.schema = {
"description": "Generates a storage engine.",
"sampleResults": ["MyISAM", "InnoDB"]
};
};

module["exports"] = Database;
76 changes: 71 additions & 5 deletions lib/finance.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @namespace faker.finance
*/
var Finance = function (faker) {
var ibanLib = require("./iban");
var Helpers = faker.helpers,
self = this;

Expand Down Expand Up @@ -40,14 +41,14 @@ var Finance = function (faker) {
* @method faker.finance.mask
* @param {number} length
* @param {boolean} parens
* @param {boolean} elipsis
* @param {boolean} ellipsis
*/
self.mask = function (length, parens, elipsis) {
self.mask = function (length, parens, ellipsis) {

//set defaults
length = (length == 0 || !length || typeof length == 'undefined') ? 4 : length;
parens = (parens === null) ? true : parens;
elipsis = (elipsis === null) ? true : elipsis;
ellipsis = (ellipsis === null) ? true : ellipsis;

//create a template for length
var template = '';
Expand All @@ -56,8 +57,8 @@ var Finance = function (faker) {
template = template + '#';
}

//prefix with elipsis
template = (elipsis) ? ['...', template].join('') : template;
//prefix with ellipsis
template = (ellipsis) ? ['...', template].join('') : template;

template = (parens) ? ['(', template, ')'].join('') : template;

Expand Down Expand Up @@ -148,6 +149,71 @@ var Finance = function (faker) {

return address;
};

/**
* iban
*
* @method faker.finance.iban
*/
self.iban = function (formatted) {
var ibanFormat = faker.random.arrayElement(ibanLib.formats);
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.random.number(100) < 80) {
s += faker.random.number(9);
} else {
s += faker.random.arrayElement(ibanLib.alpha);
}
} else {
if (c >= 3 && faker.random.number(100) < 30) {
if (faker.random.boolean()) {
s += faker.random.arrayElement(ibanLib.pattern100);
c -= 2;
} else {
s += faker.random.arrayElement(ibanLib.pattern10);
c--;
}
} else {
s += faker.random.number(9);
}
}
c--;
}
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;
};

/**
* bic
*
* @method faker.finance.bic
*/
self.bic = function () {
var vowels = ["A", "E", "I", "O", "U"];
var prob = faker.random.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("###") : "");
};
};

module['exports'] = Finance;
8 changes: 4 additions & 4 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ var Helpers = function (faker) {
*/
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 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.random.number(9);
} else if (string.charAt(i) == "?") {
str += faker.random.arrayElement(alpha);
} else if (string.charAt(i) == "?") {
str += faker.random.arrayElement(alpha);
} else {
str += string.charAt(i);
}
Expand All @@ -83,7 +83,7 @@ var Helpers = function (faker) {
* @param {array} o
*/
self.shuffle = function (o) {
if (o.length === 0) {
if (typeof o === 'undefined' || o.length === 0) {
return [];
}
o = o || ["a", "b", "c"];
Expand Down
Loading

0 comments on commit 53520a7

Please sign in to comment.