3
3
4
4
'use strict' ;
5
5
6
- var isBuffer = require ( './isBuffer' ) ;
7
-
8
6
var isArgumentsObject = require ( 'is-arguments' ) ;
9
7
var isGeneratorFunction = require ( 'is-generator-function' ) ;
8
+ var whichTypedArray = require ( 'which-typed-array' ) ;
9
+ var isTypedArray = require ( 'is-typed-array' ) ;
10
10
11
11
function uncurryThis ( f ) {
12
12
return f . call . bind ( f ) ;
13
13
}
14
14
15
15
var BigIntSupported = typeof BigInt !== 'undefined' ;
16
16
var SymbolSupported = typeof Symbol !== 'undefined' ;
17
- var SymbolToStringTagSupported = SymbolSupported && typeof Symbol . toStringTag !== 'undefined' ;
18
- var Uint8ArraySupported = typeof Uint8Array !== 'undefined' ;
19
- var ArrayBufferSupported = typeof ArrayBuffer !== 'undefined' ;
20
-
21
- if ( Uint8ArraySupported && SymbolToStringTagSupported ) {
22
- var TypedArrayPrototype = Object . getPrototypeOf ( Uint8Array . prototype ) ;
23
-
24
- var TypedArrayProto_toStringTag =
25
- uncurryThis (
26
- Object . getOwnPropertyDescriptor ( TypedArrayPrototype ,
27
- Symbol . toStringTag ) . get ) ;
28
-
29
- }
30
17
31
18
var ObjectToString = uncurryThis ( Object . prototype . toString ) ;
32
19
@@ -55,8 +42,8 @@ function checkBoxedPrimitive(value, prototypeValueOf) {
55
42
}
56
43
57
44
exports . isArgumentsObject = isArgumentsObject ;
58
-
59
45
exports . isGeneratorFunction = isGeneratorFunction ;
46
+ exports . isTypedArray = isTypedArray ;
60
47
61
48
// Taken from here and modified for better browser support
62
49
// https://github.com/sindresorhus/p-is-promise/blob/cda35a513bda03f977ad5cde3a079d237e82d7ef/index.js
@@ -77,7 +64,7 @@ function isPromise(input) {
77
64
exports . isPromise = isPromise ;
78
65
79
66
function isArrayBufferView ( value ) {
80
- if ( ArrayBufferSupported && ArrayBuffer . isView ) {
67
+ if ( typeof ArrayBuffer !== 'undefined' && ArrayBuffer . isView ) {
81
68
return ArrayBuffer . isView ( value ) ;
82
69
}
83
70
@@ -88,129 +75,59 @@ function isArrayBufferView(value) {
88
75
}
89
76
exports . isArrayBufferView = isArrayBufferView ;
90
77
91
- function isTypedArray ( value ) {
92
- if ( Uint8ArraySupported && SymbolToStringTagSupported ) {
93
- return TypedArrayProto_toStringTag ( value ) !== undefined ;
94
- } else {
95
- return (
96
- isUint8Array ( value ) ||
97
- isUint8ClampedArray ( value ) ||
98
- isUint16Array ( value ) ||
99
- isUint32Array ( value ) ||
100
- isInt8Array ( value ) ||
101
- isInt16Array ( value ) ||
102
- isInt32Array ( value ) ||
103
- isFloat32Array ( value ) ||
104
- isFloat64Array ( value ) ||
105
- isBigInt64Array ( value ) ||
106
- isBigUint64Array ( value )
107
- ) ;
108
- }
109
- }
110
- exports . isTypedArray = isTypedArray ;
111
78
112
79
function isUint8Array ( value ) {
113
- if ( Uint8ArraySupported && SymbolToStringTagSupported ) {
114
- return TypedArrayProto_toStringTag ( value ) === 'Uint8Array' ;
115
- } else {
116
- return (
117
- ObjectToString ( value ) === '[object Uint8Array]' ||
118
- // If it's a Buffer instance _and_ has a `.buffer` property,
119
- // this is an ArrayBuffer based buffer; thus it's an Uint8Array
120
- // (Old Node.js had a custom non-Uint8Array implementation)
121
- isBuffer ( value ) && value . buffer !== undefined
122
- ) ;
123
- }
80
+ return whichTypedArray ( value ) === 'Uint8Array' ;
124
81
}
125
82
exports . isUint8Array = isUint8Array ;
126
83
127
84
function isUint8ClampedArray ( value ) {
128
- if ( Uint8ArraySupported && SymbolToStringTagSupported ) {
129
- return TypedArrayProto_toStringTag ( value ) === 'Uint8ClampedArray' ;
130
- } else {
131
- return ObjectToString ( value ) === '[object Uint8ClampedArray]' ;
132
- }
85
+ return whichTypedArray ( value ) === 'Uint8ClampedArray' ;
133
86
}
134
87
exports . isUint8ClampedArray = isUint8ClampedArray ;
135
88
136
89
function isUint16Array ( value ) {
137
- if ( Uint8ArraySupported && SymbolToStringTagSupported ) {
138
- return TypedArrayProto_toStringTag ( value ) === 'Uint16Array' ;
139
- } else {
140
- return ObjectToString ( value ) === '[object Uint16Array]' ;
141
- }
90
+ return whichTypedArray ( value ) === 'Uint16Array' ;
142
91
}
143
92
exports . isUint16Array = isUint16Array ;
144
93
145
94
function isUint32Array ( value ) {
146
- if ( Uint8ArraySupported && SymbolToStringTagSupported ) {
147
- return TypedArrayProto_toStringTag ( value ) === 'Uint32Array' ;
148
- } else {
149
- return ObjectToString ( value ) === '[object Uint32Array]' ;
150
- }
95
+ return whichTypedArray ( value ) === 'Uint32Array' ;
151
96
}
152
97
exports . isUint32Array = isUint32Array ;
153
98
154
99
function isInt8Array ( value ) {
155
- if ( Uint8ArraySupported && SymbolToStringTagSupported ) {
156
- return TypedArrayProto_toStringTag ( value ) === 'Int8Array' ;
157
- } else {
158
- return ObjectToString ( value ) === '[object Int8Array]' ;
159
- }
100
+ return whichTypedArray ( value ) === 'Int8Array' ;
160
101
}
161
102
exports . isInt8Array = isInt8Array ;
162
103
163
104
function isInt16Array ( value ) {
164
- if ( Uint8ArraySupported && SymbolToStringTagSupported ) {
165
- return TypedArrayProto_toStringTag ( value ) === 'Int16Array' ;
166
- } else {
167
- return ObjectToString ( value ) === '[object Int16Array]' ;
168
- }
105
+ return whichTypedArray ( value ) === 'Int16Array' ;
169
106
}
170
107
exports . isInt16Array = isInt16Array ;
171
108
172
109
function isInt32Array ( value ) {
173
- if ( Uint8ArraySupported && SymbolToStringTagSupported ) {
174
- return TypedArrayProto_toStringTag ( value ) === 'Int32Array' ;
175
- } else {
176
- return ObjectToString ( value ) === '[object Int32Array]' ;
177
- }
110
+ return whichTypedArray ( value ) === 'Int32Array' ;
178
111
}
179
112
exports . isInt32Array = isInt32Array ;
180
113
181
114
function isFloat32Array ( value ) {
182
- if ( Uint8ArraySupported && SymbolToStringTagSupported ) {
183
- return TypedArrayProto_toStringTag ( value ) === 'Float32Array' ;
184
- } else {
185
- return ObjectToString ( value ) === '[object Float32Array]' ;
186
- }
115
+ return whichTypedArray ( value ) === 'Float32Array' ;
187
116
}
188
117
exports . isFloat32Array = isFloat32Array ;
189
118
190
119
function isFloat64Array ( value ) {
191
- if ( Uint8ArraySupported && SymbolToStringTagSupported ) {
192
- return TypedArrayProto_toStringTag ( value ) === 'Float64Array' ;
193
- } else {
194
- return ObjectToString ( value ) === '[object Float64Array]' ;
195
- }
120
+ return whichTypedArray ( value ) === 'Float64Array' ;
196
121
}
197
122
exports . isFloat64Array = isFloat64Array ;
198
123
199
124
function isBigInt64Array ( value ) {
200
- if ( Uint8ArraySupported && SymbolToStringTagSupported ) {
201
- return TypedArrayProto_toStringTag ( value ) === 'BigInt64Array' ;
202
- } else {
203
- return ObjectToString ( value ) === '[object BigInt64Array]' ;
204
- }
125
+ return whichTypedArray ( value ) === 'BigInt64Array' ;
205
126
}
206
127
exports . isBigInt64Array = isBigInt64Array ;
207
128
208
129
function isBigUint64Array ( value ) {
209
- if ( Uint8ArraySupported && SymbolToStringTagSupported ) {
210
- return TypedArrayProto_toStringTag ( value ) === 'BigUint64Array' ;
211
- } else {
212
- return ObjectToString ( value ) === '[object BigUint64Array]' ;
213
- }
130
+ return whichTypedArray ( value ) === 'BigUint64Array' ;
214
131
}
215
132
exports . isBigUint64Array = isBigUint64Array ;
216
133
@@ -405,7 +322,7 @@ function isBoxedPrimitive(value) {
405
322
exports . isBoxedPrimitive = isBoxedPrimitive ;
406
323
407
324
function isAnyArrayBuffer ( value ) {
408
- return Uint8ArraySupported && (
325
+ return typeof Uint8Array !== 'undefined' && (
409
326
isArrayBuffer ( value ) ||
410
327
isSharedArrayBuffer ( value )
411
328
) ;
0 commit comments