( accept: string, provided?: string[], )
| 141 | * negotiated encoding based on the `provided` encodings otherwise just a |
| 142 | * prioritized array of encodings. */ |
| 143 | export function preferredEncodings( |
| 144 | accept: string, |
| 145 | provided?: string[], |
| 146 | ): string[] { |
| 147 | const accepts = parseAcceptEncoding(accept); |
| 148 | |
| 149 | if (!provided) { |
| 150 | return accepts |
| 151 | .filter(isQuality) |
| 152 | .sort(compareSpecs) |
| 153 | .map((spec) => spec.encoding!); |
| 154 | } |
| 155 | |
| 156 | const priorities = provided.map((type, index) => |
| 157 | getEncodingPriority(type, accepts, index) |
| 158 | ); |
| 159 | |
| 160 | return priorities |
| 161 | .filter(isQuality) |
| 162 | .sort(compareSpecs) |
| 163 | .map((priority) => provided[priorities.indexOf(priority)]!); |
| 164 | } |
no test coverage detected