https://github.com/skratchdot/get-object-type
get the type of a javascript object
https://github.com/skratchdot/get-object-type
Last synced: 3 months ago
JSON representation
get the type of a javascript object
- Host: GitHub
- URL: https://github.com/skratchdot/get-object-type
- Owner: skratchdot
- License: mit
- Created: 2014-09-15T21:53:01.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2020-01-20T03:09:16.000Z (over 5 years ago)
- Last Synced: 2025-03-11T18:54:38.885Z (4 months ago)
- Language: JavaScript
- Size: 11.7 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-MIT
Awesome Lists containing this project
README
# get-object-type
[](http://badge.fury.io/js/get-object-type)
[](https://travis-ci.org/skratchdot/get-object-type)
[](https://codeclimate.com/github/skratchdot/get-object-type)
[](https://coveralls.io/github/skratchdot/get-object-type?branch=master)
[](https://david-dm.org/skratchdot/get-object-type)
[](https://david-dm.org/skratchdot/get-object-type#info=devDependencies)[](https://npmjs.org/package/get-object-type)
## Description
get the type of a javascript object as a string. an alternative to using typeof checks.
NOTE: I've googled / re-written / used this function so many different times, I decided to publish it
as a module.## Getting Started
Install the module with: `npm install get-object-type`
```javascript
var getType = require('get-object-type');
getType(null); // returns 'Null'
getType([]); // returns 'Array'
getType({foo: 'bar'}); // returns 'Object'
getType(42); // returns 'Number'// this modules works differently than the standard typeof operator
var d = new Date();
typeof(d); // returns 'object'
getType(d); // returns 'Date'typeof(null); // returns 'object'
getType(null); // returns 'Null'typeof({}); // returns 'object'
getType({}); // returns 'Object'
```## Links
- [Source Code](https://github.com/skratchdot/get-object-type)
- [Changelog](https://github.com/skratchdot/get-object-type/blob/master/CHANGELOG.md)
- [Live example on Tonic](https://tonicdev.com/npm/get-object-type)## License
Copyright (c) 2014 skratchdot
Licensed under the MIT license.