MCPcopy Create free account
hub / github.com/RandomAPI/Randomuser.me-Node / generate

Method generate

api/1.2/api.js:80–257  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

78
79 // Returns random user object
80 async generate(options) {
81 options = options || {};
82
83 return new Promise((resolve, reject) => {
84 // Check for multiple vals
85 this.checkOptions(options);
86
87 this.results = Number(options.results);
88 this.seed = options.seed || '';
89 this.lego = typeof options.lego !== 'undefined' && options.lego !== 'false' ? true : false;
90 this.gender = options.gender || null;
91 this.format = (options.format || options.fmt || 'json').toLowerCase();
92 this.nat = options.nat || options.nationality || null;
93 this.noInfo = typeof options.noinfo !== 'undefined' && options.lego !== 'false' ? true : false;
94 this.page = Number(options.page) || 1;
95 this.password = options.password;
96
97 // Include all fields by default
98 this.inc = options.inc || this.originalFields.join(', ');
99 this.exc = options.exc || '';
100
101 this.inc = this.inc.split(',').filter((i) => i !== '').map((w) => w.trim().toLowerCase());
102 this.exc = this.exc.split(',').filter((i) => i !== '').map((w) => w.trim().toLowerCase());
103
104 // Remove exclusions
105 this.inc = this.inc.filter((w) => this.exc.indexOf(w) === -1);
106
107 // Update exclusions list to inverse of inclusions
108 this.exc = this.originalFields.filter((w) => this.inc.indexOf(w) === -1);
109
110 if (this.nat !== null) {
111 this.nat = this.nat.split(',').filter((i) => i !== '');
112 }
113
114 if (this.nat !== null) this.nat = uppercaseify(this.nat);
115
116 // Sanitize values
117 if (isNaN(this.results) || this.results < 0 || this.results > settings.maxResults || this.results === '') this.results = 1;
118
119 if (this.gender !== 'male' && this.gender !== 'female' || this.seed !== '') {
120 this.gender = null;
121 }
122
123 if (this.lego) this.nat = 'LEGO';
124 else if (this.nat !== null && !(this.validNat(this.nat))) this.nat = null;
125
126 if (this.seed.length === 18) {
127 this.nat = this.nats[parseInt(this.seed.slice(-2), 16)];
128 } else if (this.seed === '') {
129 this.defaultSeed();
130 }
131
132 if (this.page < 0 || this.page > 10000) this.page = 1;
133 ///////////////////
134
135 this.seedRNG();
136
137 let output = [];

Callers

nothing calls this directly

Calls 12

checkOptionsMethod · 0.95
validNatMethod · 0.95
defaultSeedMethod · 0.95
seedRNGMethod · 0.95
randomNatMethod · 0.95
randomNameMethod · 0.95
includeMethod · 0.95
genPasswordMethod · 0.95
uppercaseifyFunction · 0.70
rangeFunction · 0.70
randomItemFunction · 0.70
randomFunction · 0.70

Tested by

no test coverage detected