diff options
| author | Marak <[email protected]> | 2021-02-11 01:24:16 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-02-11 01:24:16 -0500 |
| commit | 9c8b3249ffa8412d305bea0522d5754f88f000ae (patch) | |
| tree | 665bb0c281ea8a170e5c8da414aed1b80e75d86b /lib/lorem.js | |
| parent | 00f18703af6bf46b0435f4cc9ed1838054a79c1c (diff) | |
| parent | 388b6cd8513b3b73daab5278e539f8f6bb600e12 (diff) | |
| download | faker-9c8b3249ffa8412d305bea0522d5754f88f000ae.tar.xz faker-9c8b3249ffa8412d305bea0522d5754f88f000ae.zip | |
Merge branch 'master' into master
Diffstat (limited to 'lib/lorem.js')
| -rw-r--r-- | lib/lorem.js | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/lorem.js b/lib/lorem.js index db6aec72..c25234cb 100644 --- a/lib/lorem.js +++ b/lib/lorem.js @@ -8,13 +8,20 @@ var Lorem = function (faker) { var Helpers = faker.helpers; /** - * word + * generates a word of a specified length * * @method faker.lorem.word - * @param {number} num + * @param {number} length length of the word that should be returned. Defaults to a random length */ - self.word = function (num) { - return faker.random.arrayElement(faker.definitions.lorem.words); + self.word = function (length) { + var hasRightLength = function(word) { return word.length === length; }; + var properLengthWords; + if(typeof length === 'undefined') { + properLengthWords = faker.definitions.lorem.words; + } else { + properLengthWords = faker.definitions.lorem.words.filter(hasRightLength); + } + return faker.random.arrayElement(properLengthWords); }; /** |
