jquery-typeof
v1.0.1
Published
A jQuery plugin to fix typeof inconsistencies in JavaScript. AMD (Require.js) and browser compatible.
Downloads
5
Maintainers
Readme
jQuery-typeof
A jQuery plugin to fix typeof inconsistencies in JavaScript. AMD (Require.js) and browser compatible.
To support this project, you can at the support page by supporting the developer.
Getting Started
NPM (What is NPM? What is Grunt?)
npm install jquery-typeof
Bower (What is Bower?)
bower install jquery-typeof
Download directly (Do not link this directly on your site, the file is sent with a plain/text header and can cause loading problems)
API & Usage
The jQuery-typeof plugin provides a fix to overcome JavaScript native typeof behaviour.
| Function | Description | Example | | -------- | ----------- | ------- | | $.typeof(value) | Returns the proper type of the passed value as a string. | $.typeof([]) === "array" |
In Browser (NPM)
<!-- important to add jquery before jquery-typeof plugin -->
<script src="node_modules/jquery-typeof/jquery.typeof.js"></script>
In Browser (Bower)
<!-- important to add jquery before jquery-typeof plugin -->
<script src="bower_components/jquery-typeof/jquery.typeof.js"></script>
In Browser (Require.js)
<script>
require(["jquery", "jquery-typeof"], function($) {
/* jquery-typeof is usable from now on */
});
</script>
In case, you have some strange problems using jQuery with Require.js, try the following:
- install Require.js using npm (npm install requirejs)
- install jQuery using npm (npm install jquery)
- install jquery-typeof using npm (npm install jquery-typeof)
After these steps, using Require.js .config(...) function, additional setup is needed to use jQuery:
require.config({
baseUrl: "./",
paths: {
jquery: "node_modules/jquery/dist/jquery"
}
});
And the final, usable example:
<script>
require.config({
baseUrl: "./",
paths: {
jquery: "node_modules/jquery/dist/jquery"
}
});
require(["jquery", "node_modules/jquery-typeof/jquery.typeof"], function($) {
/* jquery-typeof is usable from now on */
});
</script>
In case you would like to use paths to make the code more clear and readable, this is recommended:
<script>
require.config({
baseUrl: "./",
paths: {
jquery: "node_modules/jquery/dist/jquery",
"jquery-typeof": "node_modules/jquery-typeof/jquery.typeof"
}
});
require(["jquery", "jquery-typeof"], function($) {
/* jquery-typeof is usable from now on */
});
</script>
In Browser (Directly downloaded source)
<!-- important to add jquery before jquery-typeof plugin -->
<script src="scripts/jquery.typeof.js"></script>
In the code:
/* This list below provides the usability of this plugin */
$.typeof() === "undefined"
$.typeof(undefined) === "undefined"
$.typeof(null) === "null"
$.typeof(true) === "boolean"
$.typeof(false) === "boolean"
$.typeof(-1) === "number"
$.typeof(0) === "number"
$.typeof(1) === "number"
$.typeof(-Infinity) === "number"
$.typeof(Infinity) === "number"
$.typeof(NaN) === "number"
$.typeof("string") === "string"
$.typeof([]) === "array"
$.typeof({}) === "object"
$.typeof(function(){}) === "function"
$.typeof(new Date()) === "object"
$.typeof(/s+/g) === "object"
$.typeof(new Error()) === "object"
Internet Explorer 8 and Below
This plugins is compatible with IE8 and was tested with IE8 & jQuery 1.9.0.
Suggestions, Ideas & Requests
Post any occurring suggestions, useful ideas and requests to the project's issue page under the suggestion/idea/request label by clicking here.
- Constructive criticism is encouraged and welcomed by contacting the developer or using GitHub.
Issues/Bugs
In case of any occurring issues and/or bugs, post on the project's issues page with appropriate label(s).
Support
If you find this tool useful, you can support this project by supporting the developer here.
Contribution & A Note
In the spirit of open source software development, this project is always open to and encourages community code contribution. To get started, just run through the source file, check the comments and general coding style and start to contribute.
- In case you find this tool useful, support it by supporting the developer, follow the developer on social platforms or send an email to the developer.
License
Copyright (c) 2014 "Richard KnG" Richárd Szakács. Licensed under the MIT license.
The license mentioned above applies to all parts of this software except as documented below
All files located in the node_modules and external directories are externally maintained libraries used by this software which have their own licenses. We recommend you read them, as their terms may differ from the terms above.