You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

headers-polyfill

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

headers-polyfill - npm Package Compare versions

Comparing version

to
3.3.0

lib/index.d.mts

31

lib/index.d.ts

@@ -1,9 +0,9 @@

declare type HeadersList = Array<[string, string | string[]]>;
declare type FlatHeadersList = [string, string][];
declare type HeadersObject = Record<string, string | string[]>;
declare type FlatHeadersObject = Record<string, string>;
type HeadersList = Array<[string, string | string[]]>;
type FlatHeadersList = [string, string][];
type HeadersObject = Record<string, string | string[]>;
type FlatHeadersObject = Record<string, string>;
declare const NORMALIZED_HEADERS: unique symbol;
declare const RAW_HEADER_NAMES: unique symbol;
declare class HeadersPolyfill {
declare class Headers$1 {
private [NORMALIZED_HEADERS];

@@ -37,10 +37,2 @@ private [RAW_HEADER_NAMES];

/**
* Returns the object of all the normalized headers.
*/
all(): Record<string, string>;
/**
* Returns the object of all the raw headers.
*/
raw(): Record<string, string>;
/**
* Traverses the `Headers` object,

@@ -59,2 +51,7 @@ * calling the given callback for each header.

/**
* Returns the object of all raw headers.
*/
declare function getRawHeaders(headers: Headers): Record<string, string>;
/**
* Converts a given `Headers` instance to its string representation.

@@ -76,5 +73,5 @@ */

*/
declare function stringToHeaders(str: string): HeadersPolyfill;
declare function stringToHeaders(str: string): Headers$1;
declare function listToHeaders(list: HeadersList): HeadersPolyfill;
declare function listToHeaders(list: HeadersList): Headers$1;

@@ -84,3 +81,3 @@ /**

*/
declare function objectToHeaders(headersObject: Record<string, string | string[] | undefined>): HeadersPolyfill;
declare function objectToHeaders(headersObject: Record<string, string | string[] | undefined>): Headers$1;

@@ -96,2 +93,2 @@ /**

export { FlatHeadersList, FlatHeadersObject, HeadersPolyfill as Headers, HeadersList, HeadersObject, flattenHeadersList, flattenHeadersObject, headersToList, headersToObject, headersToString, listToHeaders, objectToHeaders, reduceHeadersObject, stringToHeaders };
export { FlatHeadersList, FlatHeadersObject, Headers$1 as Headers, HeadersList, HeadersObject, flattenHeadersList, flattenHeadersObject, getRawHeaders, headersToList, headersToObject, headersToString, listToHeaders, objectToHeaders, reduceHeadersObject, stringToHeaders };

@@ -219,3 +219,7 @@ function _array_like_to_array(arr, len) {

var __toESM = function(mod, isNodeMode, target) {
return target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
return target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
value: mod,

@@ -401,3 +405,3 @@ enumerable: true

Headers: function() {
return HeadersPolyfill;
return Headers;
},

@@ -410,2 +414,5 @@ flattenHeadersList: function() {

},
getRawHeaders: function() {
return getRawHeaders;
},
headersToList: function() {

@@ -505,3 +512,5 @@ return headersToList;

var character = value.charCodeAt(i);
if (character === 0 || character === 10 || character === 13) {
if (// NUL.
character === 0 || // HTTP newline bytes.
character === 10 || character === 13) {
return false;

@@ -517,9 +526,12 @@ }

var _a, _b;
var HeadersPolyfill = /*#__PURE__*/ function() {
var Headers = /*#__PURE__*/ function() {
"use strict";
function HeadersPolyfill1(init) {
function _Headers(init) {
var _this = this;
_class_call_check(this, HeadersPolyfill1);
_class_call_check(this, _Headers);
var _init;
// Normalized header {"name":"a, b"} storage.
this[_a] = {};
// Keeps the mapping between the raw header name
// and the normalized header name to ease the lookup.
this[_b] = /* @__PURE__ */ new Map();

@@ -529,3 +541,3 @@ if ([

"HeadersPolyfill"
].includes((_init = init) === null || _init === void 0 ? void 0 : _init.constructor.name) || _instanceof(init, HeadersPolyfill)) {
].includes((_init = init) === null || _init === void 0 ? void 0 : _init.constructor.name) || _instanceof(init, _Headers)) {
var initialHeaders = init;

@@ -547,3 +559,3 @@ initialHeaders.forEach(function(value, name) {

}
_create_class(HeadersPolyfill1, [
_create_class(_Headers, [
{

@@ -844,3 +856,5 @@ key: (_a = NORMALIZED_HEADERS, _b = RAW_HEADER_NAMES, Symbol.iterator),

{
key: "has",
/**
* Returns a boolean stating whether a `Headers` object contains a certain header.
*/ key: "has",
value: function has(name) {

@@ -854,3 +868,5 @@ if (!isValidHeaderName(name)) {

{
key: "get",
/**
* Returns a `ByteString` sequence of all the values of a header with a given name.
*/ key: "get",
value: function get(name) {

@@ -865,3 +881,5 @@ if (!isValidHeaderName(name)) {

{
key: "set",
/**
* Sets a new value for an existing header inside a `Headers` object, or adds the header if it does not already exist.
*/ key: "set",
value: function set(name, value) {

@@ -878,3 +896,5 @@ if (!isValidHeaderName(name) || !isValidHeaderValue(value)) {

{
key: "append",
/**
* Appends a new value onto an existing header inside a `Headers` object, or adds the header if it does not already exist.
*/ key: "append",
value: function append(name, value) {

@@ -891,3 +911,5 @@ if (!isValidHeaderName(name) || !isValidHeaderValue(value)) {

{
key: "delete",
/**
* Deletes a header from the `Headers` object.
*/ key: "delete",
value: function _delete(name) {

@@ -906,36 +928,6 @@ if (!isValidHeaderName(name)) {

{
key: "all",
value: function all() {
return this[NORMALIZED_HEADERS];
}
},
{
key: "raw",
value: function raw() {
var rawHeaders = {};
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
try {
for(var _iterator = this.entries()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
var _step_value = _sliced_to_array(_step.value, 2), name = _step_value[0], value = _step_value[1];
rawHeaders[this[RAW_HEADER_NAMES].get(name)] = value;
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally{
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally{
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return rawHeaders;
}
},
{
key: "forEach",
/**
* Traverses the `Headers` object,
* calling the given callback for each header.
*/ key: "forEach",
value: function forEach(callback, thisArg) {

@@ -965,3 +957,7 @@ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;

{
key: "getSetCookie",
/**
* Returns an array containing the values
* of all Set-Cookie headers associated
* with a response
*/ key: "getSetCookie",
value: function getSetCookie() {

@@ -981,4 +977,29 @@ var setCookieHeader = this.get("set-cookie");

]);
return HeadersPolyfill1;
return _Headers;
}();
// src/getRawHeaders.ts
function getRawHeaders(headers) {
var rawHeaders = {};
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
try {
for(var _iterator = headers.entries()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
var _step_value = _sliced_to_array(_step.value, 2), name = _step_value[0], value = _step_value[1];
rawHeaders[headers[RAW_HEADER_NAMES].get(name)] = value;
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally{
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally{
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return rawHeaders;
}
// src/transformers/headersToList.ts

@@ -1034,7 +1055,7 @@ function headersToList(headers) {

return headers;
}, new HeadersPolyfill());
}, new Headers());
}
// src/transformers/listToHeaders.ts
function listToHeaders(list) {
var headers = new HeadersPolyfill();
var headers = new Headers();
list.forEach(function(param) {

@@ -1063,3 +1084,3 @@ var _param = _sliced_to_array(param, 2), name = _param[0], value = _param[1];

return headers;
}, new HeadersPolyfill());
}, new Headers());
}

@@ -1088,2 +1109,3 @@ // src/transformers/flattenHeadersList.ts

flattenHeadersObject: flattenHeadersObject,
getRawHeaders: getRawHeaders,
headersToList: headersToList,

@@ -1090,0 +1112,0 @@ headersToObject: headersToObject,

{
"name": "headers-polyfill",
"version": "3.2.5",
"version": "3.3.0",
"description": "A native \"Headers\" class polyfill.",

@@ -31,4 +31,5 @@ "main": "./lib/index.js",

"devDependencies": {
"@ossjs/release": "^0.7.2",
"@swc/core": "^1.3.82",
"@ossjs/release": "^0.7.3",
"@swc/core": "^1.3.84",
"@swc/jest": "^0.2.29",
"@types/jest": "^28.1.4",

@@ -40,6 +41,5 @@ "@types/set-cookie-parser": "^2.4.3",

"set-cookie-parser": "^2.6.0",
"ts-jest": "^28.0.5",
"tsup": "^6.2.3",
"typescript": "4.3.2"
"tsup": "^7.2.0",
"typescript": "^5.2.2"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet