From cd9082f069aae0f8dcdf897d3e9c4f09b40e8f9f Mon Sep 17 00:00:00 2001 From: NuoHui Date: Sun, 11 Apr 2021 10:26:31 +0800 Subject: [PATCH 1/2] refactor: replace `==` operator with util.isNil() --- index.js | 10 +++++----- lib/util.js | 4 ++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 816a15a..9e98b13 100644 --- a/index.js +++ b/index.js @@ -66,12 +66,12 @@ function formatOpts(opts) { if (!('maxAge' in opts)) opts.maxAge = opts.maxage; // defaults - if (opts.overwrite == null) opts.overwrite = true; - if (opts.httpOnly == null) opts.httpOnly = true; + if (util.isNil(opts.overwrite)) opts.overwrite = true; + if (util.isNil(opts.httpOnly)) opts.httpOnly = true; // delete null sameSite config - if (opts.sameSite == null) delete opts.sameSite; - if (opts.signed == null) opts.signed = true; - if (opts.autoCommit == null) opts.autoCommit = true; + if (util.isNil(opts.sameSite)) delete opts.sameSite; + if (util.isNil(opts.signed)) opts.signed = true; + if (util.isNil(opts.autoCommit)) opts.autoCommit = true; debug('session options %j', opts); diff --git a/lib/util.js b/lib/util.js index b3a1a28..c9afc9c 100644 --- a/lib/util.js +++ b/lib/util.js @@ -35,5 +35,9 @@ module.exports = { return crc(JSON.stringify(sess)); }, + isNil(val) { + return val === null || typeof val === 'undefined' + }, + CookieDateEpoch: 'Thu, 01 Jan 1970 00:00:00 GMT', }; From 5b3afa482f5d625012bf9ca355af705c3539cdf6 Mon Sep 17 00:00:00 2001 From: NuoHui Date: Sun, 11 Apr 2021 10:34:46 +0800 Subject: [PATCH 2/2] fix: lint error --- lib/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/util.js b/lib/util.js index c9afc9c..67c61ca 100644 --- a/lib/util.js +++ b/lib/util.js @@ -36,7 +36,7 @@ module.exports = { }, isNil(val) { - return val === null || typeof val === 'undefined' + return val === null || typeof val === 'undefined'; }, CookieDateEpoch: 'Thu, 01 Jan 1970 00:00:00 GMT',