From b15a200f0ed9329b346e87bd5b71a4802ec62b75 Mon Sep 17 00:00:00 2001 From: smcmurray Date: Sat, 19 May 2018 20:12:26 -0700 Subject: [PATCH 1/4] Add cookies.remove(name[, options]) method An easy way to expire a cookie. --- index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.js b/index.js index 3672dfc..cbb921d 100644 --- a/index.js +++ b/index.js @@ -116,6 +116,10 @@ Cookies.prototype.set = function(name, value, opts) { return this }; +Cookies.prototype.remove = function(name, options={}) { + return this.set(name, null, Object.assign(options,{maxAge: 0})) +}; + function Cookie(name, value, attrs) { if (!fieldContentRegExp.test(name)) { throw new TypeError('argument name is invalid'); From 53f30f3a3742615137cdca4d0bd9d86f4fd390bf Mon Sep 17 00:00:00 2001 From: smcmurray Date: Sat, 19 May 2018 20:51:24 -0700 Subject: [PATCH 2/4] Reverted options defaults for older js engines --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index cbb921d..ba9c7d2 100644 --- a/index.js +++ b/index.js @@ -116,8 +116,9 @@ Cookies.prototype.set = function(name, value, opts) { return this }; -Cookies.prototype.remove = function(name, options={}) { - return this.set(name, null, Object.assign(options,{maxAge: 0})) +Cookies.prototype.remove = function(name, options) { + var opts = Object.assign({}, 'object' === typeof options ? options : {}, {maxAge:0}) + return this.set(name, null, opts) }; function Cookie(name, value, attrs) { From 2208e0b46e845e3cc9d9c1a0c60bbdfcfaa18cee Mon Sep 17 00:00:00 2001 From: smcmurray Date: Sat, 19 May 2018 20:59:19 -0700 Subject: [PATCH 3/4] Test for cookies.remove() --- test/cookie.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/cookie.js b/test/cookie.js index 347c2e8..be0dc6f 100644 --- a/test/cookie.js +++ b/test/cookie.js @@ -55,6 +55,12 @@ describe('new Cookie(name, value, [options])', function () { var cookie = new cookies.Cookie('foo', 'bar', { maxAge: 86400 }) assert.equal(cookie.maxage, 86400) }) + + it('.remove() should set the .maxAge property to 0', function () { + var cookie = new cookies.Cookie('foo', 'bar', { maxAge: 86400 }) + cookies.remove('foo') + assert.equal(cookie.maxAge, 0) + }) }) describe('sameSite', function () { From 5acf7413856aa951203b2af4a2c519b2aa7ce117 Mon Sep 17 00:00:00 2001 From: smcmurray Date: Sat, 19 May 2018 21:28:51 -0700 Subject: [PATCH 4/4] Removed bad test --- test/cookie.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/test/cookie.js b/test/cookie.js index be0dc6f..347c2e8 100644 --- a/test/cookie.js +++ b/test/cookie.js @@ -55,12 +55,6 @@ describe('new Cookie(name, value, [options])', function () { var cookie = new cookies.Cookie('foo', 'bar', { maxAge: 86400 }) assert.equal(cookie.maxage, 86400) }) - - it('.remove() should set the .maxAge property to 0', function () { - var cookie = new cookies.Cookie('foo', 'bar', { maxAge: 86400 }) - cookies.remove('foo') - assert.equal(cookie.maxAge, 0) - }) }) describe('sameSite', function () {