faker 5.3.1 → 5.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{.jshintignore → .eslintignore} +0 -0
- package/.eslintrc +54 -0
- package/.travis.yml +3 -0
- package/Readme.md +48 -3
- package/dist/faker.js +71873 -39072
- package/dist/faker.min.js +1 -1
- package/lib/address.js +121 -107
- package/lib/animal.js +124 -0
- package/lib/commerce.js +16 -16
- package/lib/company.js +8 -8
- package/lib/database.js +4 -4
- package/lib/datatype.js +226 -0
- package/lib/date.js +94 -72
- package/lib/finance.js +44 -22
- package/lib/git.js +1 -1
- package/lib/helpers.js +8 -8
- package/lib/iban.js +22 -14
- package/lib/image.js +14 -14
- package/lib/image_providers/lorempixel.js +1 -1
- package/lib/index.js +58 -47
- package/lib/internet.js +148 -119
- package/lib/locales/af_ZA/name/female_first_name.js +112 -112
- package/lib/locales/af_ZA/name/first_name.js +222 -222
- package/lib/locales/af_ZA/name/male_first_name.js +115 -115
- package/lib/locales/ar/address/state.js +62 -1
- package/lib/locales/ar/date/index.js +4 -0
- package/lib/locales/ar/date/month.js +63 -0
- package/lib/locales/ar/date/weekday.js +22 -0
- package/lib/locales/ar/index.js +2 -0
- package/lib/locales/cz/address/index.js +0 -1
- package/lib/locales/cz/name/first_name.js +3 -0
- package/lib/locales/cz/name/index.js +2 -0
- package/lib/locales/cz/name/last_name.js +3 -0
- package/lib/locales/de_CH/address/city.js +3 -0
- package/lib/locales/de_CH/address/city_name.js +102 -0
- package/lib/locales/de_CH/address/index.js +4 -0
- package/lib/locales/de_CH/address/state.js +28 -0
- package/lib/locales/de_CH/address/state_abbr.js +28 -0
- package/lib/locales/de_CH/name/first_name.js +336 -336
- package/lib/locales/de_CH/name/last_name.js +209 -209
- package/lib/locales/en/address/city_name.js +1002 -0
- package/lib/locales/en/address/country_code_alpha_3.js +250 -250
- package/lib/locales/en/address/index.js +1 -0
- package/lib/locales/en/animal/bear.js +10 -0
- package/lib/locales/en/animal/bird.js +916 -0
- package/lib/locales/en/animal/cat.js +57 -0
- package/lib/locales/en/animal/cetacean.js +56 -0
- package/lib/locales/en/animal/cow.js +521 -0
- package/lib/locales/en/animal/crocodilia.js +26 -0
- package/lib/locales/en/animal/dog.js +499 -0
- package/lib/locales/en/animal/fish.js +98 -0
- package/lib/locales/en/animal/horse.js +347 -0
- package/lib/locales/en/animal/index.js +16 -0
- package/lib/locales/en/animal/insect.js +132 -0
- package/lib/locales/en/animal/lion.js +9 -0
- package/lib/locales/en/animal/rabbit.js +51 -0
- package/lib/locales/en/animal/snake.js +583 -0
- package/lib/locales/en/animal/type.js +15 -0
- package/lib/locales/en/finance/currency.js +0 -4
- package/lib/locales/en/index.js +1 -0
- package/lib/locales/en/internet/avatar_uri.js +1250 -1254
- package/lib/locales/en/music/genre.js +18 -18
- package/lib/locales/en/name/binary_gender.js +4 -0
- package/lib/locales/en/name/female_first_name.js +501 -501
- package/lib/locales/en/name/gender.js +71 -71
- package/lib/locales/en/name/index.js +1 -0
- package/lib/locales/en/name/male_first_name.js +501 -501
- package/lib/locales/en/system/directoryPaths.js +60 -60
- package/lib/locales/en/vehicle/bicycle.js +20 -0
- package/lib/locales/en/vehicle/index.js +1 -0
- package/lib/locales/en_GH/address/building_number.js +5 -0
- package/lib/locales/en_GH/address/city.js +3 -0
- package/lib/locales/en_GH/address/city_name.js +355 -0
- package/lib/locales/en_GH/address/default_country.js +3 -0
- package/lib/locales/en_GH/address/index.js +12 -0
- package/lib/locales/en_GH/address/postcode.js +4 -0
- package/lib/locales/en_GH/address/state.js +18 -0
- package/lib/locales/en_GH/address/street_address.js +3 -0
- package/lib/locales/en_GH/address/street_name.js +4 -0
- package/lib/locales/en_GH/address/street_prefix.js +3 -0
- package/lib/locales/en_GH/address/street_suffix.js +10 -0
- package/lib/locales/en_GH/company/index.js +4 -0
- package/lib/locales/en_GH/company/name.js +4 -0
- package/lib/locales/en_GH/company/suffix.js +4 -0
- package/lib/locales/en_GH/index.js +8 -0
- package/lib/locales/en_GH/internet/domain_suffix.js +11 -0
- package/lib/locales/en_GH/internet/index.js +3 -0
- package/lib/locales/en_GH/name/female_first_name.js +146 -0
- package/lib/locales/en_GH/name/first_name.js +4 -0
- package/lib/locales/en_GH/name/index.js +7 -0
- package/lib/locales/en_GH/name/last_name.js +124 -0
- package/lib/locales/en_GH/name/male_first_name.js +134 -0
- package/lib/locales/en_GH/name/name.js +6 -0
- package/lib/locales/en_GH/phone_number/formats.js +28 -0
- package/lib/locales/{nep → en_GH}/phone_number/index.js +0 -0
- package/lib/locales/en_NG/address/city_prefix.js +525 -525
- package/lib/locales/en_NG/address/state.js +37 -37
- package/lib/locales/en_NG/name/female_first_name.js +13 -13
- package/lib/locales/en_NG/name/first_name.js +33 -33
- package/lib/locales/en_NG/name/male_first_name.js +22 -22
- package/lib/locales/en_NG/phone_number/formats.js +5 -5
- package/lib/locales/en_US/address/postcode_by_state.js +104 -104
- package/lib/locales/en_ZA/address/city_prefix.js +14 -14
- package/lib/locales/en_ZA/address/state.js +9 -9
- package/lib/locales/en_ZA/cell_phone/formats.js +18 -18
- package/lib/locales/en_ZA/name/female_first_name.js +292 -292
- package/lib/locales/en_ZA/name/first_name.js +539 -539
- package/lib/locales/en_ZA/name/male_first_name.js +252 -252
- package/lib/locales/es/commerce/color.js +9 -9
- package/lib/locales/es/commerce/department.js +19 -19
- package/lib/locales/es/commerce/product_name.js +54 -54
- package/lib/locales/es/name/female_first_name.js +12 -12
- package/lib/locales/es/name/male_first_name.js +17 -17
- package/lib/locales/es_MX/address/street.js +39 -39
- package/lib/locales/es_MX/commerce/color.js +31 -31
- package/lib/locales/es_MX/commerce/department.js +22 -22
- package/lib/locales/es_MX/commerce/product_name.js +56 -56
- package/lib/locales/es_MX/company/bs_noun.js +44 -44
- package/lib/locales/es_MX/company/bs_verb.js +60 -60
- package/lib/locales/es_MX/lorem/words.js +268 -268
- package/lib/locales/es_MX/name/first_name.js +304 -304
- package/lib/locales/es_MX/name/last_name.js +686 -686
- package/lib/locales/es_MX/name/title.js +1 -1
- package/lib/locales/es_MX/team/creature.js +66 -66
- package/lib/locales/fa/name/female_first_name.js +67 -67
- package/lib/locales/fa/name/male_first_name.js +74 -74
- package/lib/locales/fa/vehicle/model.js +1 -1
- package/lib/locales/fi/name/female_first_name.js +50 -50
- package/lib/locales/fi/name/first_name.js +100 -100
- package/lib/locales/fi/name/last_name.js +50 -50
- package/lib/locales/fi/name/male_first_name.js +50 -50
- package/lib/locales/fr/address/city_name.js +84 -84
- package/lib/locales/fr/address/country.js +195 -0
- package/lib/locales/fr/address/index.js +1 -0
- package/lib/locales/fr/name/female_first_name.js +451 -451
- package/lib/locales/fr/name/first_name.js +3 -0
- package/lib/locales/fr/name/index.js +1 -0
- package/lib/locales/fr/name/male_first_name.js +496 -496
- package/lib/locales/fr_BE/adresses/building_number.js +12 -0
- package/lib/locales/fr_BE/adresses/city.js +4 -0
- package/lib/locales/fr_BE/adresses/city_prefix.js +265 -0
- package/lib/locales/fr_BE/adresses/city_suffix.js +6 -0
- package/lib/locales/fr_BE/adresses/default_country.js +3 -0
- package/lib/locales/fr_BE/adresses/index.js +25 -0
- package/lib/locales/fr_BE/adresses/postcode.js +3 -0
- package/lib/locales/fr_BE/adresses/state.js +12 -0
- package/lib/locales/fr_BE/adresses/state_abbr.js +11 -0
- package/lib/locales/fr_BE/adresses/street_address.js +3 -0
- package/lib/locales/fr_BE/adresses/street_name.js +5 -0
- package/lib/locales/fr_BE/adresses/street_prefix.js +21 -0
- package/lib/locales/fr_BE/adresses/street_suffix.js +212 -0
- package/lib/locales/fr_BE/cell_phone/formats.js +34 -0
- package/lib/locales/fr_BE/cell_phone/index.js +3 -0
- package/lib/locales/fr_BE/index.js +20 -0
- package/lib/locales/fr_BE/internet/domain_suffix.js +10 -0
- package/lib/locales/fr_BE/internet/free_email.js +6 -0
- package/lib/locales/{nep → fr_BE}/internet/index.js +0 -0
- package/lib/locales/fr_BE/name/first_name.js +3009 -0
- package/lib/locales/fr_BE/name/first_name_female.js +1532 -0
- package/lib/locales/fr_BE/name/first_name_male.js +1482 -0
- package/lib/locales/fr_BE/name/gender.js +10 -0
- package/lib/locales/fr_BE/name/index.js +11 -0
- package/lib/locales/fr_BE/name/last_name.js +624 -0
- package/lib/locales/fr_BE/name/name.js +8 -0
- package/lib/locales/fr_BE/name/prefix.js +6 -0
- package/lib/locales/fr_BE/name/suffix.js +8 -0
- package/lib/locales/fr_BE/name/title.js +22 -0
- package/lib/locales/fr_BE/phone_number/formats.js +93 -0
- package/lib/locales/fr_BE/phone_number/index.js +3 -0
- package/lib/locales/hr/address/city_name.js +128 -128
- package/lib/locales/hr/address/country.js +246 -246
- package/lib/locales/hr/address/street.js +375 -375
- package/lib/locales/hr/date/month.js +24 -24
- package/lib/locales/hr/date/weekday.js +7 -7
- package/lib/locales/hr/name/female_first_name.js +238 -238
- package/lib/locales/hr/name/first_name.js +409 -409
- package/lib/locales/hr/name/last_name.js +11617 -11617
- package/lib/locales/hr/name/male_first_name.js +171 -171
- package/lib/locales/hr/name/name.js +6 -6
- package/lib/locales/hr/name/prefix.js +5 -5
- package/lib/locales/hr/name/suffix.js +2 -2
- package/lib/locales/hy/address/building_number.js +8 -0
- package/lib/locales/hy/address/city.js +4 -0
- package/lib/locales/hy/address/city_prefix.js +7 -0
- package/lib/locales/hy/address/city_suffix.js +5 -0
- package/lib/locales/hy/address/country.js +231 -0
- package/lib/locales/hy/address/default_country.js +3 -0
- package/lib/locales/hy/address/direction.js +10 -0
- package/lib/locales/hy/address/index.js +14 -0
- package/lib/locales/hy/address/secondary_address.js +4 -0
- package/lib/locales/hy/address/state.js +21 -0
- package/lib/locales/hy/address/street_address.js +3 -0
- package/lib/locales/hy/address/street_name.js +3 -0
- package/lib/locales/hy/address/street_suffix.js +4 -0
- package/lib/locales/hy/commerce/color.js +14 -0
- package/lib/locales/hy/commerce/index.js +3 -0
- package/lib/locales/hy/date/index.js +4 -0
- package/lib/locales/hy/date/month.js +30 -0
- package/lib/locales/hy/date/weekday.js +21 -0
- package/lib/locales/hy/index.js +11 -0
- package/lib/locales/hy/internet/domain_suffix.js +9 -0
- package/lib/locales/hy/internet/index.js +3 -0
- package/lib/locales/hy/lorem/index.js +3 -0
- package/lib/locales/hy/lorem/words.js +191 -0
- package/lib/locales/hy/name/female_first_name.js +48 -0
- package/lib/locales/hy/name/first_name.js +93 -0
- package/lib/locales/hy/name/index.js +7 -0
- package/lib/locales/hy/name/last_name.js +94 -0
- package/lib/locales/hy/name/male_first_name.js +47 -0
- package/lib/locales/hy/name/name.js +8 -0
- package/lib/locales/hy/phone_number/formats.js +4 -0
- package/lib/locales/hy/phone_number/index.js +3 -0
- package/lib/locales/id_ID/name/female_first_name.js +45 -1
- package/lib/locales/id_ID/name/female_last_name.js +41 -1
- package/lib/locales/id_ID/name/male_last_name.js +47 -2
- package/lib/locales/it/address/city_name.js +981 -0
- package/lib/locales/it/address/index.js +1 -0
- package/lib/locales/it/name/last_name.js +2163 -628
- package/lib/locales/ja/address/country.js +169 -0
- package/lib/locales/ja/address/index.js +1 -0
- package/lib/locales/ko/address/postcode.js +2 -1
- package/lib/locales/ko/name/first_name.js +2994 -1
- package/lib/locales/ko/name/last_name.js +98 -1
- package/lib/locales/lv/commerce/product_name.js +14 -14
- package/lib/locales/nb_NO/name/index.js +2 -2
- package/lib/locales/{nep → ne}/address/city.js +0 -0
- package/lib/locales/{nep → ne}/address/default_country.js +0 -0
- package/lib/locales/{nep → ne}/address/index.js +0 -0
- package/lib/locales/{nep → ne}/address/postcode.js +0 -0
- package/lib/locales/{nep → ne}/address/state.js +0 -0
- package/lib/locales/{nep → ne}/company/index.js +0 -0
- package/lib/locales/{nep → ne}/company/suffix.js +0 -0
- package/lib/locales/ne/index.js +8 -0
- package/lib/locales/{nep → ne}/internet/domain_suffix.js +0 -0
- package/lib/locales/{nep → ne}/internet/free_email.js +0 -0
- package/lib/locales/ne/internet/index.js +4 -0
- package/lib/locales/{nep → ne}/name/first_name.js +0 -0
- package/lib/locales/{nep → ne}/name/index.js +0 -0
- package/lib/locales/{nep → ne}/name/last_name.js +0 -0
- package/lib/locales/{nep → ne}/phone_number/formats.js +0 -0
- package/lib/locales/ne/phone_number/index.js +3 -0
- package/lib/locales/nl/address/country.js +5 -7
- package/lib/locales/nl/address/secondary_address.js +2 -1
- package/lib/locales/nl/address/street_suffix.js +3 -1
- package/lib/locales/nl/commerce/color.js +38 -0
- package/lib/locales/nl/commerce/department.js +24 -0
- package/lib/locales/nl/commerce/index.js +5 -0
- package/lib/locales/nl/commerce/product_name.js +72 -0
- package/lib/locales/nl/company/suffix.js +5 -2
- package/lib/locales/nl/date/index.js +4 -0
- package/lib/locales/nl/date/month.js +63 -0
- package/lib/locales/nl/date/weekday.js +43 -0
- package/lib/locales/nl/hacker/adjective.js +25 -0
- package/lib/locales/nl/hacker/index.js +6 -0
- package/lib/locales/nl/hacker/noun.js +28 -0
- package/lib/locales/nl/hacker/phrase.js +10 -0
- package/lib/locales/nl/hacker/verb.js +23 -0
- package/lib/locales/nl/index.js +3 -0
- package/lib/locales/nl/internet/domain_suffix.js +2 -1
- package/lib/locales/nl/name/female_first_name.js +517 -0
- package/lib/locales/nl/name/index.js +2 -0
- package/lib/locales/nl/name/male_first_name.js +590 -0
- package/lib/locales/pl/name/female_first_name.js +176 -0
- package/lib/locales/pl/name/first_name.js +3 -410
- package/lib/locales/pl/name/male_first_name.js +236 -0
- package/lib/locales/pt_BR/address/city_suffix.js +4 -0
- package/lib/locales/pt_BR/address/country.js +41 -44
- package/lib/locales/pt_BR/address/state_abbr.js +4 -1
- package/lib/locales/pt_BR/company/suffix.js +1 -0
- package/lib/locales/pt_BR/name/female_first_name.js +82 -0
- package/lib/locales/pt_BR/name/index.js +2 -0
- package/lib/locales/pt_BR/name/male_first_name.js +90 -0
- package/lib/locales/pt_BR/name/name.js +8 -0
- package/lib/locales/pt_BR/name/prefix.js +2 -1
- package/lib/locales/pt_PT/phone_number/formats.js +1 -0
- package/lib/locales/ro/address/city.js +300 -300
- package/lib/locales/ro/address/county.js +42 -42
- package/lib/locales/ro/address/state.js +42 -42
- package/lib/locales/ro/address/state_abbr.js +42 -42
- package/lib/locales/ro/address/street_address.js +1 -1
- package/lib/locales/ro/address/street_suffix.js +3 -3
- package/lib/locales/ro/address/streets.js +100 -100
- package/lib/locales/ro/cell_phone/formats.js +59 -59
- package/lib/locales/ro/internet/domain_suffix.js +19 -19
- package/lib/locales/ro/internet/index.js +0 -1
- package/lib/locales/ro/name/female_first_name.js +387 -387
- package/lib/locales/ro/name/last_name.js +300 -300
- package/lib/locales/ro/name/male_first_name.js +288 -288
- package/lib/locales/ro/name/name.js +32 -32
- package/lib/locales/ro/name/prefix.js +3 -3
- package/lib/locales/ro/name/suffix.js +2 -2
- package/lib/locales/ro/phone_number/formats.js +82 -82
- package/lib/locales/sk/address/index.js +0 -1
- package/lib/locales/tr/name/female_first_name.js +416 -0
- package/lib/locales/tr/name/index.js +2 -0
- package/lib/locales/tr/name/male_first_name.js +754 -0
- package/lib/locales/tr/name/name.js +2 -2
- package/lib/locales/vi/name/female_first_name.js +1312 -0
- package/lib/locales/vi/name/first_name.js +3 -28
- package/lib/locales/vi/name/index.js +5 -3
- package/lib/locales/vi/name/last_name.js +1 -48
- package/lib/locales/vi/name/male_first_name.js +1227 -0
- package/lib/locales/vi/name/name.js +3 -2
- package/lib/locales/zu_ZA/name/female_first_name.js +50 -50
- package/lib/locales/zu_ZA/name/first_name.js +100 -100
- package/lib/locales/zu_ZA/name/last_name.js +100 -100
- package/lib/locales/zu_ZA/name/male_first_name.js +51 -51
- package/lib/locales.js +2 -1
- package/lib/lorem.js +25 -25
- package/lib/mersenne.js +31 -0
- package/lib/music.js +9 -9
- package/lib/name.js +36 -32
- package/lib/phone_number.js +4 -4
- package/lib/random.js +138 -150
- package/lib/system.js +114 -63
- package/lib/time.js +1 -1
- package/lib/vehicle.js +38 -4
- package/locale/ReadMe.md +1 -1
- package/locale/en.js +1 -1
- package/locale/en_GH.js +5 -0
- package/locale/hy.js +5 -0
- package/locale/ne.js +5 -0
- package/package.json +4 -3
- package/vendor/mersenne.js +194 -222
- package/vendor/user-agent.js +155 -155
- package/.jshintrc +0 -87
- package/lib/locales/cz/address/time_zone.js +0 -145
- package/lib/locales/el/internet/avatar_uri.js +0 -1256
- package/lib/locales/nep/index.js +0 -8
- package/lib/locales/ro/internet/avatar_uri.js +0 -1265
- package/lib/locales/sk/address/time_zone.js +0 -145
- package/locale/nep.js +0 -5
package/lib/random.js
CHANGED
|
@@ -1,84 +1,55 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Method to reduce array of characters
|
|
3
|
+
* @param arr existing array of characters
|
|
4
|
+
* @param values array of characters which should be removed
|
|
5
|
+
* @return {*} new array without banned characters
|
|
6
|
+
*/
|
|
7
|
+
var arrayRemove = function (arr, values) {
|
|
8
|
+
values.forEach(function(value){
|
|
9
|
+
arr = arr.filter(function(ele){
|
|
10
|
+
return ele !== value;
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
return arr;
|
|
14
|
+
};
|
|
2
15
|
|
|
3
16
|
/**
|
|
4
17
|
*
|
|
5
18
|
* @namespace faker.random
|
|
6
19
|
*/
|
|
7
20
|
function Random (faker, seed) {
|
|
8
|
-
// Use a user provided seed if it
|
|
9
|
-
if (seed) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
mersenne.seed(seed);
|
|
15
|
-
}
|
|
21
|
+
// Use a user provided seed if it is an array or number
|
|
22
|
+
if (Array.isArray(seed) && seed.length) {
|
|
23
|
+
faker.mersenne.seed_array(seed);
|
|
24
|
+
}
|
|
25
|
+
else if(!isNaN(seed)) {
|
|
26
|
+
faker.mersenne.seed(seed);
|
|
16
27
|
}
|
|
28
|
+
|
|
17
29
|
/**
|
|
30
|
+
* @Deprecated
|
|
18
31
|
* returns a single random number based on a max number or range
|
|
19
32
|
*
|
|
20
33
|
* @method faker.random.number
|
|
21
34
|
* @param {mixed} options {min, max, precision}
|
|
22
35
|
*/
|
|
23
36
|
this.number = function (options) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
max: options
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
options = options || {};
|
|
32
|
-
|
|
33
|
-
if (typeof options.min === "undefined") {
|
|
34
|
-
options.min = 0;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (typeof options.max === "undefined") {
|
|
38
|
-
options.max = 99999;
|
|
39
|
-
}
|
|
40
|
-
if (typeof options.precision === "undefined") {
|
|
41
|
-
options.precision = 1;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Make the range inclusive of the max value
|
|
45
|
-
var max = options.max;
|
|
46
|
-
if (max >= 0) {
|
|
47
|
-
max += options.precision;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
var randomNumber = Math.floor(
|
|
51
|
-
mersenne.rand(max / options.precision, options.min / options.precision));
|
|
52
|
-
// Workaround problem in Float point arithmetics for e.g. 6681493 / 0.01
|
|
53
|
-
randomNumber = randomNumber / (1 / options.precision);
|
|
54
|
-
|
|
55
|
-
return randomNumber;
|
|
56
|
-
|
|
57
|
-
}
|
|
37
|
+
console.log("Deprecation Warning: faker.random.number is now located in faker.datatype.number");
|
|
38
|
+
return faker.datatype.number(options);
|
|
39
|
+
};
|
|
58
40
|
|
|
59
41
|
/**
|
|
42
|
+
* @Deprecated
|
|
60
43
|
* returns a single random floating-point number based on a max number or range
|
|
61
44
|
*
|
|
62
45
|
* @method faker.random.float
|
|
63
46
|
* @param {mixed} options
|
|
64
47
|
*/
|
|
65
48
|
this.float = function (options) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
options = options || {};
|
|
72
|
-
var opts = {};
|
|
73
|
-
for (var p in options) {
|
|
74
|
-
opts[p] = options[p];
|
|
75
|
-
}
|
|
76
|
-
if (typeof opts.precision === 'undefined') {
|
|
77
|
-
opts.precision = 0.01;
|
|
78
|
-
}
|
|
79
|
-
return faker.random.number(opts);
|
|
80
|
-
}
|
|
81
|
-
|
|
49
|
+
console.log("Deprecation Warning: faker.random.float is now located in faker.datatype.float");
|
|
50
|
+
return faker.datatype.float(options);
|
|
51
|
+
};
|
|
52
|
+
|
|
82
53
|
/**
|
|
83
54
|
* takes an array and returns a random element of the array
|
|
84
55
|
*
|
|
@@ -86,10 +57,10 @@ function Random (faker, seed) {
|
|
|
86
57
|
* @param {array} array
|
|
87
58
|
*/
|
|
88
59
|
this.arrayElement = function (array) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
60
|
+
array = array || ["a", "b", "c"];
|
|
61
|
+
var r = faker.datatype.number({ max: array.length - 1 });
|
|
62
|
+
return array[r];
|
|
63
|
+
};
|
|
93
64
|
|
|
94
65
|
/**
|
|
95
66
|
* takes an array and returns a subset with random elements of the array
|
|
@@ -99,55 +70,57 @@ function Random (faker, seed) {
|
|
|
99
70
|
* @param {number} count number of elements to pick
|
|
100
71
|
*/
|
|
101
72
|
this.arrayElements = function (array, count) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
73
|
+
array = array || ["a", "b", "c"];
|
|
74
|
+
|
|
75
|
+
if (typeof count !== 'number') {
|
|
76
|
+
count = faker.datatype.number({ min: 1, max: array.length });
|
|
77
|
+
} else if (count > array.length) {
|
|
78
|
+
count = array.length;
|
|
79
|
+
} else if (count < 0) {
|
|
80
|
+
count = 0;
|
|
81
|
+
}
|
|
111
82
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
83
|
+
var arrayCopy = array.slice(0);
|
|
84
|
+
var i = array.length;
|
|
85
|
+
var min = i - count;
|
|
86
|
+
var temp;
|
|
87
|
+
var index;
|
|
88
|
+
|
|
89
|
+
while (i-- > min) {
|
|
90
|
+
index = Math.floor((i + 1) * faker.datatype.float({ min: 0, max: 0.99 }));
|
|
91
|
+
temp = arrayCopy[index];
|
|
92
|
+
arrayCopy[index] = arrayCopy[i];
|
|
93
|
+
arrayCopy[i] = temp;
|
|
94
|
+
}
|
|
118
95
|
|
|
119
|
-
|
|
120
|
-
}
|
|
96
|
+
return arrayCopy.slice(min);
|
|
97
|
+
};
|
|
121
98
|
|
|
122
99
|
/**
|
|
123
|
-
* takes an object and returns
|
|
100
|
+
* takes an object and returns a random key or value
|
|
124
101
|
*
|
|
125
102
|
* @method faker.random.objectElement
|
|
126
103
|
* @param {object} object
|
|
127
104
|
* @param {mixed} field
|
|
128
105
|
*/
|
|
129
106
|
this.objectElement = function (object, field) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
107
|
+
object = object || { "foo": "bar", "too": "car" };
|
|
108
|
+
var array = Object.keys(object);
|
|
109
|
+
var key = faker.random.arrayElement(array);
|
|
133
110
|
|
|
134
|
-
|
|
135
|
-
}
|
|
111
|
+
return field === "key" ? key : object[key];
|
|
112
|
+
};
|
|
136
113
|
|
|
137
114
|
/**
|
|
115
|
+
* @Deprecated
|
|
138
116
|
* uuid
|
|
139
117
|
*
|
|
140
118
|
* @method faker.random.uuid
|
|
141
119
|
*/
|
|
142
120
|
this.uuid = function () {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
var value = placeholder == 'x' ? random : (random &0x3 | 0x8);
|
|
147
|
-
return value.toString(16);
|
|
148
|
-
};
|
|
149
|
-
return RFC4122_TEMPLATE.replace(/[xy]/g, replacePlaceholders);
|
|
150
|
-
}
|
|
121
|
+
console.log("Deprecation Warning: faker.random.uuid is now located in faker.datatype.uuid");
|
|
122
|
+
return faker.datatype.uuid();
|
|
123
|
+
};
|
|
151
124
|
|
|
152
125
|
/**
|
|
153
126
|
* boolean
|
|
@@ -155,8 +128,9 @@ function Random (faker, seed) {
|
|
|
155
128
|
* @method faker.random.boolean
|
|
156
129
|
*/
|
|
157
130
|
this.boolean = function () {
|
|
158
|
-
|
|
159
|
-
|
|
131
|
+
console.log("Deprecation Warning: faker.random.boolean is now located in faker.datatype.boolean");
|
|
132
|
+
return faker.datatype.boolean();
|
|
133
|
+
};
|
|
160
134
|
|
|
161
135
|
// TODO: have ability to return specific type of word? As in: noun, adjective, verb, etc
|
|
162
136
|
/**
|
|
@@ -168,43 +142,43 @@ function Random (faker, seed) {
|
|
|
168
142
|
this.word = function randomWord (type) {
|
|
169
143
|
|
|
170
144
|
var wordMethods = [
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
145
|
+
'commerce.department',
|
|
146
|
+
'commerce.productName',
|
|
147
|
+
'commerce.productAdjective',
|
|
148
|
+
'commerce.productMaterial',
|
|
149
|
+
'commerce.product',
|
|
150
|
+
'commerce.color',
|
|
151
|
+
|
|
152
|
+
'company.catchPhraseAdjective',
|
|
153
|
+
'company.catchPhraseDescriptor',
|
|
154
|
+
'company.catchPhraseNoun',
|
|
155
|
+
'company.bsAdjective',
|
|
156
|
+
'company.bsBuzz',
|
|
157
|
+
'company.bsNoun',
|
|
158
|
+
'address.streetSuffix',
|
|
159
|
+
'address.county',
|
|
160
|
+
'address.country',
|
|
161
|
+
'address.state',
|
|
162
|
+
|
|
163
|
+
'finance.accountName',
|
|
164
|
+
'finance.transactionType',
|
|
165
|
+
'finance.currencyName',
|
|
166
|
+
|
|
167
|
+
'hacker.noun',
|
|
168
|
+
'hacker.verb',
|
|
169
|
+
'hacker.adjective',
|
|
170
|
+
'hacker.ingverb',
|
|
171
|
+
'hacker.abbreviation',
|
|
172
|
+
|
|
173
|
+
'name.jobDescriptor',
|
|
174
|
+
'name.jobArea',
|
|
175
|
+
'name.jobType'];
|
|
202
176
|
|
|
203
177
|
// randomly pick from the many faker methods that can generate words
|
|
204
178
|
var randomWordMethod = faker.random.arrayElement(wordMethods);
|
|
205
179
|
var result = faker.fake('{{' + randomWordMethod + '}}');
|
|
206
180
|
return faker.random.arrayElement(result.split(' '));
|
|
207
|
-
}
|
|
181
|
+
};
|
|
208
182
|
|
|
209
183
|
/**
|
|
210
184
|
* randomWords
|
|
@@ -215,13 +189,13 @@ function Random (faker, seed) {
|
|
|
215
189
|
this.words = function randomWords (count) {
|
|
216
190
|
var words = [];
|
|
217
191
|
if (typeof count === "undefined") {
|
|
218
|
-
count = faker.
|
|
192
|
+
count = faker.datatype.number({min:1, max: 3});
|
|
219
193
|
}
|
|
220
194
|
for (var i = 0; i<count; i++) {
|
|
221
195
|
words.push(faker.random.word());
|
|
222
196
|
}
|
|
223
197
|
return words.join(' ');
|
|
224
|
-
}
|
|
198
|
+
};
|
|
225
199
|
|
|
226
200
|
/**
|
|
227
201
|
* locale
|
|
@@ -230,7 +204,7 @@ function Random (faker, seed) {
|
|
|
230
204
|
*/
|
|
231
205
|
this.image = function randomImage () {
|
|
232
206
|
return faker.image.image();
|
|
233
|
-
}
|
|
207
|
+
};
|
|
234
208
|
|
|
235
209
|
/**
|
|
236
210
|
* locale
|
|
@@ -241,73 +215,87 @@ function Random (faker, seed) {
|
|
|
241
215
|
return faker.random.arrayElement(Object.keys(faker.locales));
|
|
242
216
|
};
|
|
243
217
|
|
|
244
|
-
|
|
218
|
+
/**
|
|
245
219
|
* alpha. returns lower/upper alpha characters based count and upcase options
|
|
246
220
|
*
|
|
247
221
|
* @method faker.random.alpha
|
|
248
|
-
* @param {mixed} options // defaults to { count: 1, upcase: false }
|
|
222
|
+
* @param {mixed} options // defaults to { count: 1, upcase: false, bannedChars: [] }
|
|
249
223
|
*/
|
|
250
224
|
this.alpha = function alpha(options) {
|
|
251
225
|
if (typeof options === "undefined") {
|
|
252
226
|
options = {
|
|
253
227
|
count: 1
|
|
254
|
-
}
|
|
228
|
+
};
|
|
255
229
|
} else if (typeof options === "number") {
|
|
256
230
|
options = {
|
|
257
231
|
count: options,
|
|
258
|
-
}
|
|
232
|
+
};
|
|
259
233
|
} else if (typeof options.count === "undefined") {
|
|
260
|
-
options.count = 1
|
|
234
|
+
options.count = 1;
|
|
261
235
|
}
|
|
262
236
|
|
|
263
237
|
if (typeof options.upcase === "undefined") {
|
|
264
238
|
options.upcase = false;
|
|
265
239
|
}
|
|
240
|
+
if (typeof options.bannedChars ==="undefined"){
|
|
241
|
+
options.bannedChars = [];
|
|
242
|
+
}
|
|
266
243
|
|
|
267
244
|
var wholeString = "";
|
|
245
|
+
var charsArray = ["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"];
|
|
246
|
+
if(options.bannedChars){
|
|
247
|
+
charsArray = arrayRemove(charsArray,options.bannedChars);
|
|
248
|
+
}
|
|
268
249
|
for(var i = 0; i < options.count; i++) {
|
|
269
|
-
wholeString += faker.random.arrayElement(
|
|
250
|
+
wholeString += faker.random.arrayElement(charsArray);
|
|
270
251
|
}
|
|
271
252
|
|
|
272
253
|
return options.upcase ? wholeString.toUpperCase() : wholeString;
|
|
273
|
-
}
|
|
254
|
+
}
|
|
274
255
|
|
|
275
256
|
/**
|
|
276
257
|
* alphaNumeric
|
|
277
258
|
*
|
|
278
259
|
* @method faker.random.alphaNumeric
|
|
279
260
|
* @param {number} count defaults to 1
|
|
261
|
+
* {mixed} options // defaults to { bannedChars: [] }
|
|
262
|
+
* options.bannedChars - array of characters which should be banned in new string
|
|
280
263
|
*/
|
|
281
|
-
this.alphaNumeric = function alphaNumeric(count) {
|
|
264
|
+
this.alphaNumeric = function alphaNumeric(count, options) {
|
|
282
265
|
if (typeof count === "undefined") {
|
|
283
266
|
count = 1;
|
|
284
267
|
}
|
|
268
|
+
if (typeof options ==="undefined"){
|
|
269
|
+
options = {};
|
|
270
|
+
}
|
|
271
|
+
if (typeof options.bannedChars ==="undefined"){
|
|
272
|
+
options.bannedChars = [];
|
|
273
|
+
}
|
|
285
274
|
|
|
286
275
|
var wholeString = "";
|
|
276
|
+
var charsArray = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "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"]
|
|
277
|
+
if(options) {
|
|
278
|
+
if (options.bannedChars) {
|
|
279
|
+
charsArray = arrayRemove(charsArray, options.bannedChars);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
287
282
|
for(var i = 0; i < count; i++) {
|
|
288
|
-
wholeString += faker.random.arrayElement(
|
|
283
|
+
wholeString += faker.random.arrayElement(charsArray);
|
|
289
284
|
}
|
|
290
285
|
|
|
291
286
|
return wholeString;
|
|
292
287
|
};
|
|
293
288
|
|
|
294
289
|
/**
|
|
290
|
+
* @Deprecated
|
|
295
291
|
* hexaDecimal
|
|
296
292
|
*
|
|
297
293
|
* @method faker.random.hexaDecimal
|
|
298
294
|
* @param {number} count defaults to 1
|
|
299
295
|
*/
|
|
300
296
|
this.hexaDecimal = function hexaDecimal(count) {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
var wholeString = "";
|
|
306
|
-
for(var i = 0; i < count; i++) {
|
|
307
|
-
wholeString += faker.random.arrayElement(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "A", "B", "C", "D", "E", "F"]);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
return "0x"+wholeString;
|
|
297
|
+
console.log("Deprecation Warning: faker.random.hexaDecimal is now located in faker.datatype.hexaDecimal");
|
|
298
|
+
return faker.datatype.hexaDecimal(count);
|
|
311
299
|
};
|
|
312
300
|
|
|
313
301
|
return this;
|