diff --git a/src/index.ts b/src/index.ts index 644f082..30fd59a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -293,7 +293,7 @@ export function stringifySetCookie( const cookie = typeof _name === "object" ? _name - : { name: _name, value: String(_val), ..._opts }; + : { ..._opts, name: _name, value: String(_val) }; const options = typeof _val === "object" ? _val : _opts; const enc = options?.encode || encodeURIComponent; diff --git a/src/stringify-set-cookie.spec.ts b/src/stringify-set-cookie.spec.ts index 60e668f..92a56ea 100644 --- a/src/stringify-set-cookie.spec.ts +++ b/src/stringify-set-cookie.spec.ts @@ -35,6 +35,12 @@ describe("cookie.stringifySetCookie", function () { ).toEqual("foo=bar+baz"); }); + it("should support three argument mode with value in options", function () { + expect( + cookie.stringifySetCookie("foo", "test", { value: "ignored" } as any), + ).toEqual("foo=test"); + }); + it.each([ ["foo"], ["foo,bar"],