browser-headers
Advanced tools
Comparing version 0.1.7 to 0.2.0
@@ -11,11 +11,7 @@ import { WindowHeaders } from "./WindowHeaders"; | ||
} | ||
export declare type HeaderObject = { | ||
[key: string]: string | string[]; | ||
}; | ||
export declare type HeaderMap = Map<string, string | string[]>; | ||
export default class BrowserHeaders { | ||
export declare class BrowserHeaders { | ||
keyValueMap: { | ||
[key: string]: string[]; | ||
}; | ||
constructor(init?: HeaderObject | HeaderMap | BrowserHeaders | WindowHeaders | string, options?: { | ||
constructor(init?: BrowserHeaders.ConstructorArg, options?: { | ||
splitValues: boolean; | ||
@@ -30,2 +26,10 @@ }); | ||
forEach(callback: (key: string, values: string[]) => void): void; | ||
toHeaders(): WindowHeaders; | ||
} | ||
export declare namespace BrowserHeaders { | ||
type HeaderObject = { | ||
[key: string]: string | string[]; | ||
}; | ||
type HeaderMap = Map<string, string | string[]>; | ||
type ConstructorArg = HeaderObject | HeaderMap | BrowserHeaders | WindowHeaders | string; | ||
} |
@@ -6,3 +6,3 @@ "use strict"; | ||
function BrowserHeaders(init, options) { | ||
if (init === void 0) { init = ""; } | ||
if (init === void 0) { init = {}; } | ||
if (options === void 0) { options = { splitValues: false }; } | ||
@@ -142,5 +142,14 @@ var _this = this; | ||
}; | ||
BrowserHeaders.prototype.toHeaders = function () { | ||
var headers = new Headers(); | ||
this.forEach(function (key, values) { | ||
values.forEach(function (value) { | ||
headers.append(key, value); | ||
}); | ||
}); | ||
return headers; | ||
}; | ||
return BrowserHeaders; | ||
}()); | ||
exports.default = BrowserHeaders; | ||
exports.BrowserHeaders = BrowserHeaders; | ||
//# sourceMappingURL=BrowserHeaders.js.map |
@@ -1,2 +0,1 @@ | ||
import BrowserHeaders from "./BrowserHeaders"; | ||
export default BrowserHeaders; | ||
export { BrowserHeaders } from "./BrowserHeaders"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var BrowserHeaders_1 = require("./BrowserHeaders"); | ||
exports.default = BrowserHeaders_1.default; | ||
exports.BrowserHeaders = BrowserHeaders_1.BrowserHeaders; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "browser-headers", | ||
"version": "0.1.7", | ||
"version": "0.2.0", | ||
"main": "lib/index.js", | ||
@@ -5,0 +5,0 @@ "types": "lib/index.d.ts", |
@@ -22,5 +22,2 @@ import { normalizeName, normalizeValue, getHeaderValues, getHeaderKeys, splitHeaderValue } from "./util"; | ||
export type HeaderObject = {[key: string]: string|string[]}; | ||
export type HeaderMap = Map<string, string|string[]>; | ||
// Declare that there is a global property named "Headers" - this might not be present at runtime | ||
@@ -30,6 +27,6 @@ declare const Headers: any; | ||
// BrowserHeaders is a wrapper class for Headers | ||
export default class BrowserHeaders { | ||
export class BrowserHeaders { | ||
keyValueMap: {[key: string]: string[]}; | ||
constructor(init: HeaderObject | HeaderMap | BrowserHeaders | WindowHeaders | string = "", options: {splitValues: boolean} = { splitValues: false } ) { | ||
constructor(init: BrowserHeaders.ConstructorArg = {}, options: {splitValues: boolean} = { splitValues: false } ) { | ||
this.keyValueMap = {}; | ||
@@ -51,7 +48,7 @@ | ||
} else if (init instanceof BrowserHeaders) { | ||
init.forEach((key, values) => { | ||
(init as BrowserHeaders).forEach((key, values) => { | ||
this.append(key, values) | ||
}); | ||
} else if (typeof Map !== "undefined" && init instanceof Map) { | ||
const asMap = init as HeaderMap; | ||
const asMap = init as BrowserHeaders.HeaderMap; | ||
asMap.forEach((value: string|string[], key: string) => { | ||
@@ -64,3 +61,3 @@ this.append(key, value); | ||
Object.getOwnPropertyNames(init).forEach(key => { | ||
const asObject = init as HeaderObject; | ||
const asObject = init as BrowserHeaders.HeaderObject; | ||
const values = asObject[key]; | ||
@@ -169,2 +166,20 @@ if (Array.isArray(values)) { | ||
} | ||
toHeaders(): WindowHeaders { | ||
const headers: WindowHeaders = new Headers(); | ||
this.forEach((key, values) => { | ||
values.forEach(value => { | ||
headers.append(key, value); | ||
}); | ||
}); | ||
return headers; | ||
} | ||
} | ||
export namespace BrowserHeaders { | ||
export type HeaderObject = {[key: string]: string|string[]}; | ||
export type HeaderMap = Map<string, string|string[]>; | ||
export type ConstructorArg = HeaderObject | HeaderMap | BrowserHeaders | WindowHeaders | string; | ||
} |
@@ -1,3 +0,1 @@ | ||
import BrowserHeaders from "./BrowserHeaders"; | ||
export default BrowserHeaders; | ||
export { BrowserHeaders } from "./BrowserHeaders"; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41941
676