js-partial-type-of
Synopsis
A partial to provide a better typeof capability. This typeof partial returns the practically correct type in string representation of the specific object. Written in UMD.
Compatible with ECMAScript 6.
Install
npm install js-partial-type-of
Usage - Include/Initialization
- AMD (e.g.: RequireJS)
;
- CommonJS (e.g.: NodeJS)
var typeOf = ; // you can now use typeOf
- Browser
// load the source from "node_modules/js-partial-type-of/dist/js-partial-type-of.js" - for development// or from "node_modules/js-partial-type-of/dist/js-partial-type-of.min.js" - for production var typeOf = js_partial_type_of; // it is available in the global namespace // you can now use typeOf
## Usage - After Initialization
- General usage
// check the type of primitive types === 'undefined' === 'null' // notice, that this will return **the practically correct type** === 'boolean' === 'boolean' === 'number' === 'number' === 'number' === 'number' === 'number' === 'number' === 'string' === 'string' === 'symbol' // check the type of reference types === 'array' // notice, that this will return **the practically correct type** === 'object' === 'function' === 'date' === 'regexp' === 'regexp' // inline RegExp === 'error' // also for any other errors, that extend the basic Error Object
- Default behaviour
// default behaviour - similar to native typeof, but it returns **the practically correct types** === 'array' // notice, that this will return **the practically correct type** === 'object' === 'function' === 'date' === 'regexp' === 'typedarray' === 'object'
- Extended behaviours
// extended behaviour - return the specific type, rather useful for extended types// when originalCase is not specified, by default, every type will be all lowercase. === 'array' === 'object' === 'function' === 'date' === 'regexp' // **note the differences below compared to previous example** === 'int8array' === 'customclass' // extended behaviour - return the specific type in original case// it is useful for logging and/or debugging purposes in general === 'Array' === 'Object' === 'Function' === 'Date' === 'RegExp' // **note the differences below compared to previous example** === 'Int8Array' === 'CustomClass'
// check the type for typed arrays === 'typedarray' === 'typedarray' === 'typedarray' === 'typedarray' === 'typedarray' === 'typedarray' === 'typedarray' === 'typedarray' === 'typedarray' // check their types with specificType = true === 'int8array' === 'uint8array' === 'uint8clampedarray' === 'int16array' === 'uint16array' === 'int32array' === 'uint32array' === 'float32array' === 'float64array' // get their constructor's names in non-converted (original) case. === 'Int8Array' === 'Uint8Array' === 'Uint8ClampedArray' === 'Int16Array' === 'Uint16Array' === 'Int32Array' === 'Uint32Array' === 'Float32Array' === 'Float64Array'
Documentation
Check the source here since it's well structured and documented. Also you can find the rendered jsDoc documentation on Doclets.io.
Also, check the unit tests in order to grasp the full-fledged capabilities.
Have fun! ;)
Issues
If you find any bugs and other issues, check the GSDC Guide - Issues section on how to submit issues in a standardized way on the project's issues page.
In case you have any suggestions regarding the project (features, additional capabilities, etc.), check the GSDC Guide - Suggestions section on how to submit suggestions in an easy, standardized way on the project's issues page.
Contribution
In order to contribute to this project, check the GSDC Guide for an easy, standardized way on how to contribute to projects.
Support
If you by any means find this project useful, consider supporting the organization.
There are multiple options to support the project and the developers. Any means of support is beneficial and helpful.
License
MIT @ Richard King