From 0d2919c29be68136b3a7918394d395dafa492121 Mon Sep 17 00:00:00 2001 From: Ayoub-Mabrouk Date: Sun, 3 Nov 2024 22:08:24 +0100 Subject: [PATCH] Refactor: update JSDoc for subdomains getter and simplify implementation - Changed JSDoc return type to specify an array of strings. - Removed the unnecessary function name from the subdomains getter for better readability. - Used destructuring to simplify property access and enhance clarity in the code. --- lib/request.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/request.js b/lib/request.js index 372a9915e9..f9740d9f3c 100644 --- a/lib/request.js +++ b/lib/request.js @@ -364,19 +364,18 @@ defineGetter(req, 'ips', function ips() { * If "subdomain offset" is not set, req.subdomains is `["ferrets", "tobi"]`. * If "subdomain offset" is 3, req.subdomains is `["tobi"]`. * - * @return {Array} + * @return {Array} * @public */ -defineGetter(req, 'subdomains', function subdomains() { - var hostname = this.hostname; - +defineGetter(req, 'subdomains', function() { + const { hostname, app } = this; if (!hostname) return []; - var offset = this.app.get('subdomain offset'); - var subdomains = !isIP(hostname) - ? hostname.split('.').reverse() - : [hostname]; + const offset = app.get('subdomain offset'); + const subdomains = isIP(hostname) + ? [hostname] + : hostname.split('.').reverse(); return subdomains.slice(offset); });