sfcode
An Online Competing and Development Environment
|
Contributing
Get the native type of a value.
Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.
Install with npm:
Install with bower
es5, es6, and browser ready
Benchmarked against typeof and type-of.
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:
typeof
checks were being used in my own libraries and other libraries I use a lot.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..slice(8, -1).toLowerCase();
just to get the word regex
? It's much faster to do ‘if (type === ’[object RegExp]') return 'regex'
There is no reason to make the code in a microlib as terse as possible, just to win points for making it shorter. It's always better to favor performant code over terse code. You will always only be using a single
require()` statement to use the library anyway, regardless of how the code is written.kind-of seems to be more consistently "correct" than other type checking libs I've looked at. For example, here are some differing results from other popular libs:
Incorrectly identifies instances of custom constructors (pretty common):
Returns object
instead of arguments
:
Incorrectly returns object
for generator functions, buffers, Map
, Set
, WeakMap
and WeakSet
:
<details>
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
</details>
<details>
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:
</details>
<details>
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:
</details>
You might also be interested in these projects:
true
if the given string looks like a glob pattern or an extglob pattern… more | homepagetrue
if the value is a primitive. | homepageCommits | Contributor |
---|---|
102 | jonschlinkert |
3 | aretecode |
2 | miguelmota |
1 | doowb |
1 | dtothefp |
1 | ianstormtaylor |
1 | ksheedlo |
1 | pdehaan |
1 | laggingreflex |
1 | tunnckoCore |
1 | xiaofen9 |
Jon Schlinkert
Copyright © 2020, Jon Schlinkert. Released under the [MIT License](LICENSE).
This file was generated by verb-generate-readme, v0.8.0, on January 16, 2020.