-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
44 lines (37 loc) · 1.12 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict';
var hasToStringTag = require('has-tostringtag/shams')();
var callBound = require('call-bound');
var $toString = callBound('Object.prototype.toString');
/** @type {import('.')} */
var isStandardArguments = function isArguments(value) {
if (
hasToStringTag
&& value
&& typeof value === 'object'
&& Symbol.toStringTag in value
) {
return false;
}
return $toString(value) === '[object Arguments]';
};
/** @type {import('.')} */
var isLegacyArguments = function isArguments(value) {
if (isStandardArguments(value)) {
return true;
}
return value !== null
&& typeof value === 'object'
&& 'length' in value
&& typeof value.length === 'number'
&& value.length >= 0
&& $toString(value) !== '[object Array]'
&& 'callee' in value
&& $toString(value.callee) === '[object Function]';
};
var supportsStandardArguments = (function () {
return isStandardArguments(arguments);
}());
// @ts-expect-error TODO make this not error
isStandardArguments.isLegacyArguments = isLegacyArguments; // for tests
/** @type {import('.')} */
module.exports = supportsStandardArguments ? isStandardArguments : isLegacyArguments;