We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8545f46 commit a4d9f10Copy full SHA for a4d9f10
index.js
@@ -3,5 +3,9 @@
3
const bindings = require('bindings')('ced.node')
4
5
module.exports = buf => {
6
+ if (!Buffer.isBuffer(buf)) {
7
+ throw new TypeError('Expected a buffer')
8
+ }
9
+
10
return bindings.detectEncoding(buf)
11
}
test.js
@@ -10,3 +10,9 @@ test('detects ASCII', t => {
const buf = Buffer.from('tést', 'ascii')
t.is(ced(buf), 'ASCII')
12
})
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