Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/ini.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ 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 || process?.platform
opt.platform = opt.platform || (typeof process !== 'undefined' && process.platform)
opt.bracketedArray = opt.bracketedArray !== false

/* istanbul ignore next */
Expand Down Expand Up @@ -172,8 +173,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
}

Expand Down
10 changes: 10 additions & 0 deletions tap-snapshots/test/foo.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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

`
10 changes: 10 additions & 0 deletions test/foo.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,13 @@ test('encode with align and sort', function (t) {
t.matchSnapshot(e)
t.end()
})

test('encode within browser context', function (t) {
Object.defineProperty(process, 'platform', { value: undefined })

const obj = { log: { type: 'file', level: { label: 'debug', value: 10 } } }
const e = i.encode(obj)

t.matchSnapshot(e)
t.end()
})