prototypeof
v1.0.0
Published
š Simply get the type of an object.
Downloads
4
Readme
prototypeof
š Simply get the type of an object.
prototypeof is a simple function to get the type of an object by
using Object.prototype.toString
on any given object. Usually, this
is always the best way to guess the type of an object since typeof
may return things not expected (Array
and Null
are considered
object
).
Furthermore, even when using Object.prototype.toString
, thereās no
easy way to make custom types names. Thatās why I created
prototypeof
.
The name may look misleading (weāre not actually getting the prototype), but is etymologically correct. Which corresponds to ĻĻĻĻĪæ- (prÅto-) (most recent ancestor) and type.
Getting Started
const prototypeof = require('prototypeof');
class Type {
constructor() {
}
}
var type = new Type();
console.log(prototypeof(type)); // "Object"
console.log(prototypeof(Type, 'Type')); // "Type"
console.log(prototypeof(type)); // "Type"
JavaScript API
prototypeof ( object[, type])
Get the type of an object and optionally set its type. If the object has a prototype, set the prototypal type. Finally return the type name.
object
: Any objects or primitives.type
: Optional. If truthy, set the type name.- Return: A type name as a
String
.
License
This module and the whole directory is subject to the MIT license.
I usually prefer the GPL license, but I donāt think itās big enough care for that (and scare people like you).
Copyright (c) 2017 Etienne Prudāhomme