Skip to content

Commit

Permalink
Improve the logic of isNode(). (#421)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamuratak committed Dec 22, 2023
1 parent f37cc7b commit 6417eaf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/environment.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@

// source: https://github.com/flexdinesh/browser-or-node
// source: https://github.com/mozilla/pdf.js/blob/7ea0e40e588864cd938d1836ec61f1928d3877d3/src/shared/util.js#L24
var isNode = function (nodeProcess) {
return (
typeof nodeProcess !== 'undefined' &&
nodeProcess.versions != null &&
nodeProcess.versions.node != null
nodeProcess.versions.node != null &&
nodeProcess + '' === '[object process]'
);
}
module.exports.isNode = isNode
Expand Down
3 changes: 2 additions & 1 deletion test/environment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ describe('Environment Detection', function () {
assert.strictEqual(isNode(undefined), false)
assert.strictEqual(isNode({}), false)
assert.strictEqual(isNode({ versions: {} }), false)
assert.strictEqual(isNode({ versions: { node: '10.0.0' } }), false)
})

it('is platform assigned to be node', function () {
assert.strictEqual(isNode({ versions: { node: '10.0.0' } }), true)
assert.strictEqual(isNode(process), true)
})
})

Expand Down

0 comments on commit 6417eaf

Please sign in to comment.