This repository has been archived on 2023-10-27. You can view files and clone it, but cannot push or open issues or pull requests.
node-fetch-cache/classes/headers.js
2021-07-05 14:17:21 -04:00

32 lines
547 B
JavaScript

export class Headers {
constructor(rawHeaders) {
this.rawHeaders = rawHeaders;
}
entries() {
return Object.entries(this.rawHeaders)
.sort((e1, e2) => e1[0].localeCompare(e2[0]))
.map(([key, val]) => [key, val[0]]);
}
keys() {
return this.entries().map((e) => e[0]);
}
values() {
return this.entries().map((e) => e[1]);
}
get(name) {
return (this.rawHeaders[name.toLowerCase()] || [])[0] || null;
}
has(name) {
return !!this.get(name);
}
raw() {
return this.rawHeaders;
}
}