Skip to content

Commit c0a62e3

Browse files
fix: support parsing buffers
1 parent 04d5f32 commit c0a62e3

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function parse (text, reviver, options) {
1818
const constructorAction = options.constructorAction || 'error'
1919

2020
// BOM checker
21-
if (text && text.charCodeAt(0) === 0xFEFF) {
21+
if (text && text.charCodeAt && text.charCodeAt(0) === 0xFEFF) {
2222
text = text.slice(1)
2323
}
2424

test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ test('parse', t => {
3636
t.end()
3737
})
3838

39+
t.test('parses buffer', t => {
40+
t.strictEqual(
41+
j.parse(Buffer.from('"X"')),
42+
JSON.parse(Buffer.from('"X"'))
43+
)
44+
t.end()
45+
})
46+
3947
t.test('parses object string (reviver)', t => {
4048
const reviver = (key, value) => {
4149
return typeof value === 'number' ? value + 1 : value

0 commit comments

Comments
 (0)