Skip to content

Commit 60187f6

Browse files
authored
Merge branch 'master' into octet-stream/add-from-blob-typings
2 parents ead4eb3 + eed6a1d commit 60187f6

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

from.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
const {statSync, createReadStream} = require('fs');
2-
const Blob = require('.');
2+
const Blob = require('./index.js');
33
const DOMException = require('domexception');
44

5+
// eslint-disable-next-line unicorn/import-index
6+
const Blob = require('./index.js');
7+
58
/**
69
* @param {string} path filepath on the disk
710
* @returns {Blob}

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ class Blob {
160160

161161
static [Symbol.hasInstance](object) {
162162
return (
163+
object &&
163164
typeof object === 'object' &&
164165
typeof object.stream === 'function' &&
165166
object.stream.length === 0 &&

test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,19 @@ test('Reading after modified should fail', async t => {
160160
const error = await blob.text().catch(error => error);
161161
t.is(error.name, 'NotReadableError');
162162
});
163+
164+
test('Blob-ish class is an instance of Blob', t => {
165+
class File {
166+
stream() { }
167+
168+
get [Symbol.toStringTag]() {
169+
return 'File';
170+
}
171+
}
172+
173+
t.true(new File() instanceof Blob);
174+
});
175+
176+
test('Instanceof check returns false for nullish values', t => {
177+
t.false(null instanceof Blob);
178+
});

0 commit comments

Comments
 (0)