Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

es-vary

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

es-vary - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

9

dist/index.d.ts
/// <reference types="node" />
import { ServerResponse as Response } from 'http';
export declare function append(header: string, field: string): string;
import { ServerResponse } from 'http';
declare function append(header: string, field: string): string;
/**
* Mark that a request is varied on a header field.
*/
export declare function vary(res: Response, field: string): void;
declare function vary(res: ServerResponse, field: string): void;
export { append, vary };

@@ -1,84 +0,1 @@

/**
* RegExp to match field-name in RFC 7230 sec 3.2
*
* field-name = token
* token = 1*tchar
* tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*"
* / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
* / DIGIT / ALPHA
* ; any VCHAR, except delimiters
*/
const FIELD_NAME_REGEXP = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
function parse(header) {
let end = 0;
let list = [];
let start = 0;
// gather tokens
for (var i = 0, len = header.length; i < len; i++) {
switch (header.charCodeAt(i)) {
case 0x20 /* */:
if (start === end) {
start = end = i + 1;
}
break;
case 0x2c /* , */:
list.push(header.substring(start, end));
start = end = i + 1;
break;
default:
end = i + 1;
break;
}
}
// final token
list.push(header.substring(start, end));
return list;
}
function append(header, field) {
// get fields array
const fields = !Array.isArray(field) ? parse(String(field)) : field;
// assert on invalid field names
for (const field of fields) {
if (!FIELD_NAME_REGEXP.test(field)) {
throw new TypeError('field argument contains an invalid header name');
}
}
// existing, unspecified vary
if (header === '*') {
return header;
}
// enumerate current values
let val = header;
const vals = parse(header.toLowerCase());
// unspecified vary
if (fields.indexOf('*') !== -1 || vals.indexOf('*') !== -1) {
return '*';
}
for (const field of fields) {
const fld = field.toLowerCase();
// append value (case-preserving)
if (vals.indexOf(fld) === -1) {
vals.push(fld);
val = val ? val + ', ' + field : field;
}
}
return val;
}
/**
* Mark that a request is varied on a header field.
*/
function vary(res, field) {
if (!res || !res.getHeader || !res.setHeader) {
// quack quack
throw new TypeError('res argument is required');
}
// get existing header
var val = res.getHeader('Vary') || '';
var header = Array.isArray(val) ? val.join(', ') : String(val);
// set new header
if ((val = append(header, field))) {
res.setHeader('Vary', val);
}
}
export { append, vary };
const FIELD_NAME_REGEXP=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;function parse(header){let end=0;let list=[];let start=0;for(var i=0,len=header.length;i<len;i++){switch(header.charCodeAt(i)){case 32:if(start===end){start=end=i+1}break;case 44:list.push(header.substring(start,end));start=end=i+1;break;default:end=i+1;break}}list.push(header.substring(start,end));return list}function append(header,field){const fields=!Array.isArray(field)?parse(String(field)):field;for(const field2 of fields){if(!FIELD_NAME_REGEXP.test(field2)){throw new TypeError("field argument contains an invalid header name")}}if(header==="*"){return header}let val=header;const vals=parse(header.toLowerCase());if(fields.indexOf("*")!==-1||vals.indexOf("*")!==-1){return"*"}for(const field2 of fields){const fld=field2.toLowerCase();if(vals.indexOf(fld)===-1){vals.push(fld);val=val?val+", "+field2:field2}}return val}function vary(res,field){if(!res||!res.getHeader||!res.setHeader){throw new TypeError("res argument is required")}var val=res.getHeader("Vary")||"";var header=Array.isArray(val)?val.join(", "):String(val);if(val=append(header,field)){res.setHeader("Vary",val)}}export{append,vary};
{
"name": "es-vary",
"description": "vary rewrite in TypeScript with ESM and CommonJS targets",
"version": "0.0.3",
"type": "module",
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"engines": {
"node": ">=12.x"
},
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"./package.json": "./package.json",
"./": "./"
},
"scripts": {
"prepare": "pnpm build",
"build": "rollup -c"
},
"repository": {
"type": "git",
"url": "git+https://github.com/talentlessguy/es-vary.git"
},
"keywords": [
"http",
"esm",
"es",
"vary",
"nodejs",
"javascript"
],
"author": "",
"license": "MIT",
"bugs": {
"url": "https://github.com/talentlessguy/es-vary/issues"
},
"homepage": "https://github.com/talentlessguy/es-vary#readme",
"devDependencies": {
"@types/node": "^14.0.23",
"rollup": "^2.22.0",
"rollup-plugin-typescript2": "^0.27.1",
"typescript": "^3.9.7"
}
"name": "es-vary",
"description": "vary rewrite in TypeScript with ESM and CommonJS targets",
"version": "0.0.4",
"type": "module",
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"engines": {
"node": ">=12.x"
},
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"./package.json": "./package.json",
"./": "./"
},
"scripts": {
"prepare": "pnpm build",
"build": "tsup src/index.ts --minify-whitespace --format cjs,esm --dts"
},
"repository": {
"type": "git",
"url": "git+https://github.com/talentlessguy/es-vary.git"
},
"keywords": [
"http",
"esm",
"es",
"vary",
"nodejs",
"javascript"
],
"author": "",
"license": "MIT",
"bugs": {
"url": "https://github.com/talentlessguy/es-vary/issues"
},
"homepage": "https://github.com/talentlessguy/es-vary#readme",
"devDependencies": {
"@types/node": "^14.6.0",
"tsup": "^3.6.1",
"typescript": "^4.0.2"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc