Skip to content

Commit

Permalink
Access global Buffer conditionally (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
denis-sokolov authored Jan 21, 2021
1 parent 4cb9129 commit f3179e6
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

const hasBuffer = typeof Buffer !== 'undefined'
const suspectProtoRx = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/
const suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/

Expand All @@ -17,7 +18,7 @@ function parse (text, reviver, options) {
const protoAction = options.protoAction || 'error'
const constructorAction = options.constructorAction || 'error'

if (Buffer.isBuffer(text)) {
if (hasBuffer && Buffer.isBuffer(text)) {
text = text.toString()
}

Expand Down

0 comments on commit f3179e6

Please sign in to comment.