Skip to content

Commit a1b3b04

Browse files
committed
Refactor compileETag function for clarity
- Simplified logic by removing unnecessary variable assignments. - Streamlined the switch statement to directly return the appropriate ETag function. - Updated JSDoc comments for consistency and clarity. - Removed redundant handling of false, returning undefined directly.
1 parent b31910c commit a1b3b04

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

lib/utils.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,33 +102,29 @@ function acceptParams (str) {
102102
/**
103103
* Compile "etag" value to function.
104104
*
105-
* @param {Boolean|String|Function} val
106-
* @return {Function}
105+
* @param {boolean|function|string} val
106+
* @return {function|undefined}
107+
* @throws {TypeError}
107108
* @api private
108109
*/
109-
110110
exports.compileETag = function(val) {
111-
var fn;
112-
113111
if (typeof val === 'function') {
114112
return val;
115113
}
116114

115+
if (val === false) {
116+
return;
117+
}
118+
117119
switch (val) {
118120
case true:
119121
case 'weak':
120-
fn = exports.wetag;
121-
break;
122-
case false:
123-
break;
122+
return exports.wetag;
124123
case 'strong':
125-
fn = exports.etag;
126-
break;
124+
return exports.etag;
127125
default:
128-
throw new TypeError('unknown value for etag function: ' + val);
126+
throw new TypeError(`unknown value for etag function: ${val}`);
129127
}
130-
131-
return fn;
132128
}
133129

134130
/**

0 commit comments

Comments
 (0)