Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/skratchdot/get-object-type
get the type of a javascript object
https://github.com/skratchdot/get-object-type
Last synced: 16 days 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 (over 10 years ago)
- Default Branch: master
- Last Pushed: 2020-01-20T03:09:16.000Z (almost 5 years ago)
- Last Synced: 2024-11-17T19:45:27.816Z (about 2 months ago)
- Language: JavaScript
- Size: 11.7 KB
- Stars: 3
- Watchers: 3
- 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
[![NPM version](https://badge.fury.io/js/get-object-type.svg)](http://badge.fury.io/js/get-object-type)
[![Build Status](https://travis-ci.org/skratchdot/get-object-type.png?branch=master)](https://travis-ci.org/skratchdot/get-object-type)
[![Code Climate](https://codeclimate.com/github/skratchdot/get-object-type.png)](https://codeclimate.com/github/skratchdot/get-object-type)
[![Coverage Status](https://coveralls.io/repos/skratchdot/get-object-type/badge.svg?branch=master&service=github)](https://coveralls.io/github/skratchdot/get-object-type?branch=master)
[![Dependency Status](https://david-dm.org/skratchdot/get-object-type.svg)](https://david-dm.org/skratchdot/get-object-type)
[![devDependency Status](https://david-dm.org/skratchdot/get-object-type/dev-status.svg)](https://david-dm.org/skratchdot/get-object-type#info=devDependencies)[![NPM](https://nodei.co/npm/get-object-type.png)](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.