diff options
| author | Marak <[email protected]> | 2018-10-28 15:35:22 -0400 |
|---|---|---|
| committer | Marak <[email protected]> | 2018-10-28 15:35:22 -0400 |
| commit | d3ce6f1a2a9359574e7f31f14d4901648047c45a (patch) | |
| tree | 6b48cb7353efea06ea81c156c86689c5cbaf4ca2 /lib/random.js | |
| parent | 72dce1198fd348f069b8e42e91ef67b74da1009f (diff) | |
| parent | b5bf3649796c5497f3d89450b6dc12dc5c10bd3d (diff) | |
| download | faker-d3ce6f1a2a9359574e7f31f14d4901648047c45a.tar.xz faker-d3ce6f1a2a9359574e7f31f14d4901648047c45a.zip | |
[api] Added vehicle module #555
Diffstat (limited to 'lib/random.js')
| -rw-r--r-- | lib/random.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/random.js b/lib/random.js index f64dbb55..1f99eed3 100644 --- a/lib/random.js +++ b/lib/random.js @@ -241,6 +241,37 @@ function Random (faker, seed) { return faker.random.arrayElement(Object.keys(faker.locales)); }; + /** + * alpha. returns lower/upper alpha characters based count and upcase options + * + * @method faker.random.alpha + * @param {mixed} options // defaults to { count: 1, upcase: false } + */ + this.alpha = function alpha(options) { + if (typeof options === "undefined") { + options = { + count: 1 + } + } else if (typeof options === "number") { + options = { + count: options, + } + } else if (typeof options.count === "undefined") { + options.count = 1 + } + + if (typeof options.upcase === "undefined") { + options.upcase = false; + } + + var wholeString = ""; + for(var i = 0; i < options.count; i++) { + wholeString += faker.random.arrayElement(["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]); + } + + return options.upcase ? wholeString.toUpperCase() : wholeString; + }; + /** * alphaNumeric * |
