diff options
| author | Marak <[email protected]> | 2020-08-25 18:46:50 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-08-25 18:46:50 -0500 |
| commit | 2f694e3adcbdb9da0709647d945b93798026b4bb (patch) | |
| tree | bff39c1067b4bffc4968bb7709dcbb6c009b475a /lib | |
| parent | 6a979f2652cfcd0f7dc6643eed4c35551f36ccf4 (diff) | |
| parent | 9a914b148190e3276786d2b2ae8a8992f61a42d2 (diff) | |
| download | faker-2f694e3adcbdb9da0709647d945b93798026b4bb.tar.xz faker-2f694e3adcbdb9da0709647d945b93798026b4bb.zip | |
Merge pull request #800 from kaykhan/country-code-alpha-3
feat: added support for generating a random ISO_3166-1 alpha-3 country code
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/address.js | 13 | ||||
| -rw-r--r-- | lib/index.js | 2 | ||||
| -rw-r--r-- | lib/locales/en/address/country_code_alpha_3.js | 252 | ||||
| -rw-r--r-- | lib/locales/en/address/index.js | 1 |
4 files changed, 266 insertions, 2 deletions
diff --git a/lib/address.js b/lib/address.js index 125e3d50..650044fe 100644 --- a/lib/address.js +++ b/lib/address.js @@ -195,9 +195,20 @@ function Address (faker) { * countryCode * * @method faker.address.countryCode + * @param {string} alphaCode default alpha-2 */ - this.countryCode = function () { + this.countryCode = function (alphaCode) { + + if (typeof alphaCode === 'undefined' || alphaCode === 'alpha-2') { + return faker.random.arrayElement(faker.definitions.address.country_code); + } + + if (alphaCode === 'alpha-3') { + return faker.random.arrayElement(faker.definitions.address.country_code_alpha_3); + } + return faker.random.arrayElement(faker.definitions.address.country_code); + } /** diff --git a/lib/index.js b/lib/index.js index 764afec5..9c724180 100644 --- a/lib/index.js +++ b/lib/index.js @@ -100,7 +100,7 @@ function Faker (opts) { var _definitions = { "name": ["first_name", "last_name", "prefix", "suffix", "gender", "title", "male_prefix", "female_prefix", "male_first_name", "female_first_name", "male_middle_name", "female_middle_name", "male_last_name", "female_last_name"], - "address": ["city_prefix", "city_suffix", "street_suffix", "county", "country", "country_code", "state", "state_abbr", "street_prefix", "postcode", "postcode_by_state", "direction", "direction_abbr", "time_zone"], + "address": ["city_prefix", "city_suffix", "street_suffix", "county", "country", "country_code", "country_code_alpha_3", "state", "state_abbr", "street_prefix", "postcode", "postcode_by_state", "direction", "direction_abbr", "time_zone"], "company": ["adjective", "noun", "descriptor", "bs_adjective", "bs_noun", "bs_verb", "suffix"], "lorem": ["words"], "hacker": ["abbreviation", "adjective", "noun", "verb", "ingverb", "phrase"], diff --git a/lib/locales/en/address/country_code_alpha_3.js b/lib/locales/en/address/country_code_alpha_3.js new file mode 100644 index 00000000..54eba176 --- /dev/null +++ b/lib/locales/en/address/country_code_alpha_3.js @@ -0,0 +1,252 @@ +module["exports"] = [ + "BGD", + "BEL", + "BFA", + "BGR", + "BIH", + "BRB", + "WLF", + "BLM", + "BMU", + "BRN", + "BOL", + "BHR", + "BDI", + "BEN", + "BTN", + "JAM", + "BVT", + "BWA", + "WSM", + "BES", + "BRA", + "BHS", + "JEY", + "BLR", + "BLZ", + "RUS", + "RWA", + "SRB", + "TLS", + "REU", + "TKM", + "TJK", + "ROU", + "TKL", + "GNB", + "GUM", + "GTM", + "SGS", + "GRC", + "GNQ", + "GLP", + "JPN", + "GUY", + "GGY", + "GUF", + "GEO", + "GRD", + "GBR", + "GAB", + "SLV", + "GIN", + "GMB", + "GRL", + "GIB", + "GHA", + "OMN", + "TUN", + "JOR", + "HRV", + "HTI", + "HUN", + "HKG", + "HND", + "HMD", + "VEN", + "PRI", + "PSE", + "PLW", + "PRT", + "SJM", + "PRY", + "IRQ", + "PAN", + "PYF", + "PNG", + "PER", + "PAK", + "PHL", + "PCN", + "POL", + "SPM", + "ZMB", + "ESH", + "EST", + "EGY", + "ZAF", + "ECU", + "ITA", + "VNM", + "SLB", + "ETH", + "SOM", + "ZWE", + "SAU", + "ESP", + "ERI", + "MNE", + "MDA", + "MDG", + "MAF", + "MAR", + "MCO", + "UZB", + "MMR", + "MLI", + "MAC", + "MNG", + "MHL", + "MKD", + "MUS", + "MLT", + "MWI", + "MDV", + "MTQ", + "MNP", + "MSR", + "MRT", + "IMN", + "UGA", + "TZA", + "MYS", + "MEX", + "ISR", + "FRA", + "IOT", + "SHN", + "FIN", + "FJI", + "FLK", + "FSM", + "FRO", + "NIC", + "NLD", + "NOR", + "NAM", + "VUT", + "NCL", + "NER", + "NFK", + "NGA", + "NZL", + "NPL", + "NRU", + "NIU", + "COK", + "XKX", + "CIV", + "CHE", + "COL", + "CHN", + "CMR", + "CHL", + "CCK", + "CAN", + "COG", + "CAF", + "COD", + "CZE", + "CYP", + "CXR", + "CRI", + "CUW", + "CPV", + "CUB", + "SWZ", + "SYR", + "SXM", + "KGZ", + "KEN", + "SSD", + "SUR", + "KIR", + "KHM", + "KNA", + "COM", + "STP", + "SVK", + "KOR", + "SVN", + "PRK", + "KWT", + "SEN", + "SMR", + "SLE", + "SYC", + "KAZ", + "CYM", + "SGP", + "SWE", + "SDN", + "DOM", + "DMA", + "DJI", + "DNK", + "VGB", + "DEU", + "YEM", + "DZA", + "USA", + "URY", + "MYT", + "UMI", + "LBN", + "LCA", + "LAO", + "TUV", + "TWN", + "TTO", + "TUR", + "LKA", + "LIE", + "LVA", + "TON", + "LTU", + "LUX", + "LBR", + "LSO", + "THA", + "ATF", + "TGO", + "TCD", + "TCA", + "LBY", + "VAT", + "VCT", + "ARE", + "AND", + "ATG", + "AFG", + "AIA", + "VIR", + "ISL", + "IRN", + "ARM", + "ALB", + "AGO", + "ATA", + "ASM", + "ARG", + "AUS", + "AUT", + "ABW", + "IND", + "ALA", + "AZE", + "IRL", + "IDN", + "UKR", + "QAT", + "MOZ" +];
\ No newline at end of file diff --git a/lib/locales/en/address/index.js b/lib/locales/en/address/index.js index 05b869c5..d65170cd 100644 --- a/lib/locales/en/address/index.js +++ b/lib/locales/en/address/index.js @@ -5,6 +5,7 @@ address.city_suffix = require("./city_suffix"); address.county = require("./county"); address.country = require("./country"); address.country_code = require("./country_code"); +address.country_code_alpha_3 = require("./country_code_alpha_3"); address.building_number = require("./building_number"); address.street_suffix = require("./street_suffix"); address.secondary_address = require("./secondary_address"); |
