Skip to content
Myr

refactored utils.accepts()

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by TJ Holowaychuk · committed by TJ Holowaychuk · parent fdf9692 · Browse files · 2 files+26 added−51 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+26 added−51 removed

  • tests:+24 added−28 removed
  • other:+2 added−23 removed

2 files+26 added−51 removed

modified:lib/utils.js+2 added-23 removed
113 unmodified lines
114 * @api private115 */116117exports.accepts = function(type, str){118 if (Array.isArray(type)) return exports.acceptsArray(type, str);119120 // accept anything when Accept is not present121 if (!str) return true;122123 // resolve mime124 if (!~type.indexOf('/')) type = mime.lookup(type);125126 // split type/subtype127 type = type.split('/');128129 // parse130 var accepted = exports.parseAccept(str)131 , len = accepted.length132 , obj133 , ok;134135 for (var i = 0; i < len; ++i) {136 obj = accepted[i];137 if (exports.accept(type, obj)) return true;138 }139140 return false;118 if (!Array.isArray(type)) type = [type];119 return exports.acceptsArray(type, str);120};121122/**123 * Check if `type` array is acceptable for `other`.
92 unmodified lines
modified:test/utils.js+24 added-28 removed