browser-headers
Advanced tools
Comparing version 0.1.1 to 0.1.2
{ | ||
"name": "browser-headers", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"main": "lib/index.js", | ||
@@ -14,7 +14,6 @@ "repository": "https://github.com/improbable-eng/js-browser-headers", | ||
"clean": "rm -rf build/*", | ||
"build:test": "mkdir -p build && cd test && tsc && browserify ./build/test/*.spec.js -o ./build/integration-tests.js --debug -t [ babelify ]", | ||
"build:test": "webpack", | ||
"build:lib": "mkdir -p lib && tsc && cp -R build/* lib", | ||
"lint": "tslint -c ./tslint.json ./src/**/*.ts ./test/**/*.ts", | ||
"test": "npm run build:test && karma start --single-run", | ||
"test:dev": "karma start", | ||
"release": "./release.sh ${npm_package_version}" | ||
@@ -25,7 +24,5 @@ }, | ||
"assert": "^1.4.1", | ||
"babel-cli": "^6.11.4", | ||
"babel-core": "^6.23.1", | ||
"babel-loader": "^6.3.2", | ||
"babel-preset-es2015": "^6.13.2", | ||
"babelify": "^7.3.0", | ||
"browserify": "^14.1.0", | ||
"jasmine": "^2.4.1", | ||
"jasmine-core": "^2.4.1", | ||
@@ -35,6 +32,9 @@ "karma": "^1.2.0", | ||
"karma-sauce-launcher": "^1.0.0", | ||
"karma-sourcemap-loader": "^0.3.7", | ||
"ts-loader": "^2.0.1", | ||
"tslint": "^4.4.2", | ||
"typescript": "^2.2.1" | ||
"typescript": "^2.2.1", | ||
"webpack": "^2.2.1" | ||
}, | ||
"dependencies": {} | ||
} |
@@ -1,16 +0,6 @@ | ||
import { normalizeName, normalizeValue } from "./util"; | ||
import {normalizeName, normalizeValue, getHeaderValues, getHeaderKeys, splitHeaderValue } from "./util"; | ||
import { WindowHeaders } from "./WindowHeaders"; | ||
// Declare the class that *might* be present in the browser | ||
export declare interface WindowHeaders { | ||
get(key: string): string[]; // in some browsers .get returns a single string | ||
getAll(key: string): string[]; // some browsers don't have a .getAll | ||
has(key: string): boolean; | ||
delete(key: string): void; | ||
keys(): any; | ||
entries(): any; | ||
forEach(callback: (value: string, key: string) => void): any; | ||
append(key: string, value: string): void; | ||
set(key: string, value: string): void; | ||
[Symbol.iterator]: () => Iterator<string>, | ||
} | ||
export type HeaderObject = {[key: string]: string|string[]}; | ||
export type HeaderMap = Map<string, string|string[]>; | ||
@@ -20,67 +10,2 @@ // Declare that there is a global property named "Headers" - this might not be present at runtime | ||
// getHeadersValues abstracts the difference between get() and getAll() between browsers and always returns an array | ||
function getHeaderValues(headers: WindowHeaders, key: string): string[] { | ||
if (headers instanceof Headers && headers.getAll) { | ||
// If the headers instance has a getAll function then it will return an array | ||
return headers.getAll(key); | ||
} | ||
// There is no getAll() function so get *should* return an array | ||
const getValue = headers.get(key); | ||
if (getValue && typeof getValue === "string") { | ||
// some .get() implementations return a string even though they don't have a .getAll() - notably Microsoft Edge | ||
return [getValue]; | ||
} | ||
return getValue; | ||
} | ||
// getHeaderKeys returns an array of keys in a headers instance | ||
function getHeaderKeys(headers: WindowHeaders): string[] { | ||
const asMap: {[key: string]: boolean} = {}; | ||
const keys: string[] = []; | ||
if (headers.keys) { | ||
for (let key of headers.keys()) { | ||
if (!asMap[key]) { | ||
// Only add the key if it hasn't been added already | ||
asMap[key] = true; | ||
keys.push(key); | ||
} | ||
} | ||
} else if (headers.forEach) { | ||
headers.forEach((_, key) => { | ||
if (!asMap[key]) { | ||
// Only add the key if it hasn't been added already | ||
asMap[key] = true; | ||
keys.push(key); | ||
} | ||
}); | ||
} else { | ||
// If keys() and forEach() aren't available then fallback to iterating through headers | ||
for (let entry of headers) { | ||
const key = entry[0]; | ||
if (!asMap[key]) { | ||
// Only add the key if it hasn't been added already | ||
asMap[key] = true; | ||
keys.push(key); | ||
} | ||
} | ||
} | ||
return keys; | ||
} | ||
function splitHeaderValue(str: string) { | ||
const values: string[] = []; | ||
const commaSpaceValues = str.split(", "); | ||
commaSpaceValues.forEach(commaSpaceValue => { | ||
commaSpaceValue.split(",").forEach(commaValue => { | ||
values.push(commaValue); | ||
}); | ||
}); | ||
return values; | ||
} | ||
export type HeaderObject = {[key: string]: string|string[]}; | ||
export type HeaderMap = Map<string, string|string[]>; | ||
// BrowserHeaders is a wrapper class for Headers | ||
@@ -87,0 +12,0 @@ export default class BrowserHeaders { |
@@ -0,1 +1,7 @@ | ||
import { WindowHeaders } from "./WindowHeaders"; | ||
// Declare that there is a global property named "Headers" - this might not be present at runtime | ||
declare const Headers: any; | ||
/** @internal */ | ||
export function normalizeName(name: any): string { | ||
@@ -11,2 +17,3 @@ if (typeof name !== "string") { | ||
/** @internal */ | ||
export function normalizeValue(value: any): string { | ||
@@ -18,1 +25,66 @@ if (typeof value !== "string") { | ||
} | ||
// getHeadersValues abstracts the difference between get() and getAll() between browsers and always returns an array | ||
/** @internal */ | ||
export function getHeaderValues(headers: WindowHeaders, key: string): string[] { | ||
if (headers instanceof Headers && headers.getAll) { | ||
// If the headers instance has a getAll function then it will return an array | ||
return headers.getAll(key); | ||
} | ||
// There is no getAll() function so get *should* return an array | ||
const getValue = headers.get(key); | ||
if (getValue && typeof getValue === "string") { | ||
// some .get() implementations return a string even though they don't have a .getAll() - notably Microsoft Edge | ||
return [getValue]; | ||
} | ||
return getValue; | ||
} | ||
// getHeaderKeys returns an array of keys in a headers instance | ||
/** @internal */ | ||
export function getHeaderKeys(headers: WindowHeaders): string[] { | ||
const asMap: {[key: string]: boolean} = {}; | ||
const keys: string[] = []; | ||
if (headers.keys) { | ||
for (let key of headers.keys()) { | ||
if (!asMap[key]) { | ||
// Only add the key if it hasn't been added already | ||
asMap[key] = true; | ||
keys.push(key); | ||
} | ||
} | ||
} else if (headers.forEach) { | ||
headers.forEach((_, key) => { | ||
if (!asMap[key]) { | ||
// Only add the key if it hasn't been added already | ||
asMap[key] = true; | ||
keys.push(key); | ||
} | ||
}); | ||
} else { | ||
// If keys() and forEach() aren't available then fallback to iterating through headers | ||
for (let entry of headers) { | ||
const key = entry[0]; | ||
if (!asMap[key]) { | ||
// Only add the key if it hasn't been added already | ||
asMap[key] = true; | ||
keys.push(key); | ||
} | ||
} | ||
} | ||
return keys; | ||
} | ||
/** @internal */ | ||
export function splitHeaderValue(str: string) { | ||
const values: string[] = []; | ||
const commaSpaceValues = str.split(", "); | ||
commaSpaceValues.forEach(commaSpaceValue => { | ||
commaSpaceValue.split(",").forEach(commaValue => { | ||
values.push(commaValue); | ||
}); | ||
}); | ||
return values; | ||
} |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
1
41098
14
564
1