Socket
Socket
Sign inDemoInstall

structured-headers

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.4.1 to 0.5.0

LICENSE

2

browser/structured-header.min.js

@@ -1,2 +0,2 @@

var structuredHeader;!function(){"use strict";var e={590:function(e,t,r){var i=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r),Object.defineProperty(e,i,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),s=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||i(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),t.Token=void 0,s(r(223),t),s(r(759),t),s(r(985),t);var n=r(0);Object.defineProperty(t,"Token",{enumerable:!0,get:function(){return n.Token}})},759:function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.ParseError=t.parseItem=t.parseList=t.parseDictionary=void 0;const i=r(985),s=r(0),n=r(128);t.parseDictionary=function(e){return new a(e).parseDictionary()},t.parseList=function(e){return new a(e).parseList()},t.parseItem=function(e){return new a(e).parseItem()};class o extends Error{constructor(e,t){super(`Parse error: ${t} at offset ${e}`)}}t.ParseError=o;class a{constructor(e){this.input=e,this.pos=0}parseDictionary(){this.skipWS();const e=new Map;for(;!this.eof();){const t=this.parseKey();let r;if("="===this.lookChar()?(this.pos++,r=this.parseItemOrInnerList()):r=[!0,this.parseParameters()],e.set(t,r),this.skipOWS(),this.eof())return e;if(this.expectChar(","),this.pos++,this.skipOWS(),this.eof())throw new o(this.pos,"Dictionary contained a trailing comma")}return e}parseList(){this.skipWS();const e=[];for(;!this.eof();){if(e.push(this.parseItemOrInnerList()),this.skipOWS(),this.eof())return e;if(this.expectChar(","),this.pos++,this.skipOWS(),this.eof())throw new o(this.pos,"A list may not end with a trailing comma")}return e}parseItem(e=!0){e&&this.skipWS();const t=[this.parseBareItem(),this.parseParameters()];return e&&this.checkTrail(),t}parseItemOrInnerList(){return"("===this.lookChar()?this.parseInnerList():this.parseItem(!1)}parseInnerList(){this.expectChar("("),this.pos++;const e=[];for(;!this.eof();){if(this.skipWS(),")"===this.lookChar())return this.pos++,[e,this.parseParameters()];e.push(this.parseItem(!1));const t=this.lookChar();if(" "!==t&&")"!==t)throw new o(this.pos,"Expected a whitespace or ) after every item in an inner list")}throw new o(this.pos,"Could not find end of inner list")}parseBareItem(){const e=this.lookChar();if(e.match(/^[-0-9]/))return this.parseIntegerOrDecimal();if('"'===e)return this.parseString();if(e.match(/^[A-Za-z*]/))return this.parseToken();if(":"===e)return this.parseByteSequence();if("?"===e)return this.parseBoolean();throw new o(this.pos,"Unexpected input")}parseParameters(){const e=new Map;for(;!this.eof()&&";"===this.lookChar();){this.pos++,this.skipWS();const t=this.parseKey();let r=!0;"="===this.lookChar()&&(this.pos++,r=this.parseBareItem()),e.set(t,r)}return e}parseIntegerOrDecimal(){let e="integer",t=1,r="";if("-"===this.lookChar()&&(t=-1,this.pos++),!c(this.lookChar()))throw new o(this.pos,"Expected a digit (0-9)");for(;!this.eof();){const t=this.getChar();if(c(t))r+=t;else{if("integer"!==e||"."!==t){this.pos--;break}if(r.length>12)throw new o(this.pos,"Exceeded maximum decimal length");r+=".",e="decimal"}if("integer"===e&&r.length>15)throw new o(this.pos,"Exceeded maximum integer length");if("decimal"===e&&r.length>16)throw new o(this.pos,"Exceeded maximum decimal length")}if("integer"===e)return parseInt(r,10)*t;if(r.endsWith("."))throw new o(this.pos,"Decimal cannot end on a period");if(r.split(".")[1].length>3)throw new o(this.pos,"Number of digits after the decimal point cannot exceed 3");return parseFloat(r)*t}parseString(){let e="";for(this.expectChar('"'),this.pos++;!this.eof();){const t=this.getChar();if("\\"===t){if(this.eof())throw new o(this.pos,"Unexpected end of input");const t=this.getChar();if("\\"!==t&&'"'!==t)throw new o(this.pos,"A backslash must be followed by another backslash or double quote");e+=t}else{if('"'===t)return e;if(!n.isAscii(t))throw new Error("Strings must be in the ASCII range");e+=t}}throw new o(this.pos,"Unexpected end of input")}parseToken(){let e="";for(;!this.eof();){const t=this.lookChar();if(!/^[:/!#$%&'*+\-.^_`|~A-Za-z0-9]$/.test(t))return new s.Token(e);e+=this.getChar()}return new s.Token(e)}parseByteSequence(){this.expectChar(":"),this.pos++;const e=this.input.indexOf(":",this.pos);if(-1===e)throw new o(this.pos,'Could not find a closing ":" character to mark end of Byte Sequence');const t=this.input.substring(this.pos,e);if(this.pos+=t.length+1,!/^[A-Za-z0-9+/=]*$/.test(t))throw new o(this.pos,"ByteSequence does not contain a valid base64 string");return new i.ByteSequence(t)}parseBoolean(){this.expectChar("?"),this.pos++;const e=this.getChar();if("1"===e)return!0;if("0"===e)return!1;throw new o(this.pos,'Unexpected character. Expected a "1" or a "0"')}parseKey(){if(!this.lookChar().match(/^[a-z*]/))throw new o(this.pos,"A key must begin with an asterisk or letter (a-z)");let e="";for(;!this.eof();){const t=this.lookChar();if(!/^[a-z0-9_\-.*]$/.test(t))return e;e+=this.getChar()}return e}lookChar(){return this.input[this.pos]}expectChar(e){if(this.lookChar()!==e)throw new o(this.pos,`Expected ${e}`)}getChar(){return this.input[this.pos++]}eof(){return this.pos>=this.input.length}skipOWS(){for(;;){const e=this.input.substr(this.pos,1);if(" "!==e&&"\t"!==e)break;this.pos++}}skipWS(){for(;" "===this.lookChar();)this.pos++}checkTrail(){if(this.skipWS(),!this.eof())throw new o(this.pos,"Unexpected characters at end of input")}}t.default=a;const h=/^[0-9]$/;function c(e){return h.test(e)}},223:function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.serializeItem=t.serializeDictionary=t.serializeList=t.SerializeError=void 0;const i=r(985),s=r(0),n=r(128);class o extends Error{}function a(e){return c(e[0])+u(e[1])}function h(e){return`(${e[0].map((e=>a(e))).join(" ")})${u(e[1])}`}function c(e){if("number"==typeof e)return Number.isInteger(e)?function(e){if(e<-999999999999999||e>999999999999999)throw new o("Structured headers can only encode integers in the range range of -999,999,999,999,999 to 999,999,999,999,999 inclusive");return e.toString()}(e):function(e){const t=e.toFixed(3).replace(/0+$/,"");if(t.split(".")[0].replace("-","").length>12)throw new o("Fractional numbers are not allowed to have more than 12 significant digits before the decimal point");return t}(e);if("string"==typeof e)return function(e){if(!n.isAscii(e))throw new o("Only ASCII strings may be serialized");return`"${e.replace(/("|\\)/g,(e=>"\\"+e))}"`}(e);if(e instanceof s.Token)return function(e){return e.toString()}(e);if(e instanceof i.ByteSequence)return function(e){return`:${e.toBase64()}:`}(e);if("boolean"==typeof e)return function(e){return e?"?1":"?0"}(e);throw new o("Cannot serialize values of type "+typeof e)}function u(e){return Array.from(e).map((([e,t])=>{let r=";"+p(e);return!0!==t&&(r+="="+c(t)),r})).join("")}function p(e){if(!n.isValidKeyStr(e))throw new o("Keys in dictionaries must only contain lowercase letter, numbers, _-*. and must start with a letter or *");return e}t.SerializeError=o,t.serializeList=function(e){return e.map((e=>n.isInnerList(e)?h(e):a(e))).join(", ")},t.serializeDictionary=function(e){return Array.from(e.entries()).map((([e,t])=>{let r=p(e);return!0===t[0]?r+=u(t[1]):(r+="=",n.isInnerList(t)?r+=h(t):r+=a(t)),r})).join(", ")},t.serializeItem=a},0:function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.Token=void 0;const i=r(128);t.Token=class{constructor(e){if(!i.isValidTokenStr(e))throw new TypeError("Invalid character in Token string. Tokens must start with *, A-Z and the rest of the string may only contain a-z, A-Z, 0-9, :/!#$%&'*+-.^_`|~");this.value=e}toString(){return this.value}}},985:function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.ByteSequence=void 0,t.ByteSequence=class{constructor(e){this.base64Value=e}toBase64(){return this.base64Value}}},128:function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.isInnerList=t.isValidKeyStr=t.isValidTokenStr=t.isAscii=void 0;const r=/^[\x20-\x7E]*$/,i=/^[a-zA-Z*][:/!#$%&'*+\-.^_`|~A-Za-z0-9]*$/,s=/^[a-z*][*\-_.a-z0-9]*$/;t.isAscii=function(e){return r.test(e)},t.isValidTokenStr=function(e){return i.test(e)},t.isValidKeyStr=function(e){return s.test(e)},t.isInnerList=function(e){return Array.isArray(e[0])}}},t={},r=function r(i){var s=t[i];if(void 0!==s)return s.exports;var n=t[i]={exports:{}};return e[i].call(n.exports,n,n.exports,r),n.exports}(590);structuredHeader=r}();
var structuredHeader;!function(){"use strict";var e={590:function(e,t,r){var i=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var s=Object.getOwnPropertyDescriptor(t,r);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,s)}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),s=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||i(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),t.Token=void 0,s(r(223),t),s(r(759),t),s(r(985),t),s(r(128),t);var n=r(0);Object.defineProperty(t,"Token",{enumerable:!0,get:function(){return n.Token}})},759:function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.ParseError=t.parseItem=t.parseList=t.parseDictionary=void 0;const i=r(985),s=r(0),n=r(128);t.parseDictionary=function(e){return new a(e).parseDictionary()},t.parseList=function(e){return new a(e).parseList()},t.parseItem=function(e){return new a(e).parseItem()};class o extends Error{constructor(e,t){super(`Parse error: ${t} at offset ${e}`)}}t.ParseError=o;class a{constructor(e){this.input=e,this.pos=0}parseDictionary(){this.skipWS();const e=new Map;for(;!this.eof();){const t=this.parseKey();let r;if("="===this.lookChar()?(this.pos++,r=this.parseItemOrInnerList()):r=[!0,this.parseParameters()],e.set(t,r),this.skipOWS(),this.eof())return e;if(this.expectChar(","),this.pos++,this.skipOWS(),this.eof())throw new o(this.pos,"Dictionary contained a trailing comma")}return e}parseList(){this.skipWS();const e=[];for(;!this.eof();){if(e.push(this.parseItemOrInnerList()),this.skipOWS(),this.eof())return e;if(this.expectChar(","),this.pos++,this.skipOWS(),this.eof())throw new o(this.pos,"A list may not end with a trailing comma")}return e}parseItem(e=!0){e&&this.skipWS();const t=[this.parseBareItem(),this.parseParameters()];return e&&this.checkTrail(),t}parseItemOrInnerList(){return"("===this.lookChar()?this.parseInnerList():this.parseItem(!1)}parseInnerList(){this.expectChar("("),this.pos++;const e=[];for(;!this.eof();){if(this.skipWS(),")"===this.lookChar())return this.pos++,[e,this.parseParameters()];e.push(this.parseItem(!1));const t=this.lookChar();if(" "!==t&&")"!==t)throw new o(this.pos,"Expected a whitespace or ) after every item in an inner list")}throw new o(this.pos,"Could not find end of inner list")}parseBareItem(){const e=this.lookChar();if(e.match(/^[-0-9]/))return this.parseIntegerOrDecimal();if('"'===e)return this.parseString();if(e.match(/^[A-Za-z*]/))return this.parseToken();if(":"===e)return this.parseByteSequence();if("?"===e)return this.parseBoolean();throw new o(this.pos,"Unexpected input")}parseParameters(){const e=new Map;for(;!this.eof()&&";"===this.lookChar();){this.pos++,this.skipWS();const t=this.parseKey();let r=!0;"="===this.lookChar()&&(this.pos++,r=this.parseBareItem()),e.set(t,r)}return e}parseIntegerOrDecimal(){let e="integer",t=1,r="";if("-"===this.lookChar()&&(t=-1,this.pos++),!c(this.lookChar()))throw new o(this.pos,"Expected a digit (0-9)");for(;!this.eof();){const t=this.getChar();if(c(t))r+=t;else{if("integer"!==e||"."!==t){this.pos--;break}if(r.length>12)throw new o(this.pos,"Exceeded maximum decimal length");r+=".",e="decimal"}if("integer"===e&&r.length>15)throw new o(this.pos,"Exceeded maximum integer length");if("decimal"===e&&r.length>16)throw new o(this.pos,"Exceeded maximum decimal length")}if("integer"===e)return parseInt(r,10)*t;if(r.endsWith("."))throw new o(this.pos,"Decimal cannot end on a period");if(r.split(".")[1].length>3)throw new o(this.pos,"Number of digits after the decimal point cannot exceed 3");return parseFloat(r)*t}parseString(){let e="";for(this.expectChar('"'),this.pos++;!this.eof();){const t=this.getChar();if("\\"===t){if(this.eof())throw new o(this.pos,"Unexpected end of input");const t=this.getChar();if("\\"!==t&&'"'!==t)throw new o(this.pos,"A backslash must be followed by another backslash or double quote");e+=t}else{if('"'===t)return e;if(!(0,n.isAscii)(t))throw new Error("Strings must be in the ASCII range");e+=t}}throw new o(this.pos,"Unexpected end of input")}parseToken(){let e="";for(;!this.eof();){const t=this.lookChar();if(!/^[:/!#$%&'*+\-.^_`|~A-Za-z0-9]$/.test(t))return new s.Token(e);e+=this.getChar()}return new s.Token(e)}parseByteSequence(){this.expectChar(":"),this.pos++;const e=this.input.indexOf(":",this.pos);if(-1===e)throw new o(this.pos,'Could not find a closing ":" character to mark end of Byte Sequence');const t=this.input.substring(this.pos,e);if(this.pos+=t.length+1,!/^[A-Za-z0-9+/=]*$/.test(t))throw new o(this.pos,"ByteSequence does not contain a valid base64 string");return new i.ByteSequence(t)}parseBoolean(){this.expectChar("?"),this.pos++;const e=this.getChar();if("1"===e)return!0;if("0"===e)return!1;throw new o(this.pos,'Unexpected character. Expected a "1" or a "0"')}parseKey(){if(!this.lookChar().match(/^[a-z*]/))throw new o(this.pos,"A key must begin with an asterisk or letter (a-z)");let e="";for(;!this.eof();){const t=this.lookChar();if(!/^[a-z0-9_\-.*]$/.test(t))return e;e+=this.getChar()}return e}lookChar(){return this.input[this.pos]}expectChar(e){if(this.lookChar()!==e)throw new o(this.pos,`Expected ${e}`)}getChar(){return this.input[this.pos++]}eof(){return this.pos>=this.input.length}skipOWS(){for(;;){const e=this.input.substr(this.pos,1);if(" "!==e&&"\t"!==e)break;this.pos++}}skipWS(){for(;" "===this.lookChar();)this.pos++}checkTrail(){if(this.skipWS(),!this.eof())throw new o(this.pos,"Unexpected characters at end of input")}}t.default=a;const h=/^[0-9]$/;function c(e){return h.test(e)}},223:function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.serializeKey=t.serializeParameters=t.serializeToken=t.serializeByteSequence=t.serializeBoolean=t.serializeString=t.serializeDecimal=t.serializeInteger=t.serializeBareItem=t.serializeInnerList=t.serializeItem=t.serializeDictionary=t.serializeList=t.SerializeError=void 0;const i=r(985),s=r(0),n=r(128);class o extends Error{}function a(e){return c(e[0])+w(e[1])}function h(e){return`(${e[0].map((e=>a(e))).join(" ")})${w(e[1])}`}function c(e){if("number"==typeof e)return Number.isInteger(e)?u(e):p(e);if("string"==typeof e)return l(e);if(e instanceof s.Token)return m(e);if(e instanceof i.ByteSequence)return d(e);if("boolean"==typeof e)return f(e);throw new o("Cannot serialize values of type "+typeof e)}function u(e){if(e<-999999999999999||e>999999999999999)throw new o("Structured headers can only encode integers in the range range of -999,999,999,999,999 to 999,999,999,999,999 inclusive");return e.toString()}function p(e){const t=e.toFixed(3).replace(/0+$/,"");if(t.split(".")[0].replace("-","").length>12)throw new o("Fractional numbers are not allowed to have more than 12 significant digits before the decimal point");return t}function l(e){if(!(0,n.isAscii)(e))throw new o("Only ASCII strings may be serialized");return`"${e.replace(/("|\\)/g,(e=>"\\"+e))}"`}function f(e){return e?"?1":"?0"}function d(e){return`:${e.toBase64()}:`}function m(e){return e.toString()}function w(e){return Array.from(e).map((([e,t])=>{let r=";"+g(e);return!0!==t&&(r+="="+c(t)),r})).join("")}function g(e){if(!(0,n.isValidKeyStr)(e))throw new o("Keys in dictionaries must only contain lowercase letter, numbers, _-*. and must start with a letter or *");return e}t.SerializeError=o,t.serializeList=function(e){return e.map((e=>(0,n.isInnerList)(e)?h(e):a(e))).join(", ")},t.serializeDictionary=function(e){return Array.from(e.entries()).map((([e,t])=>{let r=g(e);return!0===t[0]?r+=w(t[1]):(r+="=",(0,n.isInnerList)(t)?r+=h(t):r+=a(t)),r})).join(", ")},t.serializeItem=a,t.serializeInnerList=h,t.serializeBareItem=c,t.serializeInteger=u,t.serializeDecimal=p,t.serializeString=l,t.serializeBoolean=f,t.serializeByteSequence=d,t.serializeToken=m,t.serializeParameters=w,t.serializeKey=g},0:function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.Token=void 0;const i=r(128);t.Token=class{constructor(e){if(!(0,i.isValidTokenStr)(e))throw new TypeError("Invalid character in Token string. Tokens must start with *, A-Z and the rest of the string may only contain a-z, A-Z, 0-9, :/!#$%&'*+-.^_`|~");this.value=e}toString(){return this.value}}},985:function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.ByteSequence=void 0,t.ByteSequence=class{constructor(e){this.base64Value=e}toBase64(){return this.base64Value}}},128:function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.isByteSequence=t.isInnerList=t.isValidKeyStr=t.isValidTokenStr=t.isAscii=void 0;const r=/^[\x20-\x7E]*$/,i=/^[a-zA-Z*][:/!#$%&'*+\-.^_`|~A-Za-z0-9]*$/,s=/^[a-z*][*\-_.a-z0-9]*$/;t.isAscii=function(e){return r.test(e)},t.isValidTokenStr=function(e){return i.test(e)},t.isValidKeyStr=function(e){return s.test(e)},t.isInnerList=function(e){return Array.isArray(e[0])},t.isByteSequence=function(e){return"object"==typeof e&&"base64Value"in e}}},t={},r=function r(i){var s=t[i];if(void 0!==s)return s.exports;var n=t[i]={exports:{}};return e[i].call(n.exports,n,n.exports,r),n.exports}(590);structuredHeader=r}();
//# sourceMappingURL=structured-header.min.js.map
export * from './serializer';
export * from './parser';
export * from './types';
export * from './util';
export { Token } from './token';
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -17,4 +21,5 @@ if (k2 === undefined) k2 = k;

__exportStar(require("./types"), exports);
__exportStar(require("./util"), exports);
var token_1 = require("./token");
Object.defineProperty(exports, "Token", { enumerable: true, get: function () { return token_1.Token; } });
//# sourceMappingURL=index.js.map

@@ -227,3 +227,3 @@ "use strict";

}
else if (!util_1.isAscii(char)) {
else if (!(0, util_1.isAscii)(char)) {
throw new Error('Strings must be in the ASCII range');

@@ -230,0 +230,0 @@ }

@@ -1,2 +0,3 @@

import { Dictionary, Item, List } from './types';
import { BareItem, ByteSequence, Dictionary, InnerList, Item, List, Parameters } from './types';
import { Token } from './token';
export declare class SerializeError extends Error {

@@ -7,1 +8,11 @@ }

export declare function serializeItem(input: Item): string;
export declare function serializeInnerList(input: InnerList): string;
export declare function serializeBareItem(input: BareItem): string;
export declare function serializeInteger(input: number): string;
export declare function serializeDecimal(input: number): string;
export declare function serializeString(input: string): string;
export declare function serializeBoolean(input: boolean): string;
export declare function serializeByteSequence(input: ByteSequence): string;
export declare function serializeToken(input: Token): string;
export declare function serializeParameters(input: Parameters): string;
export declare function serializeKey(input: string): string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.serializeItem = exports.serializeDictionary = exports.serializeList = exports.SerializeError = void 0;
exports.serializeKey = exports.serializeParameters = exports.serializeToken = exports.serializeByteSequence = exports.serializeBoolean = exports.serializeString = exports.serializeDecimal = exports.serializeInteger = exports.serializeBareItem = exports.serializeInnerList = exports.serializeItem = exports.serializeDictionary = exports.serializeList = exports.SerializeError = void 0;
const types_1 = require("./types");

@@ -12,3 +12,3 @@ const token_1 = require("./token");

return input.map(value => {
if (util_1.isInnerList(value)) {
if ((0, util_1.isInnerList)(value)) {
return serializeInnerList(value);

@@ -30,3 +30,3 @@ }

out += '=';
if (util_1.isInnerList(value)) {
if ((0, util_1.isInnerList)(value)) {
out += serializeInnerList(value);

@@ -49,2 +49,3 @@ }

}
exports.serializeInnerList = serializeInnerList;
function serializeBareItem(input) {

@@ -71,2 +72,3 @@ if (typeof input === 'number') {

}
exports.serializeBareItem = serializeBareItem;
function serializeInteger(input) {

@@ -78,2 +80,3 @@ if (input < -999999999999999 || input > 999999999999999) {

}
exports.serializeInteger = serializeInteger;
function serializeDecimal(input) {

@@ -87,4 +90,5 @@ const out = input.toFixed(3).replace(/0+$/, '');

}
exports.serializeDecimal = serializeDecimal;
function serializeString(input) {
if (!util_1.isAscii(input)) {
if (!(0, util_1.isAscii)(input)) {
throw new SerializeError('Only ASCII strings may be serialized');

@@ -94,11 +98,15 @@ }

}
exports.serializeString = serializeString;
function serializeBoolean(input) {
return input ? '?1' : '?0';
}
exports.serializeBoolean = serializeBoolean;
function serializeByteSequence(input) {
return `:${input.toBase64()}:`;
}
exports.serializeByteSequence = serializeByteSequence;
function serializeToken(input) {
return input.toString();
}
exports.serializeToken = serializeToken;
function serializeParameters(input) {

@@ -113,4 +121,5 @@ return Array.from(input).map(([key, value]) => {

}
exports.serializeParameters = serializeParameters;
function serializeKey(input) {
if (!util_1.isValidKeyStr(input)) {
if (!(0, util_1.isValidKeyStr)(input)) {
throw new SerializeError('Keys in dictionaries must only contain lowercase letter, numbers, _-*. and must start with a letter or *');

@@ -120,2 +129,3 @@ }

}
exports.serializeKey = serializeKey;
//# sourceMappingURL=serializer.js.map

@@ -7,3 +7,3 @@ "use strict";

constructor(value) {
if (!util_1.isValidTokenStr(value)) {
if (!(0, util_1.isValidTokenStr)(value)) {
throw new TypeError('Invalid character in Token string. Tokens must start with *, A-Z and the rest of the string may only contain a-z, A-Z, 0-9, :/!#$%&\'*+-.^_`|~');

@@ -10,0 +10,0 @@ }

@@ -1,2 +0,2 @@

import { Item, InnerList } from './types';
import { Item, InnerList, BareItem, ByteSequence } from './types';
export declare function isAscii(str: string): boolean;

@@ -6,1 +6,2 @@ export declare function isValidTokenStr(str: string): boolean;

export declare function isInnerList(input: Item | InnerList): input is InnerList;
export declare function isByteSequence(input: BareItem): input is ByteSequence;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isInnerList = exports.isValidKeyStr = exports.isValidTokenStr = exports.isAscii = void 0;
exports.isByteSequence = exports.isInnerList = exports.isValidKeyStr = exports.isValidTokenStr = exports.isAscii = void 0;
const asciiRe = /^[\x20-\x7E]*$/;

@@ -23,2 +23,6 @@ const tokenRe = /^[a-zA-Z*][:/!#$%&'*+\-.^_`|~A-Za-z0-9]*$/;

exports.isInnerList = isInnerList;
function isByteSequence(input) {
return typeof input === 'object' && 'base64Value' in input;
}
exports.isByteSequence = isByteSequence;
//# sourceMappingURL=util.js.map
{
"name": "structured-headers",
"version": "0.4.1",
"version": "0.5.0",
"description": "Implementation of RFC8941, structured headers for HTTP.",

@@ -35,10 +35,12 @@ "main": "dist/index.js",

"devDependencies": {
"@types/chai": "^4.3.3",
"@types/mocha": "^9.1.1",
"@types/node": "^12.20.13",
"@typescript-eslint/eslint-plugin": "^4.23.0",
"@typescript-eslint/parser": "^4.23.0",
"@typescript-eslint/eslint-plugin": "^5.36.2",
"@typescript-eslint/parser": "^5.36.2",
"base32-decode": "^1.0.0",
"base32-encode": "^1.1.1",
"chai": "^4.2.0",
"eslint": "^7.26.0",
"mocha": "^9.0.0",
"eslint": "^8.23.0",
"mocha": "^10.0.0",
"nyc": "^15.1.0",

@@ -45,0 +47,0 @@ "ts-node": "^10.0.0",

export * from './serializer';
export * from './parser';
export * from './types';
export * from './util';
export { Token } from './token';

@@ -60,3 +60,3 @@ import {

function serializeInnerList(input: InnerList): string {
export function serializeInnerList(input: InnerList): string {

@@ -68,3 +68,3 @@ return `(${input[0].map(value => serializeItem(value)).join(' ')})${serializeParameters(input[1])}`;

function serializeBareItem(input: BareItem): string {
export function serializeBareItem(input: BareItem): string {
if (typeof input === 'number') {

@@ -91,3 +91,3 @@ if (Number.isInteger(input)) {

function serializeInteger(input: number): string {
export function serializeInteger(input: number): string {

@@ -100,3 +100,3 @@ if (input < -999_999_999_999_999 || input > 999_999_999_999_999) {

function serializeDecimal(input: number): string {
export function serializeDecimal(input: number): string {
const out = input.toFixed(3).replace(/0+$/,'');

@@ -111,3 +111,3 @@ const signifantDigits = out.split('.')[0].replace('-','').length;

function serializeString(input: string): string {
export function serializeString(input: string): string {
if (!isAscii(input)) {

@@ -119,15 +119,15 @@ throw new SerializeError('Only ASCII strings may be serialized');

function serializeBoolean(input: boolean): string {
export function serializeBoolean(input: boolean): string {
return input ? '?1' : '?0';
}
function serializeByteSequence(input: ByteSequence): string {
export function serializeByteSequence(input: ByteSequence): string {
return `:${input.toBase64()}:`;
}
function serializeToken(input: Token): string {
export function serializeToken(input: Token): string {
return input.toString();
}
function serializeParameters(input: Parameters): string {
export function serializeParameters(input: Parameters): string {

@@ -146,3 +146,3 @@ return Array.from(input).map(([key, value]) => {

function serializeKey(input: string): string {
export function serializeKey(input: string): string {

@@ -149,0 +149,0 @@ if (!isValidKeyStr(input)) {

@@ -1,2 +0,2 @@

import { Item, InnerList } from './types';
import { Item, InnerList, BareItem, ByteSequence } from './types';

@@ -31,1 +31,8 @@ const asciiRe = /^[\x20-\x7E]*$/;

}
export function isByteSequence(input: BareItem): input is ByteSequence {
return typeof input === 'object' && 'base64Value' in input;
}

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

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

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc