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
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
[79a0317] | 3 | var callBound = require('call-bound');
|
---|
| 4 | var $toString = callBound('Object.prototype.toString');
|
---|
[d565449] | 5 | var hasSymbols = require('has-symbols')();
|
---|
[79a0317] | 6 | var safeRegexTest = require('safe-regex-test');
|
---|
[d565449] | 7 |
|
---|
| 8 | if (hasSymbols) {
|
---|
[79a0317] | 9 | var $symToStr = callBound('Symbol.prototype.toString');
|
---|
| 10 | var isSymString = safeRegexTest(/^Symbol\(.*\)$/);
|
---|
| 11 |
|
---|
| 12 | /** @type {(value: object) => value is Symbol} */
|
---|
[d565449] | 13 | var isSymbolObject = function isRealSymbolObject(value) {
|
---|
| 14 | if (typeof value.valueOf() !== 'symbol') {
|
---|
| 15 | return false;
|
---|
| 16 | }
|
---|
[79a0317] | 17 | return isSymString($symToStr(value));
|
---|
[d565449] | 18 | };
|
---|
| 19 |
|
---|
[79a0317] | 20 | /** @type {import('.')} */
|
---|
[d565449] | 21 | module.exports = function isSymbol(value) {
|
---|
| 22 | if (typeof value === 'symbol') {
|
---|
| 23 | return true;
|
---|
| 24 | }
|
---|
[79a0317] | 25 | if (!value || typeof value !== 'object' || $toString(value) !== '[object Symbol]') {
|
---|
[d565449] | 26 | return false;
|
---|
| 27 | }
|
---|
| 28 | try {
|
---|
| 29 | return isSymbolObject(value);
|
---|
| 30 | } catch (e) {
|
---|
| 31 | return false;
|
---|
| 32 | }
|
---|
| 33 | };
|
---|
| 34 | } else {
|
---|
[79a0317] | 35 | /** @type {import('.')} */
|
---|
[d565449] | 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.