diff options
| author | Marak <[email protected]> | 2017-10-22 14:40:58 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-10-22 14:40:58 -0400 |
| commit | ce92b3aebb0f87e07e5cff03a3b3d8ca56cf5a76 (patch) | |
| tree | 17c39ebd80f9d3e412e9a63678724ac04d85d1d0 /lib/address.js | |
| parent | b78fdff29d5c6c3318948c2c44c7903eed55ce4c (diff) | |
| parent | d92b012aefd60fdc919d03a147dc0f28ababf0cd (diff) | |
| download | faker-ce92b3aebb0f87e07e5cff03a3b3d8ca56cf5a76.tar.xz faker-ce92b3aebb0f87e07e5cff03a3b3d8ca56cf5a76.zip | |
Merge pull request #564 from tylerreichle/add-directions
add directions to Address namespace
Diffstat (limited to 'lib/address.js')
| -rw-r--r-- | lib/address.js | 69 |
1 files changed, 65 insertions, 4 deletions
diff --git a/lib/address.js b/lib/address.js index 0a6f0c5b..21e14ff6 100644 --- a/lib/address.js +++ b/lib/address.js @@ -32,7 +32,7 @@ function Address (faker) { * order to build the city name. * * If no format string is provided one of the following is randomly used: - * + * * * `{{address.cityPrefix}} {{name.firstName}}{{address.citySuffix}}` * * `{{address.cityPrefix}} {{name.firstName}}` * * `{{name.firstName}}{{address.citySuffix}}` @@ -131,7 +131,7 @@ function Address (faker) { this.streetSuffix = function () { return faker.random.arrayElement(faker.definitions.address.street_suffix); } - + /** * streetPrefix * @@ -226,9 +226,70 @@ function Address (faker) { min = min || -180 return faker.random.number({max: max, min:min, precision:0.0001}).toFixed(4); } - + + /** + * direction + * + * @method faker.address.direction + * @param {Boolean} useAbbr return direction abbreviation. defaults to false + */ + this.direction = function (useAbbr) { + if (typeof useAbbr === 'undefined' || useAbbr === false) { + return faker.random.arrayElement(faker.definitions.address.direction); + } + return faker.random.arrayElement(faker.definitions.address.direction_abbr); + } + + this.direction.schema = { + "description": "Generates a direction. Use optional useAbbr bool to return abbrevation", + "sampleResults": ["Northwest", "South", "SW", "E"] + }; + + /** + * cardinal direction + * + * @method faker.address.cardinalDirection + * @param {Boolean} useAbbr return direction abbreviation. defaults to false + */ + this.cardinalDirection = function (useAbbr) { + if (typeof useAbbr === 'undefined' || useAbbr === false) { + return ( + faker.random.arrayElement(faker.definitions.address.direction.slice(0, 4)) + ); + } + return ( + faker.random.arrayElement(faker.definitions.address.direction_abbr.slice(0, 4)) + ); + } + + this.cardinalDirection.schema = { + "description": "Generates a cardinal direction. Use optional useAbbr boolean to return abbrevation", + "sampleResults": ["North", "South", "E", "W"] + }; + + /** + * ordinal direction + * + * @method faker.address.ordinalDirection + * @param {Boolean} useAbbr return direction abbreviation. defaults to false + */ + this.ordinalDirection = function (useAbbr) { + if (typeof useAbbr === 'undefined' || useAbbr === false) { + return ( + faker.random.arrayElement(faker.definitions.address.direction.slice(4, 8)) + ); + } + return ( + faker.random.arrayElement(faker.definitions.address.direction_abbr.slice(4, 8)) + ); + } + + this.ordinalDirection.schema = { + "description": "Generates an ordinal direction. Use optional useAbbr boolean to return abbrevation", + "sampleResults": ["Northwest", "Southeast", "SW", "NE"] + }; + return this; } - module.exports = Address; |
