From f4ff44fcbe0a272afa6e128ebd38df596cf72aac Mon Sep 17 00:00:00 2001 From: Kenan Soylu Date: Thu, 4 May 2023 15:11:25 +0200 Subject: [PATCH 1/5] fix: check process on browser --- lib/ini.js | 6 +++--- tap-snapshots/test/foo.js.test.cjs | 10 ++++++++++ test/foo.js | 10 ++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/ini.js b/lib/ini.js index 763c829..9516ae8 100644 --- a/lib/ini.js +++ b/lib/ini.js @@ -9,7 +9,7 @@ const encode = (obj, opt = {}) => { opt.sort = opt.sort === true opt.whitespace = opt.whitespace === true || opt.align === true /* istanbul ignore next */ - opt.platform = opt.platform || process?.platform + opt.platform = opt.platform || (typeof process === 'undefined' ? null : process.platform) opt.bracketedArray = opt.bracketedArray !== false /* istanbul ignore next */ @@ -172,8 +172,8 @@ const decode = (str, opt = {}) => { const remove = [] for (const k of Object.keys(out)) { if (!hasOwnProperty.call(out, k) || - typeof out[k] !== 'object' || - Array.isArray(out[k])) { + typeof out[k] !== 'object' || + Array.isArray(out[k])) { continue } diff --git a/tap-snapshots/test/foo.js.test.cjs b/tap-snapshots/test/foo.js.test.cjs index 26b81ce..2646323 100644 --- a/tap-snapshots/test/foo.js.test.cjs +++ b/tap-snapshots/test/foo.js.test.cjs @@ -292,3 +292,13 @@ label = debug value = 10 ` + +exports[`test/foo.js TAP encode within browser context > must match snapshot 1`] = ` +[log] +type=file + +[log.level] +label=debug +value=10 + +` diff --git a/test/foo.js b/test/foo.js index 4d380e3..93127e1 100644 --- a/test/foo.js +++ b/test/foo.js @@ -84,3 +84,13 @@ test('encode with align and sort', function (t) { t.matchSnapshot(e) t.end() }) + +test('encode within browser context', function (t) { + process = undefined + + const obj = { log: { type: 'file', level: { label: 'debug', value: 10 } } } + const e = i.encode(obj) + + t.matchSnapshot(e) + t.end() +}) From e01d37677dfdcce07357cf0b641384b3b4717689 Mon Sep 17 00:00:00 2001 From: Kenan Soylu Date: Thu, 4 May 2023 15:19:43 +0200 Subject: [PATCH 2/5] revert format --- lib/ini.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ini.js b/lib/ini.js index 9516ae8..bc58810 100644 --- a/lib/ini.js +++ b/lib/ini.js @@ -172,8 +172,8 @@ const decode = (str, opt = {}) => { const remove = [] for (const k of Object.keys(out)) { if (!hasOwnProperty.call(out, k) || - typeof out[k] !== 'object' || - Array.isArray(out[k])) { + typeof out[k] !== 'object' || + Array.isArray(out[k])) { continue } From 408bbe50a8a5e502b057d76893443f0948bf8817 Mon Sep 17 00:00:00 2001 From: Kenan Soylu Date: Thu, 4 May 2023 16:29:44 +0200 Subject: [PATCH 3/5] avoid ternery --- lib/ini.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ini.js b/lib/ini.js index bc58810..20b7dd6 100644 --- a/lib/ini.js +++ b/lib/ini.js @@ -9,7 +9,7 @@ const encode = (obj, opt = {}) => { opt.sort = opt.sort === true opt.whitespace = opt.whitespace === true || opt.align === true /* istanbul ignore next */ - opt.platform = opt.platform || (typeof process === 'undefined' ? null : process.platform) + opt.platform = opt.platform || (typeof process !== 'undefined' && process.platform) opt.bracketedArray = opt.bracketedArray !== false /* istanbul ignore next */ @@ -76,7 +76,7 @@ const encode = (obj, opt = {}) => { return out } -function splitSections (str, separator) { +function splitSections(str, separator) { var lastMatchIndex = 0 var lastSeparatorIndex = 0 var nextIndex = 0 @@ -172,8 +172,8 @@ const decode = (str, opt = {}) => { const remove = [] for (const k of Object.keys(out)) { if (!hasOwnProperty.call(out, k) || - typeof out[k] !== 'object' || - Array.isArray(out[k])) { + typeof out[k] !== 'object' || + Array.isArray(out[k])) { continue } From 41c2f49582b370ceb080961aa5ccc8fdcf3c4a64 Mon Sep 17 00:00:00 2001 From: Kenan Soylu Date: Thu, 4 May 2023 17:16:26 +0200 Subject: [PATCH 4/5] lintfix --- lib/ini.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ini.js b/lib/ini.js index 20b7dd6..d01ae41 100644 --- a/lib/ini.js +++ b/lib/ini.js @@ -76,7 +76,7 @@ const encode = (obj, opt = {}) => { return out } -function splitSections(str, separator) { +function splitSections (str, separator) { var lastMatchIndex = 0 var lastSeparatorIndex = 0 var nextIndex = 0 From 2f3b1ad65231082b28c17cc85ce7c5954f4a74f1 Mon Sep 17 00:00:00 2001 From: Kenan Soylu Date: Sun, 14 May 2023 13:08:09 +0200 Subject: [PATCH 5/5] test coverage --- lib/ini.js | 1 + test/foo.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ini.js b/lib/ini.js index d01ae41..724d69d 100644 --- a/lib/ini.js +++ b/lib/ini.js @@ -8,6 +8,7 @@ const encode = (obj, opt = {}) => { opt.newline = opt.newline === true opt.sort = opt.sort === true opt.whitespace = opt.whitespace === true || opt.align === true + // The `typeof` check is required because accessing the `process` directly fails on browsers. /* istanbul ignore next */ opt.platform = opt.platform || (typeof process !== 'undefined' && process.platform) opt.bracketedArray = opt.bracketedArray !== false diff --git a/test/foo.js b/test/foo.js index 93127e1..fe92435 100644 --- a/test/foo.js +++ b/test/foo.js @@ -86,7 +86,7 @@ test('encode with align and sort', function (t) { }) test('encode within browser context', function (t) { - process = undefined + Object.defineProperty(process, 'platform', { value: undefined }) const obj = { log: { type: 'file', level: { label: 'debug', value: 10 } } } const e = i.encode(obj)