JQuery version of YAHOO.lang (isUndefined, isNull, isString, etc.)

Does anyone know of a jQuery plugin that has β€œhelpers” or extensions similar to those found in the YAHOO.lang namespace ?

I mean features like:

isNull isDefined isString isFunction 

I would also appreciate the same for strings and arrays like Contains, StartsWith (I know they are easy to write, I'm just looking for a plugin that covers them all).

This is not in the YAHOO.lang namespace, but also in the form of related extensions defining the value of the radio block (from one verified), the type of the form element in a friendly name.

In particular, a plugin with a smooth API, not a selector, for example

 $("input[@type=radio][@checked]") 

Again I know that they are easy to implement, but I do not want to reinvent the wheel.

+4
source share
3 answers

I decided to write two new plugins. There are two projects here:

Form extensions

Example:

 // elementExists is also added if ($("#someid").elementExists()) alert("found it"); // Select box related $("#mydropdown").isDropDownList(); // Can be any of the items from a list of radio boxes - it will use the name $("#randomradioboxitem").isRadioBox("myvalue"); $("#radioboxitem").isSelected("myvalue"); 

Common extensions

They are modeled by Prototype / Mochikit functions such as isNull.

Example:

 $.isNumber(42); var x; $.isUndefined(x); $.isNullOrUndefined(x); $.isString(false); $.emptyString("the quick brown fox"); $.startsWith("the quick brown fox","the"); $.formatString("Here is the {0} and {2}","first","second"); 

Both have more than 50 unit tests that are part of the download. I hope they will be useful to people who find this page.

0
source

jQuery 1.3.2 has built-in isFunction and isArray (see snippet below). The code for isString is staightforward ( typeof obj === "string" ), like isNull ( obj === null ) and isDefined ( obj !== undefined ) - so I would just program this inline instead of using a function.

 // See test/unit/core.js for details concerning isFunction. // Since version 1.3, DOM methods and functions like alert // aren't supported. They return false on IE (#2968). isFunction: function( obj ) { return toString.call(obj) === "[object Function]"; }, isArray: function( obj ) { return toString.call(obj) === "[object Array]"; }, 
+2
source

Underscore.js or _.js, if you prefer, is a library that contains these functions.

+1
source

All Articles