1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | var Lorem = function (faker) {
|
7 | var self = this;
|
8 | var Helpers = faker.helpers;
|
9 |
|
10 | |
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | self.word = function (length) {
|
17 | var hasRightLength = function(word) { return word.length === length; };
|
18 | var properLengthWords;
|
19 | if(typeof length === 'undefined') {
|
20 | properLengthWords = faker.definitions.lorem.words;
|
21 | } else {
|
22 | properLengthWords = faker.definitions.lorem.words.filter(hasRightLength);
|
23 | }
|
24 | return faker.random.arrayElement(properLengthWords);
|
25 | };
|
26 |
|
27 | |
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | self.words = function (num) {
|
34 | if (typeof num == 'undefined') { num = 3; }
|
35 | var words = [];
|
36 | for (var i = 0; i < num; i++) {
|
37 | words.push(faker.lorem.word());
|
38 | }
|
39 | return words.join(' ');
|
40 | };
|
41 |
|
42 | |
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | self.sentence = function (wordCount, range) {
|
50 | if (typeof wordCount == 'undefined') { wordCount = faker.datatype.number({ min: 3, max: 10 }); }
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | var sentence = faker.lorem.words(wordCount);
|
57 | return sentence.charAt(0).toUpperCase() + sentence.slice(1) + '.';
|
58 | };
|
59 |
|
60 | |
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | self.slug = function (wordCount) {
|
67 | var words = faker.lorem.words(wordCount);
|
68 | return Helpers.slugify(words);
|
69 | };
|
70 |
|
71 | |
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 | self.sentences = function (sentenceCount, separator) {
|
79 | if (typeof sentenceCount === 'undefined') { sentenceCount = faker.datatype.number({ min: 2, max: 6 });}
|
80 | if (typeof separator == 'undefined') { separator = " "; }
|
81 | var sentences = [];
|
82 | for (sentenceCount; sentenceCount > 0; sentenceCount--) {
|
83 | sentences.push(faker.lorem.sentence());
|
84 | }
|
85 | return sentences.join(separator);
|
86 | };
|
87 |
|
88 | |
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | self.paragraph = function (sentenceCount) {
|
95 | if (typeof sentenceCount == 'undefined') { sentenceCount = 3; }
|
96 | return faker.lorem.sentences(sentenceCount + faker.datatype.number(3));
|
97 | };
|
98 |
|
99 | |
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 | self.paragraphs = function (paragraphCount, separator) {
|
107 | if (typeof separator === "undefined") {
|
108 | separator = "\n \r";
|
109 | }
|
110 | if (typeof paragraphCount == 'undefined') { paragraphCount = 3; }
|
111 | var paragraphs = [];
|
112 | for (paragraphCount; paragraphCount > 0; paragraphCount--) {
|
113 | paragraphs.push(faker.lorem.paragraph());
|
114 | }
|
115 | return paragraphs.join(separator);
|
116 | }
|
117 |
|
118 | |
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 | self.text = function loremText (times) {
|
125 | var loremMethods = ['lorem.word', 'lorem.words', 'lorem.sentence', 'lorem.sentences', 'lorem.paragraph', 'lorem.paragraphs', 'lorem.lines'];
|
126 | var randomLoremMethod = faker.random.arrayElement(loremMethods);
|
127 | return faker.fake('{{' + randomLoremMethod + '}}');
|
128 | };
|
129 |
|
130 | |
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 | self.lines = function lines (lineCount) {
|
137 | if (typeof lineCount === 'undefined') { lineCount = faker.datatype.number({ min: 1, max: 5 });}
|
138 | return faker.lorem.sentences(lineCount, '\n')
|
139 | };
|
140 |
|
141 | return self;
|
142 | };
|
143 |
|
144 |
|
145 | module["exports"] = Lorem;
|