diff options
| author | Matthew Bergman <[email protected]> | 2013-01-08 09:35:00 -0800 |
|---|---|---|
| committer | Matthew Bergman <[email protected]> | 2013-01-08 09:35:00 -0800 |
| commit | fd79022a8cb6d0d3adc50e8af96a5e2ae93d8e53 (patch) | |
| tree | 28c0bd9453cf4e6d273b97bfe2ce53cab11d3330 /lib/random.js | |
| parent | 1e4fcf794181b8d8c9286ee1890a903199f81847 (diff) | |
| parent | 19d0e99ebec18bab6047bf944c07fc472fd9773a (diff) | |
| download | faker-fd79022a8cb6d0d3adc50e8af96a5e2ae93d8e53.tar.xz faker-fd79022a8cb6d0d3adc50e8af96a5e2ae93d8e53.zip | |
Merge pull request #37 from BryanDonovan/main
Refactored with 100% test coverage
Diffstat (limited to 'lib/random.js')
| -rw-r--r-- | lib/random.js | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/lib/random.js b/lib/random.js new file mode 100644 index 00000000..2a149ee0 --- /dev/null +++ b/lib/random.js @@ -0,0 +1,101 @@ +var definitions = require('./definitions'); + +var random = { + // returns a single random number based on a range + number: function (range) { + return Math.floor(Math.random() * range); + }, + + // takes an array and returns the array randomly sorted + array_element: function (array) { + var r = Math.floor(Math.random() * array.length); + return array[r]; + }, + + city_prefix: function () { + return this.array_element(definitions.city_prefix()); + }, + + city_suffix: function () { + return this.array_element(definitions.city_suffix()); + }, + + street_suffix: function () { + return this.array_element(definitions.street_suffix()); + }, + + br_state: function () { + return this.array_element(definitions.br_state()); + }, + + br_state_abbr: function () { + return this.array_element(definitions.br_state_abbr()); + }, + + us_state: function () { + return this.array_element(definitions.us_state()); + }, + + us_state_abbr: function () { + return this.array_element(definitions.us_state_abbr()); + }, + + uk_county: function () { + return this.array_element(definitions.uk_county()); + }, + + uk_country: function () { + return this.array_element(definitions.uk_country()); + }, + + first_name: function () { + return this.array_element(definitions.first_name()); + }, + + last_name: function () { + return this.array_element(definitions.last_name()); + }, + + name_prefix: function () { + return this.array_element(definitions.name_prefix()); + }, + + name_suffix: function () { + return this.array_element(definitions.name_suffix()); + }, + + catch_phrase_adjective: function () { + return this.array_element(definitions.catch_phrase_adjective()); + }, + + catch_phrase_descriptor: function () { + return this.array_element(definitions.catch_phrase_descriptor()); + }, + + catch_phrase_noun: function () { + return this.array_element(definitions.catch_phrase_noun()); + }, + + bs_adjective: function () { + return this.array_element(definitions.bs_adjective()); + }, + + bs_buzz: function () { + return this.array_element(definitions.bs_buzz()); + }, + + bs_noun: function () { + return this.array_element(definitions.bs_noun()); + }, + + phone_formats: function () { + return this.array_element(definitions.phone_formats()); + }, + + domain_suffix: function () { + return this.array_element(definitions.domain_suffix()); + } + +}; + +module.exports = random; |
