Benchmarked against and . 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 like val.constructor.name), so that every other type check would not be penalized it.
About
Related projects
: Returns true if the given string looks like a glob pattern or an extglob pattern… |
: Returns true if the value is a number. comprehensive tests. |
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, .
Contributors
Building docs
(This project's readme.md is generated by , please don't edit the readme directly. Any changes to the readme must be made in the 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:
This file was generated by , v0.6.0, on May 16, 2017.
$ npm install --save kind-of
Don't do uneccessary processing - why do .slice(8, -1).toLowerCase(); just to get the word regex? It's much faster to do if (type === '[object RegExp]') return 'regex'