Skip to content

Commit ea8a542

Browse files
committed
#247: fixed isFile/isBlob methods
1 parent 5864500 commit ea8a542

File tree

5 files changed

+39
-15
lines changed

5 files changed

+39
-15
lines changed

dist/FileAPI.html5.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@
135135
_rinput = /input/i,
136136
_rdata = /^data:[^,]+,/,
137137

138+
_toString = {}.toString,
139+
138140

139141
Math = window.Math,
140142

@@ -556,19 +558,25 @@
556558

557559

558560
/**
559-
* Is file instance
560-
*
561+
* Is file?
561562
* @param {File} file
562563
* @return {Boolean}
563564
*/
564565
isFile: function (file){
565-
returnhtml5 && file && (file instanceof File);
566+
return _toString.call(file) === '[object File]';
566567
},
567568

569+
570+
/**
571+
* Is blob?
572+
* @param {Blob} blob
573+
* @returns {Boolean}
574+
*/
568575
isBlob: function (blob) {
569-
return html5 && blob && (blob instanceof Blob);
576+
return this.isFile(blob) || (_toString.call(blob) === '[object Blob]');
570577
},
571578

579+
572580
/**
573581
* Is canvas element
574582
*

dist/FileAPI.html5.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/FileAPI.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@
135135
_rinput = /input/i,
136136
_rdata = /^data:[^,]+,/,
137137

138+
_toString = {}.toString,
139+
138140

139141
Math = window.Math,
140142

@@ -556,19 +558,25 @@
556558

557559

558560
/**
559-
* Is file instance
560-
*
561+
* Is file?
561562
* @param {File} file
562563
* @return {Boolean}
563564
*/
564565
isFile: function (file){
565-
returnhtml5 && file && (file instanceof File);
566+
return _toString.call(file) === '[object File]';
566567
},
567568

569+
570+
/**
571+
* Is blob?
572+
* @param {Blob} blob
573+
* @returns {Boolean}
574+
*/
568575
isBlob: function (blob) {
569-
return html5 && blob && (blob instanceof Blob);
576+
return this.isFile(blob) || (_toString.call(blob) === '[object Blob]');
570577
},
571578

579+
572580
/**
573581
* Is canvas element
574582
*

dist/FileAPI.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/FileAPI.core.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
_rinput = /input/i,
4242
_rdata = /^data:[^,]+,/,
4343

44+
_toString = {}.toString,
45+
4446

4547
Math = window.Math,
4648

@@ -462,19 +464,25 @@
462464

463465

464466
/**
465-
* Is file instance
466-
*
467+
* Is file?
467468
* @param {File} file
468469
* @return {Boolean}
469470
*/
470471
isFile: function (file){
471-
returnhtml5 && file && (file instanceof File);
472+
return _toString.call(file) === '[object File]';
472473
},
473474

475+
476+
/**
477+
* Is blob?
478+
* @param {Blob} blob
479+
* @returns {Boolean}
480+
*/
474481
isBlob: function (blob) {
475-
return html5 && blob && (blob instanceof Blob);
482+
return this.isFile(blob) || (_toString.call(blob) === '[object Blob]');
476483
},
477484

485+
478486
/**
479487
* Is canvas element
480488
*

0 commit comments

Comments
 (0)