Skip to content

Commit a4d9f10

Browse files
committed
Throw TypeError if argument is not a buffer
1 parent 8545f46 commit a4d9f10

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

index.js

+4
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@
33
const bindings = require('bindings')('ced.node')
44

55
module.exports = buf => {
6+
if (!Buffer.isBuffer(buf)) {
7+
throw new TypeError('Expected a buffer')
8+
}
9+
610
return bindings.detectEncoding(buf)
711
}

test.js

+6
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ test('detects ASCII', t => {
1010
const buf = Buffer.from('tést', 'ascii')
1111
t.is(ced(buf), 'ASCII')
1212
})
13+
14+
test('throws a TypeError if the argument is not a buffer', t => {
15+
t.throws(() => {
16+
ced('tést')
17+
}, TypeError)
18+
})

0 commit comments

Comments
 (0)