@@ -6,6 +6,7 @@ var callBind = require('call-bind');
6
6
var callBound = require ( 'call-bind/callBound' ) ;
7
7
var gOPD = require ( 'gopd' ) ;
8
8
9
+ /** @type {(O: object) => string } */
9
10
var $toString = callBound ( 'Object.prototype.toString' ) ;
10
11
var hasToStringTag = require ( 'has-tostringtag/shams' ) ( ) ;
11
12
@@ -15,7 +16,8 @@ var typedArrays = availableTypedArrays();
15
16
var $slice = callBound ( 'String.prototype.slice' ) ;
16
17
var getPrototypeOf = Object . getPrototypeOf ; // require('getprototypeof');
17
18
18
- var $indexOf = callBound ( 'Array.prototype.indexOf' , true ) || /** @type {(array: readonly unknown[], value: unknown) => keyof array } */ function indexOf ( array , value ) {
19
+ /** @type {<T = unknown>(array: readonly T[], value: unknown) => number } */
20
+ var $indexOf = callBound ( 'Array.prototype.indexOf' , true ) || function indexOf ( array , value ) {
19
21
for ( var i = 0 ; i < array . length ; i += 1 ) {
20
22
if ( array [ i ] === value ) {
21
23
return i ;
@@ -24,9 +26,8 @@ var $indexOf = callBound('Array.prototype.indexOf', true) || /** @type {(array:
24
26
return - 1 ;
25
27
} ;
26
28
27
- /** @typedef {Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array } TypedArray */
28
- /** @typedef {'Int8Array' | 'Uint8Array' | 'Uint8ClampedArray' | 'Int16Array' | 'Uint16Array' | 'Int32Array' | 'Uint32Array' | 'Float32Array' | 'Float64Array' | 'BigInt64Array' | 'BigUint64Array' } TypedArrayName */
29
- /** @type {{ [k in `\$${TypedArrayName}`]?: (receiver: TypedArray) => string | typeof Uint8Array.prototype.slice.call | typeof Uint8Array.prototype.set.call } & { __proto__: null } } */
29
+ /** @typedef {(receiver: import('.').TypedArray) => string | typeof Uint8Array.prototype.slice.call | typeof Uint8Array.prototype.set.call } Getter */
30
+ /** @type {{ [k in `\$${import('.').TypedArrayName}`]?: Getter } & { __proto__: null } } */
30
31
var cache = { __proto__ : null } ;
31
32
if ( hasToStringTag && gOPD && getPrototypeOf ) {
32
33
forEach ( typedArrays , function ( typedArray ) {
@@ -55,13 +56,14 @@ if (hasToStringTag && gOPD && getPrototypeOf) {
55
56
} ) ;
56
57
}
57
58
58
- /** @type {import('.') } */
59
+ /** @type {(value: object) => false | import('.').TypedArrayName } */
59
60
var tryTypedArrays = function tryAllTypedArrays ( value ) {
60
- /** @type {ReturnType<tryAllTypedArrays> } */ var found = false ;
61
+ /** @type {ReturnType<typeof tryAllTypedArrays> } */ var found = false ;
61
62
forEach (
62
63
// eslint-disable-next-line no-extra-parens
63
- /** @type {Record<`\$${TypedArrayName}`, typeof cache> } */ /** @type {any } */ ( cache ) ,
64
- /** @type {(getter: typeof cache, name: `\$${TypedArrayName}`) => void } */ function ( getter , typedArray ) {
64
+ /** @type {Record<`\$${TypedArrayName}`, Getter> } */ /** @type {any } */ ( cache ) ,
65
+ /** @type {(getter: Getter, name: `\$${import('.').TypedArrayName}`) => void } */
66
+ function ( getter , typedArray ) {
65
67
if ( ! found ) {
66
68
try {
67
69
// @ts -expect-error TODO: fix
@@ -75,16 +77,16 @@ var tryTypedArrays = function tryAllTypedArrays(value) {
75
77
return found ;
76
78
} ;
77
79
78
- /** @type {import('.') } */
80
+ /** @type {(value: object) => false | import('.').TypedArrayName } */
79
81
var trySlices = function tryAllSlices ( value ) {
80
- /** @type {ReturnType<tryAllSlices> } */ var found = false ;
82
+ /** @type {ReturnType<typeof tryAllSlices> } */ var found = false ;
81
83
forEach (
82
84
// eslint-disable-next-line no-extra-parens
83
- /** @type {any } */ ( cache ) ,
84
- /** @type {(getter: typeof cache, name: `\$${TypedArrayName}`) => void } */ function ( getter , name ) {
85
+ /** @type {Record<`\$${TypedArrayName}`, Getter> } */ /** @type { any } */ ( cache ) ,
86
+ /** @type {(getter: typeof cache, name: `\$${import('.'). TypedArrayName}`) => void } */ function ( getter , name ) {
85
87
if ( ! found ) {
86
88
try {
87
- // @ts -expect-error TODO: fix
89
+ // @ts -expect-error TODO: fix
88
90
getter ( value ) ;
89
91
found = $slice ( name , 1 ) ;
90
92
} catch ( e ) { /**/ }
@@ -98,6 +100,7 @@ var trySlices = function tryAllSlices(value) {
98
100
module . exports = function whichTypedArray ( value ) {
99
101
if ( ! value || typeof value !== 'object' ) { return false ; }
100
102
if ( ! hasToStringTag ) {
103
+ /** @type {string } */
101
104
var tag = $slice ( $toString ( value ) , 8 , - 1 ) ;
102
105
if ( $indexOf ( typedArrays , tag ) > - 1 ) {
103
106
return tag ;
0 commit comments