Skip to content

Commit

Permalink
Remove hasOwnProperty, use undefined (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
gurgunday authored Oct 8, 2024
1 parent 93a5b97 commit 8f3ee9e
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {};
Expand Down Expand Up @@ -94,8 +93,8 @@ export interface ParseOptions {
export function parse(
str: string,
options?: ParseOptions,
): Record<string, string> {
const obj: Record<string, string> = new NullObject();
): Record<string, string | undefined> {
const obj: Record<string, string | undefined> = 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;
Expand All @@ -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);

Expand All @@ -134,7 +133,7 @@ export function parse(
}

const value = dec(str.slice(valStartIdx, valEndIdx));
if (value !== undefined) obj[key] = value;
obj[key] = value;
}

index = endIdx + 1;
Expand Down Expand Up @@ -366,7 +365,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 {
Expand Down

0 comments on commit 8f3ee9e

Please sign in to comment.