aboutsummaryrefslogtreecommitdiff
path: root/lib/lorem.js
diff options
context:
space:
mode:
authorLuiz Strobelt <[email protected]>2020-10-01 00:28:36 -0300
committerGitHub <[email protected]>2020-10-01 00:28:36 -0300
commit5df3678f842383855c53a4c14d39a20deb64f7cc (patch)
tree3b9fb614af27c68cfae7cdf76929069f8935ec0c /lib/lorem.js
parent27f4878ab3d989cdddec9df99802fe2150730ba2 (diff)
parent91dc8a3372426bc691be56153b33e81a16459f49 (diff)
downloadfaker-5df3678f842383855c53a4c14d39a20deb64f7cc.tar.xz
faker-5df3678f842383855c53a4c14d39a20deb64f7cc.zip
Merge pull request #1 from Marak/master
Update to latest base branch
Diffstat (limited to 'lib/lorem.js')
-rw-r--r--lib/lorem.js15
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);
};
/**