diff options
| author | Tyler <[email protected]> | 2017-10-15 13:42:17 -0700 |
|---|---|---|
| committer | Tyler <[email protected]> | 2017-10-15 13:42:17 -0700 |
| commit | ef6bec454298f9582ba84dcdd661001586401e60 (patch) | |
| tree | 87110a1b52be166782bd94c5df557fd033ffebee /lib | |
| parent | 16ccfa16489be1533297158ee9f1ab5dab1a3b0f (diff) | |
| download | faker-ef6bec454298f9582ba84dcdd661001586401e60.tar.xz faker-ef6bec454298f9582ba84dcdd661001586401e60.zip | |
add random.alpaha with tests
Diffstat (limited to 'lib')
| -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 8dccf376..1f408fe0 100644 --- a/lib/random.js +++ b/lib/random.js @@ -219,6 +219,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 * |
