kind-of
Get the native type of a value.
Install
Install with npm:
Install
Install with bower
Usage
es5, browser and es6 ready
Benchmarks
Benchmarked against typeof and type-of. Note that performaces is slower for es6 features Map
, WeakMap
, Set
and WeakSet
.
Optimizations
In 7 out of 8 cases, this library is 2x-10x faster than other top libraries included in the benchmarks. There are a few things that lead to this performance advantage, none of them hard and fast rules, but all of them simple and repeatable in almost any code library:
Optimize around the fastest and most common use cases first. Of course, this will change from project-to-project, but I took some time to understand how and why
typeof
checks were being used in my own libraries and other libraries I use a lot.Optimize around bottlenecks - In other words, the order in which conditionals are implemented is significant, because each check is only as fast as the failing checks that came before it. Here, the biggest bottleneck by far is checking for plain objects (an object that was created by the
Object
constructor). I opted to make this check happen by process of elimination rather than brute force up front (e.g. by using something likeval.constructor.name
), so that every other type check would not be penalized it.Don't do uneccessary processing - why do
.slice(8, -1).toLowerCase();
just to get the wordregex
? It's much faster to doif (type === '[object RegExp]') return 'regex'
About
Related projects
is-primitive: Returns
true
if the value is a primitive. | homepage
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Contributors
Building docs
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
Running tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
Author
Jon Schlinkert
License
Copyright © 2017, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on May 16, 2017.
Last updated