From ba22bcc267ec0900532ee58198a8a7908c5c9727 Mon Sep 17 00:00:00 2001 From: Morgan Denis Date: Fri, 12 Feb 2021 10:06:17 +0100 Subject: Allow using real city name when available --- lib/address.js | 13 +++++++++++++ lib/index.js | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/address.js b/lib/address.js index 38c1e38c..1ccbfdc9 100644 --- a/lib/address.js +++ b/lib/address.js @@ -60,6 +60,10 @@ function Address (faker) { * @param {String} format */ this.city = function (format) { + if (!format && faker.definitions.address.city_name) { + return this.cityName(); + } + var formats = [ '{{address.cityPrefix}} {{name.firstName}}{{address.citySuffix}}', '{{address.cityPrefix}} {{name.firstName}}', @@ -92,6 +96,15 @@ function Address (faker) { return faker.random.arrayElement(faker.definitions.address.city_suffix); } + /** + * Returns a random city name + * + * @method faker.address.cityName + */ + this.cityName = function() { + return faker.random.arrayElement(faker.definitions.address.city_name); + } + /** * Returns a random localized street name * diff --git a/lib/index.js b/lib/index.js index 16def0a3..205adec5 100644 --- a/lib/index.js +++ b/lib/index.js @@ -103,7 +103,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", "country_code_alpha_3", "state", "state_abbr", "street_prefix", "postcode", "postcode_by_state", "direction", "direction_abbr", "time_zone"], + "address": ["city_name", "city_prefix", "city_suffix", "street_suffix", "county", "country", "country_code", "country_code_alpha_3", "state", "state_abbr", "street_prefix", "postcode", "postcode_by_state", "direction", "direction_abbr", "time_zone"], "company": ["adjective", "noun", "descriptor", "bs_adjective", "bs_noun", "bs_verb", "suffix"], "lorem": ["words"], "hacker": ["abbreviation", "adjective", "noun", "verb", "ingverb", "phrase"], -- cgit v1.2.3