main
Last change
on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var callBound = require('call-bound');
|
---|
4 | var $toString = callBound('Object.prototype.toString');
|
---|
5 | var hasSymbols = require('has-symbols')();
|
---|
6 | var safeRegexTest = require('safe-regex-test');
|
---|
7 |
|
---|
8 | if (hasSymbols) {
|
---|
9 | var $symToStr = callBound('Symbol.prototype.toString');
|
---|
10 | var isSymString = safeRegexTest(/^Symbol\(.*\)$/);
|
---|
11 |
|
---|
12 | /** @type {(value: object) => value is Symbol} */
|
---|
13 | var isSymbolObject = function isRealSymbolObject(value) {
|
---|
14 | if (typeof value.valueOf() !== 'symbol') {
|
---|
15 | return false;
|
---|
16 | }
|
---|
17 | return isSymString($symToStr(value));
|
---|
18 | };
|
---|
19 |
|
---|
20 | /** @type {import('.')} */
|
---|
21 | module.exports = function isSymbol(value) {
|
---|
22 | if (typeof value === 'symbol') {
|
---|
23 | return true;
|
---|
24 | }
|
---|
25 | if (!value || typeof value !== 'object' || $toString(value) !== '[object Symbol]') {
|
---|
26 | return false;
|
---|
27 | }
|
---|
28 | try {
|
---|
29 | return isSymbolObject(value);
|
---|
30 | } catch (e) {
|
---|
31 | return false;
|
---|
32 | }
|
---|
33 | };
|
---|
34 | } else {
|
---|
35 | /** @type {import('.')} */
|
---|
36 | module.exports = function isSymbol(value) {
|
---|
37 | // this environment does not support Symbols.
|
---|
38 | return false && value;
|
---|
39 | };
|
---|
40 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.