browser-headers
Advanced tools
Comparing version 0.3.2 to 0.4.0
@@ -1,2 +0,1 @@ | ||
import { WindowHeaders } from "./WindowHeaders"; | ||
export interface Map<K, V> { | ||
@@ -25,3 +24,3 @@ clear(): void; | ||
forEach(callback: (key: string, values: string[]) => void): void; | ||
toHeaders(): WindowHeaders; | ||
toHeaders(): Headers; | ||
} | ||
@@ -33,3 +32,3 @@ export declare namespace BrowserHeaders { | ||
type HeaderMap = Map<string, string | string[]>; | ||
type ConstructorArg = HeaderObject | HeaderMap | BrowserHeaders | WindowHeaders | string; | ||
type ConstructorArg = HeaderObject | HeaderMap | BrowserHeaders | Headers | string; | ||
} |
@@ -62,6 +62,6 @@ "use strict"; | ||
var p = pairs[i]; | ||
var index = p.indexOf(": "); | ||
var index = p.indexOf(":"); | ||
if (index > 0) { | ||
var key = p.substring(0, index); | ||
var value = p.substring(index + 2); | ||
var key = p.substring(0, index).trim(); | ||
var value = p.substring(index + 1).trim(); | ||
this.append(key, value); | ||
@@ -68,0 +68,0 @@ } |
@@ -21,3 +21,4 @@ "use strict"; | ||
exports.normalizeValue = normalizeValue; | ||
function getHeaderValues(headers, key) { | ||
function getHeaderValues(headersAsNative, key) { | ||
var headers = toWindowHeaders(headersAsNative); | ||
if (headers instanceof Headers && headers.getAll) { | ||
@@ -33,3 +34,7 @@ return headers.getAll(key); | ||
exports.getHeaderValues = getHeaderValues; | ||
function getHeaderKeys(headers) { | ||
function toWindowHeaders(headersAsNative) { | ||
return headersAsNative; | ||
} | ||
function getHeaderKeys(headersAsNative) { | ||
var headers = toWindowHeaders(headersAsNative); | ||
var asMap = {}; | ||
@@ -36,0 +41,0 @@ var keys = []; |
{ | ||
"name": "browser-headers", | ||
"version": "0.3.2", | ||
"version": "0.4.0", | ||
"main": "lib/index.js", | ||
@@ -29,4 +29,4 @@ "types": "lib/index.d.ts", | ||
"karma": "^1.2.0", | ||
"karma-browserstack-launcher": "^1.3.0", | ||
"karma-jasmine": "^1.0.2", | ||
"karma-sauce-launcher": "^1.0.0", | ||
"karma-sourcemap-loader": "^0.3.7", | ||
@@ -40,4 +40,6 @@ "ts-loader": "^2.0.1", | ||
"browserify": { | ||
"transform": ["babelify"] | ||
"transform": [ | ||
"babelify" | ||
] | ||
} | ||
} |
import { normalizeName, normalizeValue, getHeaderValues, getHeaderKeys, splitHeaderValue } from "./util"; | ||
import { WindowHeaders } from "./WindowHeaders"; | ||
@@ -40,5 +39,5 @@ export interface Map<K, V> { | ||
if (typeof Headers !== "undefined" && init instanceof Headers) { | ||
const keys = getHeaderKeys(init as WindowHeaders); | ||
const keys = getHeaderKeys(init as Headers); | ||
keys.forEach(key => { | ||
const values = getHeaderValues(init as WindowHeaders, key); | ||
const values = getHeaderValues(init as Headers, key); | ||
values.forEach(value => { | ||
@@ -83,6 +82,6 @@ if (options.splitValues) { | ||
const p = pairs[i]; | ||
const index = p.indexOf(": "); | ||
const index = p.indexOf(":"); | ||
if (index > 0) { | ||
const key = p.substring(0, index); | ||
const value = p.substring(index + 2); | ||
const key = p.substring(0, index).trim(); | ||
const value = p.substring(index + 1).trim(); | ||
this.append(key, value); | ||
@@ -171,5 +170,5 @@ } | ||
toHeaders(): WindowHeaders { | ||
toHeaders(): Headers { | ||
if (typeof Headers !== "undefined") { | ||
const headers: WindowHeaders = new Headers(); | ||
const headers = new Headers(); | ||
this.forEach((key, values) => { | ||
@@ -190,3 +189,3 @@ values.forEach(value => { | ||
export type HeaderMap = Map<string, string|string[]>; | ||
export type ConstructorArg = HeaderObject | HeaderMap | BrowserHeaders | WindowHeaders | string; | ||
export type ConstructorArg = HeaderObject | HeaderMap | BrowserHeaders | Headers | string; | ||
} |
@@ -28,3 +28,4 @@ import { WindowHeaders } from "./WindowHeaders"; | ||
/** @internal */ | ||
export function getHeaderValues(headers: WindowHeaders, key: string): string[] { | ||
export function getHeaderValues(headersAsNative: Headers, key: string): string[] { | ||
const headers = toWindowHeaders(headersAsNative); | ||
if (headers instanceof Headers && headers.getAll) { | ||
@@ -44,5 +45,11 @@ // If the headers instance has a getAll function then it will return an array | ||
// toWindowHeaders casts the native browser class to an interface that includes functions of different browser implementations | ||
function toWindowHeaders(headersAsNative: Headers): WindowHeaders { | ||
return headersAsNative as any as WindowHeaders; | ||
} | ||
// getHeaderKeys returns an array of keys in a headers instance | ||
/** @internal */ | ||
export function getHeaderKeys(headers: WindowHeaders): string[] { | ||
export function getHeaderKeys(headersAsNative: Headers): string[] { | ||
const headers = toWindowHeaders(headersAsNative); | ||
const asMap: {[key: string]: boolean} = {}; | ||
@@ -49,0 +56,0 @@ const keys: string[] = []; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
48287
702
0