Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check process on browser #208

Merged
merged 5 commits into from May 15, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/ini.js
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)
wraithgar marked this conversation as resolved.
Show resolved Hide resolved
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
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
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()
})