forked from zuriby/Faker.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[refactor] [dist] Allow for node to require individual locales ( to a…
…void the default behavior of requiring all locale data. #125 #167
- Loading branch information
Showing
52 changed files
with
266 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
var faker = require('../locale/en'); | ||
|
||
console.log(faker.name.findName()); | ||
|
||
var faker = require('../locale/uk'); | ||
|
||
console.log(faker.name.findName()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,4 @@ | ||
/* | ||
module['exports'] = require('./lib'); | ||
|
||
this index.js file is used for including the faker library as a CommonJS module, instead of a bundle | ||
you can include the faker library into your existing node.js application by requiring the entire /faker directory | ||
var faker = require(./faker); | ||
var randomName = faker.name.findName(); | ||
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(); | ||
if you plan on modifying the faker library you should be performing your changes in the /lib/ directory | ||
*/ | ||
exports.random = require('./lib/random'); | ||
exports.fake = require('./lib/fake'); | ||
|
||
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.finance = require('./lib/finance'); | ||
exports.hacker = require('./lib/hacker'); | ||
exports.commerce = require('./lib/commerce'); | ||
|
||
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", "title", "male_first_name", "female_first_name", "male_middle_name", "female_middle_name", "male_last_name", "female_last_name"], | ||
"address": ["city_prefix", "city_suffix", "street_suffix", "county", "country", "country_code", "state", "state_abbr", "street_prefix", "zipFormat"], | ||
"company": ["adjective", "noun", "descriptor", "bs_adjective", "bs_noun", "bs_verb", "suffix"], | ||
"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"], | ||
"commerce": ["color", "department", "product_name", "price", "categories"], | ||
"title": "", | ||
"separator": "" | ||
}; | ||
|
||
// Create a Getter for all definitions.foo.bar propetries | ||
Object.keys(_definitions).forEach(function(d){ | ||
if (typeof exports.definitions[d] === "undefined") { | ||
exports.definitions[d] = {}; | ||
} | ||
|
||
if (typeof _definitions[d] === "string") { | ||
exports.definitions[d] = locales[exports.locale][d]; | ||
return; | ||
} | ||
|
||
_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]; | ||
} | ||
} | ||
}); | ||
}); | ||
}); | ||
// since we are requiring the top level of faker, load all locales by default | ||
module['exports'].locales = require('./lib/locales'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
var faker = require('../index'), | ||
var faker = require('./index'), | ||
f = faker.fake; | ||
|
||
var company = { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
var faker = require("../index"); | ||
var faker = require("./index"); | ||
|
||
var date = { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
*/ | ||
|
||
var faker = require('../'); | ||
var faker = require('./'); | ||
|
||
module['exports'] = function fake (str) { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
var Helpers = require('./helpers'), | ||
faker = require('../index'); | ||
faker = require('./index'); | ||
|
||
var finance = { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
var faker = require('../index'); | ||
var faker = require('./index'); | ||
|
||
var hacker = { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
var faker = require('../index'); | ||
var faker = require('./index'); | ||
|
||
var image = { | ||
image: function () { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
this index.js file is used for including the faker library as a CommonJS module, instead of a bundle | ||
you can include the faker library into your existing node.js application by requiring the entire /faker directory | ||
var faker = require(./faker); | ||
var randomName = faker.name.findName(); | ||
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(); | ||
if you plan on modifying the faker library you should be performing your changes in the /lib/ directory | ||
*/ | ||
exports.random = require('./random'); | ||
exports.fake = require('./fake'); | ||
|
||
exports.name = require('./name'); | ||
exports.address = require('./address'); | ||
exports.phone = require('./phone_number'); | ||
exports.internet = require('./internet'); | ||
exports.company = require('./company'); | ||
exports.image = require('./image'); | ||
exports.lorem = require('./lorem'); | ||
exports.helpers = require('./helpers'); | ||
exports.date = require('./date'); | ||
exports.finance = require('./finance'); | ||
exports.hacker = require('./hacker'); | ||
//exports.commerce = require('./commerce'); | ||
|
||
// don't load all locales by default | ||
var locales = {}; | ||
exports.locales = locales; | ||
locales = require('./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", "title", "male_first_name", "female_first_name", "male_middle_name", "female_middle_name", "male_last_name", "female_last_name"], | ||
"address": ["city_prefix", "city_suffix", "street_suffix", "county", "country", "country_code", "state", "state_abbr", "street_prefix", "zipFormat"], | ||
"company": ["adjective", "noun", "descriptor", "bs_adjective", "bs_noun", "bs_verb", "suffix"], | ||
"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"], | ||
"commerce": ["color", "department", "product_name", "price", "categories"], | ||
"title": "", | ||
"separator": "" | ||
}; | ||
|
||
// Create a Getter for all definitions.foo.bar propetries | ||
Object.keys(_definitions).forEach(function(d){ | ||
if (typeof exports.definitions[d] === "undefined") { | ||
exports.definitions[d] = {}; | ||
} | ||
|
||
if (typeof _definitions[d] === "string") { | ||
exports.definitions[d] = _definitions[d]; | ||
|
||
|
||
return; | ||
} | ||
|
||
_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]; | ||
} | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
var faker = require('../index'); | ||
var faker = require('./index'); | ||
|
||
var _name = { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
var faker = require('../index'); | ||
var faker = require('./index'); | ||
|
||
var phone = { | ||
phoneNumber: function (format) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
var faker = require('../lib'); | ||
faker.locale = "de"; | ||
faker.locales['de'] = require('../lib/locales/de'); | ||
module['exports'] = faker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
var faker = require('../lib'); | ||
faker.locale = "de_AT"; | ||
faker.locales['de_AT'] = require('../lib/locales/de_AT'); | ||
module['exports'] = faker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
var faker = require('../lib'); | ||
faker.locale = "de_CH"; | ||
faker.locales['de_CH'] = require('../lib/locales/de_CH'); | ||
module['exports'] = faker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
var faker = require('../lib'); | ||
faker.locale = "en"; | ||
faker.locales['en'] = require('../lib/locales/en'); | ||
module['exports'] = faker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
var faker = require('../lib'); | ||
faker.locale = "en_AU"; | ||
faker.locales['en_AU'] = require('../lib/locales/en_AU'); | ||
module['exports'] = faker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
var faker = require('../lib'); | ||
faker.locale = "en_BORK"; | ||
faker.locales['en_BORK'] = require('../lib/locales/en_BORK'); | ||
module['exports'] = faker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
var faker = require('../lib'); | ||
faker.locale = "en_CA"; | ||
faker.locales['en_CA'] = require('../lib/locales/en_CA'); | ||
module['exports'] = faker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
var faker = require('../lib'); | ||
faker.locale = "en_GB"; | ||
faker.locales['en_GB'] = require('../lib/locales/en_GB'); | ||
module['exports'] = faker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
var faker = require('../lib'); | ||
faker.locale = "en_IND"; | ||
faker.locales['en_IND'] = require('../lib/locales/en_IND'); | ||
module['exports'] = faker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
var faker = require('../lib'); | ||
faker.locale = "en_US"; | ||
faker.locales['en_US'] = require('../lib/locales/en_US'); | ||
module['exports'] = faker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
var faker = require('../lib'); | ||
faker.locale = "en_au_ocker"; | ||
faker.locales['en_au_ocker'] = require('../lib/locales/en_au_ocker'); | ||
module['exports'] = faker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
var faker = require('../lib'); | ||
faker.locale = "es"; | ||
faker.locales['es'] = require('../lib/locales/es'); | ||
module['exports'] = faker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
var faker = require('../lib'); | ||
faker.locale = "fa"; | ||
faker.locales['fa'] = require('../lib/locales/fa'); | ||
module['exports'] = faker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
var faker = require('../lib'); | ||
faker.locale = "fr"; | ||
faker.locales['fr'] = require('../lib/locales/fr'); | ||
module['exports'] = faker; |
Oops, something went wrong.