| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 | 
							- 'use strict';
 
- var forEach = require('for-each');
 
- var availableTypedArrays = require('available-typed-arrays');
 
- var callBind = require('call-bind');
 
- var callBound = require('call-bound');
 
- var gOPD = require('gopd');
 
- var getProto = require('get-proto');
 
- var $toString = callBound('Object.prototype.toString');
 
- var hasToStringTag = require('has-tostringtag/shams')();
 
- var g = typeof globalThis === 'undefined' ? global : globalThis;
 
- var typedArrays = availableTypedArrays();
 
- var $slice = callBound('String.prototype.slice');
 
- /** @type {<T = unknown>(array: readonly T[], value: unknown) => number} */
 
- var $indexOf = callBound('Array.prototype.indexOf', true) || function indexOf(array, value) {
 
- 	for (var i = 0; i < array.length; i += 1) {
 
- 		if (array[i] === value) {
 
- 			return i;
 
- 		}
 
- 	}
 
- 	return -1;
 
- };
 
- /** @typedef {import('./types').Getter} Getter */
 
- /** @type {import('./types').Cache} */
 
- var cache = { __proto__: null };
 
- if (hasToStringTag && gOPD && getProto) {
 
- 	forEach(typedArrays, function (typedArray) {
 
- 		var arr = new g[typedArray]();
 
- 		if (Symbol.toStringTag in arr && getProto) {
 
- 			var proto = getProto(arr);
 
- 			// @ts-expect-error TS won't narrow inside a closure
 
- 			var descriptor = gOPD(proto, Symbol.toStringTag);
 
- 			if (!descriptor && proto) {
 
- 				var superProto = getProto(proto);
 
- 				// @ts-expect-error TS won't narrow inside a closure
 
- 				descriptor = gOPD(superProto, Symbol.toStringTag);
 
- 			}
 
- 			// @ts-expect-error TODO: fix
 
- 			cache['$' + typedArray] = callBind(descriptor.get);
 
- 		}
 
- 	});
 
- } else {
 
- 	forEach(typedArrays, function (typedArray) {
 
- 		var arr = new g[typedArray]();
 
- 		var fn = arr.slice || arr.set;
 
- 		if (fn) {
 
- 			cache[
 
- 				/** @type {`$${import('.').TypedArrayName}`} */ ('$' + typedArray)
 
- 			] = /** @type {import('./types').BoundSlice | import('./types').BoundSet} */ (
 
- 				// @ts-expect-error TODO FIXME
 
- 				callBind(fn)
 
- 			);
 
- 		}
 
- 	});
 
- }
 
- /** @type {(value: object) => false | import('.').TypedArrayName} */
 
- var tryTypedArrays = function tryAllTypedArrays(value) {
 
- 	/** @type {ReturnType<typeof tryAllTypedArrays>} */ var found = false;
 
- 	forEach(
 
- 		/** @type {Record<`\$${import('.').TypedArrayName}`, Getter>} */ (cache),
 
- 		/** @type {(getter: Getter, name: `\$${import('.').TypedArrayName}`) => void} */
 
- 		function (getter, typedArray) {
 
- 			if (!found) {
 
- 				try {
 
- 					// @ts-expect-error a throw is fine here
 
- 					if ('$' + getter(value) === typedArray) {
 
- 						found = /** @type {import('.').TypedArrayName} */ ($slice(typedArray, 1));
 
- 					}
 
- 				} catch (e) { /**/ }
 
- 			}
 
- 		}
 
- 	);
 
- 	return found;
 
- };
 
- /** @type {(value: object) => false | import('.').TypedArrayName} */
 
- var trySlices = function tryAllSlices(value) {
 
- 	/** @type {ReturnType<typeof tryAllSlices>} */ var found = false;
 
- 	forEach(
 
- 		/** @type {Record<`\$${import('.').TypedArrayName}`, Getter>} */(cache),
 
- 		/** @type {(getter: Getter, name: `\$${import('.').TypedArrayName}`) => void} */ function (getter, name) {
 
- 			if (!found) {
 
- 				try {
 
- 					// @ts-expect-error a throw is fine here
 
- 					getter(value);
 
- 					found = /** @type {import('.').TypedArrayName} */ ($slice(name, 1));
 
- 				} catch (e) { /**/ }
 
- 			}
 
- 		}
 
- 	);
 
- 	return found;
 
- };
 
- /** @type {import('.')} */
 
- module.exports = function whichTypedArray(value) {
 
- 	if (!value || typeof value !== 'object') { return false; }
 
- 	if (!hasToStringTag) {
 
- 		/** @type {string} */
 
- 		var tag = $slice($toString(value), 8, -1);
 
- 		if ($indexOf(typedArrays, tag) > -1) {
 
- 			return tag;
 
- 		}
 
- 		if (tag !== 'Object') {
 
- 			return false;
 
- 		}
 
- 		// node < 0.6 hits here on real Typed Arrays
 
- 		return trySlices(value);
 
- 	}
 
- 	if (!gOPD) { return null; } // unknown engine
 
- 	return tryTypedArrays(value);
 
- };
 
 
  |