From 852cab8a123295d05ceec01f0e7f20414b9e9cde Mon Sep 17 00:00:00 2001 From: Mikhail Bodrov Date: Mon, 27 Dec 2021 22:09:36 +0200 Subject: [PATCH] [Refactor] simplify checking for undefined --- lib/parse.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/parse.js b/lib/parse.js index c833315c..d197162e 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -210,13 +210,13 @@ var normalizeParseOptions = function normalizeParseOptions(opts) { throw new TypeError('Decoder has to be a function.'); } - if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') { + if (opts.charset !== undefined && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') { throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined'); } - var charset = typeof opts.charset === 'undefined' ? defaults.charset : opts.charset; + var charset = opts.charset === undefined ? defaults.charset : opts.charset; return { - allowDots: typeof opts.allowDots === 'undefined' ? defaults.allowDots : !!opts.allowDots, + allowDots: opts.allowDots === undefined ? defaults.allowDots : !!opts.allowDots, allowPrototypes: typeof opts.allowPrototypes === 'boolean' ? opts.allowPrototypes : defaults.allowPrototypes, allowSparse: typeof opts.allowSparse === 'boolean' ? opts.allowSparse : defaults.allowSparse, arrayLimit: typeof opts.arrayLimit === 'number' ? opts.arrayLimit : defaults.arrayLimit, @@ -239,7 +239,7 @@ var normalizeParseOptions = function normalizeParseOptions(opts) { module.exports = function (str, opts) { var options = normalizeParseOptions(opts); - if (str === '' || str === null || typeof str === 'undefined') { + if (str === '' || str === null || str === undefined) { return options.plainObjects ? Object.create(null) : {}; }