Socket
Socket
Sign inDemoInstall

@tinyhttp/cookie

Package Overview
Dependencies
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tinyhttp/cookie - npm Package Compare versions

Comparing version 0.0.8 to 0.0.9

4

dist/index.d.ts

@@ -8,3 +8,5 @@ /**

*/
declare function parse(str: string): {};
declare function parse(str: string, options?: {
decode: (str: string) => any;
}): {};
type SerializeOptions = Partial<{

@@ -11,0 +13,0 @@ encode: (str: string) => string;

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

const e=/; */,t=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;function i(e){try{return decodeURIComponent(e)}catch(t){return e}}function n(t){let n={};const r=t.split(e);for(const e of r){let t=e.indexOf("=");if(t<0)continue;const r=e.substr(0,t).trim();let o=e.substr(++t,e.length).trim();'"'==o[0]&&(o=o.slice(1,-1)),null==n[r]&&(n[r]=i(o))}return n}function r(e,i,{encode:n=encodeURIComponent,domain:r,secure:o,httpOnly:a,expires:s,path:c,...f}){if(!t.test(e))throw new TypeError("argument name is invalid");const p=n(i);if(p&&!t.test(p))throw new TypeError("argument val is invalid");var l=e+"="+p;if(null!=f.maxAge){const e=f.maxAge-0;if(isNaN(e)||!isFinite(e))throw new TypeError("option maxAge is invalid");l+="; Max-Age="+Math.floor(e)}if(r){if(!t.test(r))throw new TypeError("option domain is invalid");l+="; Domain="+r}if(c){if(!t.test(c))throw new TypeError("option path is invalid");l+="; Path="+c}if(s){if("function"!=typeof s.toUTCString)throw new TypeError("option expires is invalid");l+="; Expires="+s.toUTCString()}if(a&&(l+="; HttpOnly"),o&&(l+="; Secure"),f.sameSite){switch("string"==typeof f.sameSite?f.sameSite.toLowerCase():f.sameSite){case!0:l+="; SameSite=Strict";break;case"lax":l+="; SameSite=Lax";break;case"strict":l+="; SameSite=Strict";break;case"none":l+="; SameSite=None";break;default:throw new TypeError("option sameSite is invalid")}}return l}export{n as parse,r as serialize};
const e=/; */,t=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;function i(e,t=decodeURIComponent){try{return t(e)}catch(t){return e}}function n(t,n={decode:decodeURIComponent}){let o={};const r=t.split(e);for(const e of r){let t=e.indexOf("=");if(t<0)continue;const r=e.substr(0,t).trim();let a=e.substr(++t,e.length).trim();'"'==a[0]&&(a=a.slice(1,-1)),null==o[r]&&(o[r]=i(a,n.decode))}return o}function o(e,i,{encode:n=encodeURIComponent,domain:o,secure:r,httpOnly:a,expires:s,path:c,...p}){if(!t.test(e))throw new TypeError("argument name is invalid");const f=n(i);if(f&&!t.test(f))throw new TypeError("argument val is invalid");var l=e+"="+f;if(null!=p.maxAge){const e=p.maxAge-0;if(isNaN(e)||!isFinite(e))throw new TypeError("option maxAge is invalid");l+="; Max-Age="+Math.floor(e)}if(o){if(!t.test(o))throw new TypeError("option domain is invalid");l+="; Domain="+o}if(c){if(!t.test(c))throw new TypeError("option path is invalid");l+="; Path="+c}if(s){if("function"!=typeof s.toUTCString)throw new TypeError("option expires is invalid");l+="; Expires="+s.toUTCString()}if(a&&(l+="; HttpOnly"),r&&(l+="; Secure"),p.sameSite){switch("string"==typeof p.sameSite?p.sameSite.toLowerCase():p.sameSite){case!0:l+="; SameSite=Strict";break;case"lax":l+="; SameSite=Lax";break;case"strict":l+="; SameSite=Strict";break;case"none":l+="; SameSite=None";break;default:throw new TypeError("option sameSite is invalid")}}return l}export{n as parse,o as serialize};

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e=/; */,t=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;function i(e){try{return decodeURIComponent(e)}catch(t){return e}}exports.parse=function(t){let r={};const n=t.split(e);for(const e of n){let t=e.indexOf("=");if(t<0)continue;const n=e.substr(0,t).trim();let o=e.substr(++t,e.length).trim();'"'==o[0]&&(o=o.slice(1,-1)),null==r[n]&&(r[n]=i(o))}return r},exports.serialize=function(e,i,{encode:r=encodeURIComponent,domain:n,secure:o,httpOnly:s,expires:a,path:c,...p}){if(!t.test(e))throw new TypeError("argument name is invalid");const f=r(i);if(f&&!t.test(f))throw new TypeError("argument val is invalid");var l=e+"="+f;if(null!=p.maxAge){const e=p.maxAge-0;if(isNaN(e)||!isFinite(e))throw new TypeError("option maxAge is invalid");l+="; Max-Age="+Math.floor(e)}if(n){if(!t.test(n))throw new TypeError("option domain is invalid");l+="; Domain="+n}if(c){if(!t.test(c))throw new TypeError("option path is invalid");l+="; Path="+c}if(a){if("function"!=typeof a.toUTCString)throw new TypeError("option expires is invalid");l+="; Expires="+a.toUTCString()}if(s&&(l+="; HttpOnly"),o&&(l+="; Secure"),p.sameSite){switch("string"==typeof p.sameSite?p.sameSite.toLowerCase():p.sameSite){case!0:l+="; SameSite=Strict";break;case"lax":l+="; SameSite=Lax";break;case"strict":l+="; SameSite=Strict";break;case"none":l+="; SameSite=None";break;default:throw new TypeError("option sameSite is invalid")}}return l};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e=/; */,t=/^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;function i(e,t=decodeURIComponent){try{return t(e)}catch(t){return e}}exports.parse=function(t,r={decode:decodeURIComponent}){let n={};const o=t.split(e);for(const e of o){let t=e.indexOf("=");if(t<0)continue;const o=e.substr(0,t).trim();let s=e.substr(++t,e.length).trim();'"'==s[0]&&(s=s.slice(1,-1)),null==n[o]&&(n[o]=i(s,r.decode))}return n},exports.serialize=function(e,i,{encode:r=encodeURIComponent,domain:n,secure:o,httpOnly:s,expires:a,path:c,...p}){if(!t.test(e))throw new TypeError("argument name is invalid");const f=r(i);if(f&&!t.test(f))throw new TypeError("argument val is invalid");var l=e+"="+f;if(null!=p.maxAge){const e=p.maxAge-0;if(isNaN(e)||!isFinite(e))throw new TypeError("option maxAge is invalid");l+="; Max-Age="+Math.floor(e)}if(n){if(!t.test(n))throw new TypeError("option domain is invalid");l+="; Domain="+n}if(c){if(!t.test(c))throw new TypeError("option path is invalid");l+="; Path="+c}if(a){if("function"!=typeof a.toUTCString)throw new TypeError("option expires is invalid");l+="; Expires="+a.toUTCString()}if(s&&(l+="; HttpOnly"),o&&(l+="; Secure"),p.sameSite){switch("string"==typeof p.sameSite?p.sameSite.toLowerCase():p.sameSite){case!0:l+="; SameSite=Strict";break;case"lax":l+="; SameSite=Lax";break;case"strict":l+="; SameSite=Strict";break;case"none":l+="; SameSite=None";break;default:throw new TypeError("option sameSite is invalid")}}return l};
{
"name": "@tinyhttp/cookie",
"version": "0.0.8",
"version": "0.0.9",
"description": "HTTP cookie parser and serializer for Node.js",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/talentlessguy/tinyhttp",

@@ -13,5 +13,5 @@ const pairSplitRegExp = /; */

function tryDecode(str: string) {
function tryDecode(str: string, decode: (str: string) => any = decodeURIComponent) {
try {
return decodeURIComponent(str)
return decode(str)
} catch (e) {

@@ -29,3 +29,10 @@ return str

*/
export function parse(str: string) {
export function parse(
str: string,
options: {
decode: (str: string) => any
} = {
decode: decodeURIComponent
}
) {
let obj = {}

@@ -49,3 +56,3 @@ const pairs = str.split(pairSplitRegExp)

// only assign once
if (obj[key] == null) obj[key] = tryDecode(val)
if (obj[key] == null) obj[key] = tryDecode(val, options.decode)
}

@@ -52,0 +59,0 @@

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