From f3179e69d0bc723f0c4f124de63de297a526b6ad Mon Sep 17 00:00:00 2001 From: Denis Sokolov Date: Thu, 21 Jan 2021 15:49:07 +0200 Subject: [PATCH] Access global Buffer conditionally (#15) --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 6d21eb0..d1513be 100755 --- a/index.js +++ b/index.js @@ -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*:/ @@ -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() }