Conditions | 6 |
Total Lines | 139 |
Code Lines | 86 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | // jshint esversion: 8, -W069 |
||
83 | function isDomainAvailable(resultsText, resultsJSON) { |
||
84 | const { |
||
85 | 'lookup.assumptions': assumptions |
||
86 | } = settings; |
||
87 | |||
88 | resultsJSON = resultsJSON || 0; |
||
89 | |||
90 | if (resultsJSON === 0) resultsJSON = toJSON(resultsText); |
||
91 | |||
92 | var domainParams = getDomainParameters(null, null, null, resultsJSON, true); |
||
93 | var controlDate = getDate(Date.now()); |
||
94 | |||
95 | switch (true) { |
||
96 | /* |
||
97 | Special cases |
||
98 | */ |
||
99 | case (resultsText.includes('Uniregistry') && resultsText.includes('Query limit exceeded')): |
||
100 | return (assumptions.uniregistry ? 'unavailable' : 'error:ratelimiting'); |
||
101 | |||
102 | /* |
||
103 | Available checks |
||
104 | */ |
||
105 | |||
106 | // Not found cases & variants |
||
107 | //case (resultsText.includes('ERROR:101: no entries found')): |
||
108 | |||
109 | |||
110 | // No match cases & variants |
||
111 | case (resultsText.includes('No match for domain')): |
||
112 | case (resultsText.includes('- No Match')): |
||
113 | case (resultsText.includes('NO MATCH:')): |
||
114 | case (resultsText.includes('No match for')): |
||
115 | case (resultsText.includes('No match')): |
||
116 | case (resultsText.includes('No matching record.')): |
||
117 | case (resultsText.includes('Nincs talalat')): |
||
118 | |||
119 | // Status cases & variants |
||
120 | case (resultsText.includes('Status: AVAILABLE')): |
||
121 | case (resultsText.includes('Status: AVAILABLE')): |
||
122 | case (resultsText.includes('Status: available')): |
||
123 | case (resultsText.includes('Status: free')): |
||
124 | case (resultsText.includes('Status: Not Registered')): |
||
125 | case (resultsText.includes('query_status: 220 Available')): |
||
126 | |||
127 | // Unique cases |
||
128 | case (domainParams.expiryDate - controlDate < 0): |
||
129 | case (resultsText.includes('This domain name has not been registered')): |
||
130 | case (resultsText.includes('The domain has not been registered')): |
||
131 | case (resultsText.includes('This query returned 0 objects')): |
||
132 | case (resultsText.includes(' is free') && domainParams.whoisreply.length < 50): |
||
133 | case (resultsText.includes('domain name not known in')): |
||
134 | case (resultsText.includes('registration status: available')): |
||
135 | case (resultsText.includes('whois.nic.bo') && domainParams.whoisreply.length < 55): |
||
136 | case (resultsText.includes('Object does not exist')): |
||
137 | case (resultsText.includes('The queried object does not exist')): |
||
138 | case (resultsText.includes('Not Registered -')): |
||
139 | case (resultsText.includes('is available for registration')): |
||
140 | case (resultsText.includes('is available for purchase')): |
||
141 | case (resultsText.includes('DOMAIN IS NOT A REGISTERD')): |
||
142 | case (resultsText.includes('No such domain')): |
||
143 | case (resultsText.includes('No_Se_Encontro_El_Objeto')): |
||
144 | case (resultsText.includes('Domain unknown')): |
||
145 | case (resultsText.includes('No information available about domain name')): |
||
146 | case (resultsText.includes('Error.') && resultsText.includes('SaudiNIC')): |
||
147 | case (resultsText.includes('is not valid!')): // ??? |
||
148 | return 'available'; |
||
149 | |||
150 | /* |
||
151 | Unavailable checks |
||
152 | */ |
||
153 | case (resultsJSON.hasOwnProperty('domainName')): // Has domain name |
||
154 | case (resultsText.includes('Domain Status:ok')): // Domain name is ok |
||
155 | case (resultsText.includes('Expiration Date:')): // Has expiration date (1) |
||
156 | case (resultsText.includes('Expiry Date:')): // Has Expiration date (2) |
||
157 | case (resultsText.includes('Status: connect')): // Has connect status |
||
158 | case (resultsText.includes('Changed:')): // Has a changed date |
||
159 | case (Object.keys(resultsJSON).length > 5): // JSON has more than 5 keys (probably taken?) |
||
160 | case (resultsText.includes('organisation: Internet Assigned Numbers Authority')): // Is controlled by IANA |
||
161 | return 'unavailable'; |
||
162 | |||
163 | /* |
||
164 | Error checks |
||
165 | */ |
||
166 | |||
167 | // Error, null or no contents |
||
168 | case (resultsText == null): |
||
169 | case (resultsText == ''): |
||
170 | return 'error:nocontent'; |
||
171 | |||
172 | // Error, unauthorized |
||
173 | case (resultsText.includes('You are not authorized to access or query our Whois')): |
||
174 | return 'error:unauthorized'; |
||
175 | |||
176 | // Error, rate limiting |
||
177 | case (resultsText.includes('IP Address Has Reached Rate Limit')): |
||
178 | case (resultsText.includes('Too many connection attempts')): |
||
179 | case (resultsText.includes('Your request is being rate limited')): |
||
180 | case (resultsText.includes('Your query is too often.')): |
||
181 | case (resultsText.includes('Your connection limit exceeded.')): |
||
182 | return (assumptions.ratelimit ? 'unavailable' : 'error:ratelimiting'); |
||
183 | |||
184 | // Error, unretrivable |
||
185 | case (resultsText.includes('Could not retrieve Whois data')): |
||
186 | return 'error:unretrivable'; |
||
187 | |||
188 | // Error, forbidden |
||
189 | case (resultsText.includes('si is forbidden')): // .si is forbidden |
||
190 | case (resultsText.includes('Requests of this client are not permitted')): // .ch forbidden |
||
191 | return 'error:forbidden'; |
||
192 | |||
193 | // Error, reserved by regulator |
||
194 | case (resultsText.includes('reserved by aeDA Regulator')): // Reserved for aeDA regulator |
||
195 | return 'error:reservedbyregulator'; |
||
196 | |||
197 | // Error, unregistrable. |
||
198 | case (resultsText.includes('third-level domains may not start with')): |
||
199 | return 'error:unregistrable'; |
||
200 | |||
201 | // Error, reply error |
||
202 | case (resultsJSON.hasOwnProperty('error')): |
||
203 | case (resultsJSON.hasOwnProperty('errno')): |
||
204 | case (resultsText.includes('error ')): |
||
205 | case (resultsText.includes('error')): // includes plain error, may cause false negatives? i.e. error.com lookup |
||
206 | case (resultsText.includes('Error')): // includes plain error, may cause false negatives? i.e. error.com lookup |
||
207 | case (resultsText.includes('ERROR:101:')): |
||
208 | case (resultsText.includes('Whois lookup error')): |
||
209 | case (resultsText.includes('can temporarily not be answered')): |
||
210 | case (resultsText.includes('Invalid input')): |
||
211 | return 'error:replyerror'; |
||
212 | |||
213 | /* |
||
214 | Error throw |
||
215 | If every check fails throw Error, unparsable |
||
216 | */ |
||
217 | |||
218 | default: |
||
219 | return (assumptions.unparsable ? 'available' : 'error:unparsable'); |
||
220 | } |
||
221 | } |
||
222 | |||
402 |