MCPcopy Index your code
hub / github.com/RandomAPI/Randomuser.me-Node / generate

Method generate

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

Callers

nothing calls this directly

Calls 13

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

Tested by

no test coverage detected