File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -8,13 +8,26 @@ function isError(obj) { return toS(obj) === '[object Error]'; }
8
8
function isBoolean ( obj ) { return toS ( obj ) === '[object Boolean]' ; }
9
9
function isNumber ( obj ) { return toS ( obj ) === '[object Number]' ; }
10
10
function isString ( obj ) { return toS ( obj ) === '[object String]' ; }
11
- function isBuffer ( obj ) { return typeof Buffer !== 'undefined' && typeof Buffer . isBuffer === 'function' && Buffer . isBuffer ( obj ) ; }
12
11
13
12
// TODO: use isarray
14
13
var isArray = Array . isArray || function isArray ( xs ) {
15
14
return Object . prototype . toString . call ( xs ) === '[object Array]' ;
16
15
} ;
17
16
17
+ function isBuffer ( x ) {
18
+ if ( ! x || typeof x !== 'object' || typeof x . length !== 'number' ) {
19
+ return false ;
20
+ }
21
+ if ( typeof x . copy !== 'function' || typeof x . slice !== 'function' ) {
22
+ return false ;
23
+ }
24
+ if ( x . length > 0 && typeof x [ 0 ] !== 'number' ) {
25
+ return false ;
26
+ }
27
+
28
+ return ! ! ( x . constructor && x . constructor . isBuffer && x . constructor . isBuffer ( x ) ) ;
29
+ }
30
+
18
31
// TODO: use for-each?
19
32
function forEach ( xs , fn ) {
20
33
if ( xs . forEach ) { return xs . forEach ( fn ) ; }
You can’t perform that action at this time.
0 commit comments