Skip to content

Commit f3179e6

Browse files
Access global Buffer conditionally (#15)
1 parent 4cb9129 commit f3179e6

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
const hasBuffer = typeof Buffer !== 'undefined'
34
const suspectProtoRx = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/
45
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*:/
56

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

20-
if (Buffer.isBuffer(text)) {
21+
if (hasBuffer && Buffer.isBuffer(text)) {
2122
text = text.toString()
2223
}
2324

0 commit comments

Comments
 (0)