UNPKG

@knowmax/http-utils

Version:

HTTP utilities for headers, content types, and common HTTP operations

36 lines (35 loc) 929 B
import { CONTENTTYPE_JSON } from "./contenttypes"; export const headers = (initial) => { return new Headers(initial); }; class Headers { constructor(initial) { this.headers = Object.assign({}, (initial !== null && initial !== void 0 ? initial : {})); } withBearer(token) { this.headers["Authorization"] = "Bearer " + token; return this; } withLanguage(language) { if (language) { this.headers["Accept-Language"] = language; } return this; } withContentTypeJson() { return this.withContentType(CONTENTTYPE_JSON); } withContentType(contentType) { this.headers["Content-Type"] = contentType; return this; } withHeader(key, value) { if (value) { this.headers[key] = value; } return this; } export() { return Object.assign({}, this.headers); } }