From 44f6e63280b1f46d6113695d3f162a285fbdd098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Tue, 8 Oct 2024 07:27:48 +0200 Subject: [PATCH 1/4] remove hasownproperty call --- src/index.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index b572fab..02c4444 100644 --- a/src/index.ts +++ b/src/index.ts @@ -59,7 +59,6 @@ const domainValueRegExp = const pathValueRegExp = /^[\u0020-\u003A\u003D-\u007E]*$/; const __toString = Object.prototype.toString; -const __hasOwnProperty = Object.prototype.hasOwnProperty; const NullObject = /* @__PURE__ */ (() => { const C = function () {}; @@ -121,7 +120,7 @@ export function parse( const key = str.slice(keyStartIdx, keyEndIdx); // only assign once - if (!__hasOwnProperty.call(obj, key)) { + if (obj[key] === undefined) { let valStartIdx = startIndex(str, eqIdx + 1, endIdx); let valEndIdx = endIndex(str, endIdx, valStartIdx); From dfa910c3e6e238926323fa981cbf3ad220ebadb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Tue, 8 Oct 2024 21:03:39 +0200 Subject: [PATCH 2/4] remove undefined check --- src/index.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 02c4444..fb62078 100644 --- a/src/index.ts +++ b/src/index.ts @@ -81,7 +81,7 @@ export interface ParseOptions { * * @default decodeURIComponent */ - decode?: (str: string) => string | undefined; + decode?: (str: string) => string; } /** @@ -133,7 +133,8 @@ export function parse( } const value = dec(str.slice(valStartIdx, valEndIdx)); - if (value !== undefined) obj[key] = value; + + obj[key] = value; } index = endIdx + 1; @@ -365,7 +366,7 @@ export function serialize( /** * URL-decode string value. Optimized to skip native call when no %. */ -function decode(str: string): string | undefined { +function decode(str: string): string { if (str.indexOf("%") === -1) return str; try { From 90dd8e055b4a0c7834aba3cacf9a909c8ab42b8b Mon Sep 17 00:00:00 2001 From: Blake Embrey Date: Tue, 8 Oct 2024 12:08:09 -0700 Subject: [PATCH 3/4] Allow undefined in type --- src/index.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index fb62078..a773692 100644 --- a/src/index.ts +++ b/src/index.ts @@ -81,7 +81,7 @@ export interface ParseOptions { * * @default decodeURIComponent */ - decode?: (str: string) => string; + decode?: (str: string) => string | undefined; } /** @@ -133,7 +133,6 @@ export function parse( } const value = dec(str.slice(valStartIdx, valEndIdx)); - obj[key] = value; } From a56d27f75221fdfdcff19ce65f85855dcf049c5e Mon Sep 17 00:00:00 2001 From: Blake Embrey Date: Tue, 8 Oct 2024 12:09:21 -0700 Subject: [PATCH 4/4] Update parse return type --- src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index a773692..4e12462 100644 --- a/src/index.ts +++ b/src/index.ts @@ -93,8 +93,8 @@ export interface ParseOptions { export function parse( str: string, options?: ParseOptions, -): Record { - const obj: Record = new NullObject(); +): Record { + const obj: Record = new NullObject(); const len = str.length; // RFC 6265 sec 4.1.1, RFC 2616 2.2 defines a cookie name consists of one char minimum, plus '='. if (len < 2) return obj;