Every object has a toString() method that is automatically called when the object is to be represented as a text value or when an object is referred to in a manner in which a string is expected.
By default, the toString() method is inherited by every object descended from Object. If this method is not overridden in a custom object, toString() returns "[object type]", where type is the object type. The following code illustrates this:
Although using toString() in this way is unreliable, as objects can change the behavior of Object.prototype.toString() this library might be helpful when you need to compare objects' tags inside a procedure call or if you just need a quick reference.
moatorres/typetags
TypeTags
String Representations of Node.js Built-in Objects
This package contains a list of default string representations of built-in objects and types of Node.js — see the full list here.
Features
d.ts
filesInstall
NPM
Yarn
Usage
In the examples below
console.log
andtoString
calls are not shown.The
TypeTags
object contains a set of properties, methods and predicates, each representing an object type.The library exports a single object
TypeTags
.We can use it to check if an object's type tag matches the default tag of a data type.
Bundles
esm
cjs
umd
Using
TypeTags
to detect Object ClassEvery object has a
toString()
method that is automatically called when the object is to be represented as a text value or when an object is referred to in a manner in which a string is expected.By default, the
toString()
method is inherited by every object descended fromObject
. If this method is not overridden in a custom object,toString()
returns "[object type]
", wheretype
is the object type. The following code illustrates this:Although using
toString()
in this way is unreliable, as objects can change the behavior ofObject.prototype.toString()
this library might be helpful when you need to compare objects' tags inside a procedure call or if you just need a quick reference.Tests
jest --coverage
TypeScript
Using TypeScript? We've got you covered. Check out our
d.ts
declaration files.< >
with