33
44'use strict' ;
55
6- var isBuffer = require ( './isBuffer' ) ;
7-
86var isArgumentsObject = require ( 'is-arguments' ) ;
97var isGeneratorFunction = require ( 'is-generator-function' ) ;
8+ var whichTypedArray = require ( 'which-typed-array' ) ;
9+ var isTypedArray = require ( 'is-typed-array' ) ;
1010
1111function uncurryThis ( f ) {
1212 return f . call . bind ( f ) ;
1313}
1414
1515var BigIntSupported = typeof BigInt !== 'undefined' ;
1616var 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- }
3017
3118var ObjectToString = uncurryThis ( Object . prototype . toString ) ;
3219
@@ -55,8 +42,8 @@ function checkBoxedPrimitive(value, prototypeValueOf) {
5542}
5643
5744exports . isArgumentsObject = isArgumentsObject ;
58-
5945exports . isGeneratorFunction = isGeneratorFunction ;
46+ exports . isTypedArray = isTypedArray ;
6047
6148// Taken from here and modified for better browser support
6249// https://github.com/sindresorhus/p-is-promise/blob/cda35a513bda03f977ad5cde3a079d237e82d7ef/index.js
@@ -77,7 +64,7 @@ function isPromise(input) {
7764exports . isPromise = isPromise ;
7865
7966function isArrayBufferView ( value ) {
80- if ( ArrayBufferSupported && ArrayBuffer . isView ) {
67+ if ( typeof ArrayBuffer !== 'undefined' && ArrayBuffer . isView ) {
8168 return ArrayBuffer . isView ( value ) ;
8269 }
8370
@@ -88,129 +75,59 @@ function isArrayBufferView(value) {
8875}
8976exports . isArrayBufferView = isArrayBufferView ;
9077
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 ;
11178
11279function 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' ;
12481}
12582exports . isUint8Array = isUint8Array ;
12683
12784function 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' ;
13386}
13487exports . isUint8ClampedArray = isUint8ClampedArray ;
13588
13689function 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' ;
14291}
14392exports . isUint16Array = isUint16Array ;
14493
14594function 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' ;
15196}
15297exports . isUint32Array = isUint32Array ;
15398
15499function 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' ;
160101}
161102exports . isInt8Array = isInt8Array ;
162103
163104function 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' ;
169106}
170107exports . isInt16Array = isInt16Array ;
171108
172109function 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' ;
178111}
179112exports . isInt32Array = isInt32Array ;
180113
181114function 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' ;
187116}
188117exports . isFloat32Array = isFloat32Array ;
189118
190119function 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' ;
196121}
197122exports . isFloat64Array = isFloat64Array ;
198123
199124function 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' ;
205126}
206127exports . isBigInt64Array = isBigInt64Array ;
207128
208129function 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' ;
214131}
215132exports . isBigUint64Array = isBigUint64Array ;
216133
@@ -278,13 +195,6 @@ isWeakSetToString.working = (
278195) ;
279196function isWeakSet ( value ) {
280197 return isWeakSetToString ( value ) ;
281- if ( typeof WeakSet === 'undefined' ) {
282- return false ;
283- }
284-
285- return isWeakSetToString . working
286- ? isWeakSetToString ( value )
287- : value instanceof WeakSet ;
288198}
289199exports . isWeakSet = isWeakSet ;
290200
@@ -405,7 +315,7 @@ function isBoxedPrimitive(value) {
405315exports . isBoxedPrimitive = isBoxedPrimitive ;
406316
407317function isAnyArrayBuffer ( value ) {
408- return Uint8ArraySupported && (
318+ return typeof Uint8Array !== 'undefined' && (
409319 isArrayBuffer ( value ) ||
410320 isSharedArrayBuffer ( value )
411321 ) ;
0 commit comments