source: imaps-frontend/node_modules/get-symbol-description/index.js@ 79a0317

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.5 KB
Line 
1'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4
5var callBound = require('call-bound');
6
7var $SyntaxError = require('es-errors/syntax');
8var getGlobalSymbolDescription = GetIntrinsic('%Symbol.keyFor%', true);
9/** @type {undefined | ((thisArg: symbol | Symbol) => symbol)} */
10var thisSymbolValue = callBound('%Symbol.prototype.valueOf%', true);
11/** @type {undefined | ((thisArg: symbol | Symbol) => string)} */
12var symToStr = callBound('Symbol.prototype.toString', true);
13/** @type {(thisArg: string, start?: number, end?: number) => string} */
14var $strSlice = callBound('String.prototype.slice');
15
16var getInferredName = require('./getInferredName');
17
18/** @type {import('.')} */
19/* eslint-disable consistent-return */
20module.exports = callBound('%Symbol.prototype.description%', true) || function getSymbolDescription(symbol) {
21 if (!thisSymbolValue) {
22 throw new $SyntaxError('Symbols are not supported in this environment');
23 }
24
25 // will throw if not a symbol primitive or wrapper object
26 var sym = thisSymbolValue(symbol);
27
28 if (getInferredName) {
29 var name = getInferredName(sym);
30 if (name === '') {
31 return;
32 }
33 return name.slice(1, -1); // name.slice('['.length, -']'.length);
34 }
35
36 var desc;
37 if (getGlobalSymbolDescription) {
38 desc = getGlobalSymbolDescription(sym);
39 if (typeof desc === 'string') {
40 return desc;
41 }
42 }
43
44 // eslint-disable-next-line no-extra-parens
45 desc = $strSlice(/** @type {NonNullable<typeof symToStr>} */ (symToStr)(sym), 7, -1); // str.slice('Symbol('.length, -')'.length);
46 if (desc) {
47 return desc;
48 }
49};
Note: See TracBrowser for help on using the repository browser.