UNPKG

@feugene/mu

Version:

Helpful TS utilities without dependencies

46 lines 1.52 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = getRawTag; const root_1 = __importDefault(require("./root")); /** Built-in value references. */ const symToStringTag = root_1.default.Symbol ? root_1.default.Symbol.toStringTag : undefined; /** Used for built-in method references. */ const objectProto = Object.prototype; /** Used to check objects for own properties. */ const hasOwnProperty = objectProto.hasOwnProperty; /** * Used to resolve the * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) * of values. */ const nativeObjectToString = objectProto.toString; /** * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values. * * @private * @param {*} value The value to query. * @returns {string} Returns the raw `toStringTag`. */ function getRawTag(value) { const isOwn = hasOwnProperty.call(value, symToStringTag), tag = value[symToStringTag]; let unmasked = false; try { value[symToStringTag] = undefined; unmasked = true; } catch (error) { } const result = nativeObjectToString.call(value); if (unmasked) { if (isOwn) { value[symToStringTag] = tag; } else { delete value[symToStringTag]; } } return result; } //# sourceMappingURL=getRawTag.js.map