aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTyler <[email protected]>2017-10-15 13:42:17 -0700
committerTyler <[email protected]>2017-10-15 13:42:17 -0700
commitef6bec454298f9582ba84dcdd661001586401e60 (patch)
tree87110a1b52be166782bd94c5df557fd033ffebee /lib
parent16ccfa16489be1533297158ee9f1ab5dab1a3b0f (diff)
downloadfaker-ef6bec454298f9582ba84dcdd661001586401e60.tar.xz
faker-ef6bec454298f9582ba84dcdd661001586401e60.zip
add random.alpaha with tests
Diffstat (limited to 'lib')
-rw-r--r--lib/random.js31
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
*