diff --git a/from.js b/from.js index a8919bb..0f493c6 100644 --- a/from.js +++ b/from.js @@ -1,7 +1,9 @@ const {statSync, createReadStream} = require('fs'); -const Blob = require('./index.js'); const DOMException = require('domexception'); +// eslint-disable-next-line unicorn/import-index +const Blob = require('./index.js'); + /** * @param {string} path filepath on the disk * @returns {Blob} @@ -27,7 +29,7 @@ class BlobDataItem { this.mtime = options.mtime; } - // Slicing arguments is first validated and formated + // Slicing arguments is first validated and formated // to not be out of range by Blob.prototype.slice slice(start, end) { return new BlobDataItem({ diff --git a/index.js b/index.js index 403eca4..2569e03 100644 --- a/index.js +++ b/index.js @@ -160,6 +160,7 @@ class Blob { static [Symbol.hasInstance](object) { return ( + object && typeof object === 'object' && typeof object.stream === 'function' && object.stream.length === 0 && diff --git a/test.js b/test.js index 3a7b23b..d188ba0 100644 --- a/test.js +++ b/test.js @@ -160,3 +160,19 @@ test('Reading after modified should fail', async t => { const error = await blob.text().catch(error => error); t.is(error.name, 'NotReadableError'); }); + +test('Blob-ish class is an instance of Blob', t => { + class File { + stream() { } + + get [Symbol.toStringTag]() { + return 'File'; + } + } + + t.true(new File() instanceof Blob); +}); + +test('Instanceof check returns false for nullish values', t => { + t.false(null instanceof Blob); +});