Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/phawk/js-typeof
A better typeOf method for JavaScript, where null !== "object"
https://github.com/phawk/js-typeof
Last synced: 14 days ago
JSON representation
A better typeOf method for JavaScript, where null !== "object"
- Host: GitHub
- URL: https://github.com/phawk/js-typeof
- Owner: phawk
- Created: 2012-09-19T22:53:59.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2013-02-07T21:06:49.000Z (almost 12 years ago)
- Last Synced: 2024-10-25T01:39:30.943Z (2 months ago)
- Language: JavaScript
- Size: 168 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# js typeOf
## typeOf(Object)
JavaScripts typeof operator sucks! This aims to provide an extremely simple method to call to check typeof and should be a little more epectable, and reduce boilerplate on your input checking.
```js
// Rudementary example
if (objectToTest && typeof objectToTest === "object" && objectToTest instanceof Array)// Easier
if (typeOf(objectToTest) === "array")
```## is(Object, "Object")
Used for shorthand comparisons, returns a boolean.
```js
var obj = {};is(obj, "object"); // true
is(obj, "string"); // false
```## Changelog
### v0.3.0
* Switched is("number", 5) to is(5, "number") for better readability.
* Added more resiliant check for null and undefined for odd environments, like phantomJS.### v0.2.0
* Simpler and more accurate calculation using `Object.toString.
* Now with `is()` method for comparisons
* typeOf(new Date()) now equals "date"
* typeOf(new Error()) now equals "error"### v0.1.2
* Massively simplify and optimise
### v0.1.1
* Custom constructors return typeof as `object`
* The only two objects that do return a different typeof are `Array` and `RegExp`### v0.1.0
* Added support for `null`
* Add extra tests