diff options
| author | Tyler <[email protected]> | 2017-10-22 11:27:30 -0700 |
|---|---|---|
| committer | Tyler <[email protected]> | 2017-10-22 11:27:30 -0700 |
| commit | d92b012aefd60fdc919d03a147dc0f28ababf0cd (patch) | |
| tree | 17c39ebd80f9d3e412e9a63678724ac04d85d1d0 /lib/address.js | |
| parent | 07929b4c54ea386e5fab198b87b8a05493676c29 (diff) | |
| download | faker-d92b012aefd60fdc919d03a147dc0f28ababf0cd.tar.xz faker-d92b012aefd60fdc919d03a147dc0f28ababf0cd.zip | |
add direction abbr options with tests
Diffstat (limited to 'lib/address.js')
| -rw-r--r-- | lib/address.js | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/lib/address.js b/lib/address.js index 5d98554e..21e14ff6 100644 --- a/lib/address.js +++ b/lib/address.js @@ -231,46 +231,62 @@ function Address (faker) { * direction * * @method faker.address.direction + * @param {Boolean} useAbbr return direction abbreviation. defaults to false */ - this.direction = function () { - return faker.random.arrayElement(faker.definitions.address.direction); + 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.", - "sampleResults": ["NW", "S", "SW", "E"] + "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 () { + 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.slice(0, 4)) + faker.random.arrayElement(faker.definitions.address.direction_abbr.slice(0, 4)) ); } this.cardinalDirection.schema = { - "description": "Generates a cardinal direction.", - "sampleResults": ["N", "S", "E", "W"] + "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 () { + 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.slice(4, 8)) + faker.random.arrayElement(faker.definitions.address.direction_abbr.slice(4, 8)) ); } this.ordinalDirection.schema = { - "description": "Generates an ordinal direction.", - "sampleResults": ["NW", "SE", "SW", "NE"] + "description": "Generates an ordinal direction. Use optional useAbbr boolean to return abbrevation", + "sampleResults": ["Northwest", "Southeast", "SW", "NE"] }; return this; |
