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