has-tostringtag
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
has-symbols | 1.0.3 | 6.9 kB | MIT | prod |
"has-tostringtag" is a JavaScript utility function that helps developers identify if the JavaScript environment they are working in supports Symbol.toStringTag
. The Symbol.toStringTag
feature is critical in defining a user-defined string value in a JavaScript object's default description. The acknowledgement of a valid Symbol.toStringTag
support ensures functions like Object.prototype.toString
can provide expected results. It can identify both spec-compliant symbols and shams (pseudo implementations).
You can use "has-tostringtag" package easily in your JavaScript project. To get started, first install the has-tostringtag
package with npm by running npm install has-tostringtag
. Once the package is installed, you can require it in your JavaScript file and use it as shown in the following code sample:
var hasSymbolToStringTag = require('has-tostringtag');
// to check if the environment has native Symbol.toStringTag support
if(hasSymbolToStringTag() === true) {
// Your code here if the environment supports Symbol.toStringTag
} else {
// Your code here if the environment does not support Symbol.toStringTag
}
// For checking the support of Symbol.toStringTag sham
var hasSymbolToStringTagKinda = require('has-tostringtag/shams');
if(hasSymbolToStringTagKinda() === true) {
// Your code here if the environment supports a Symbol.toStringTag sham
} else {
// Your code here if the environment does not support a Symbol.toStringTag sham
}
Please note that "has-tostringtag" provides two kinds of checks: one for the native Symbol.toStringTag
support which is not poly-fillable, not forgeable, and another for Symbol.toStringTag
sham that mostly follows the spec.
The "has-tostringtag" documentation can be found in the README of the npm package page here. The README provides an overview of the package's purpose, an example of how to use it, and information on supported Symbol shams. It also gives a brief guide on how to launch tests if required. For more robust information regarding the JavaScript Symbol.toStringTag
property, developers can refer to the ECMAScript specification as well as the comprehensive documentation provided by Mozilla Developer Network (MDN).