File: number/js/number-parse.js
/**
* Parse number submodule.
*
* @module datatype-number
* @submodule datatype-number-parse
* @for Number
*/
var LANG = Y.Lang;
Y.mix(Y.namespace("Number"), {
/**
* Converts data to type Number.
*
* @method parse
* @param data {String | Number | Boolean} Data to convert. The following
* values return as null: null, undefined, NaN, "".
* @return {Number} A number, or null.
*/
parse: function(data) {
var number = (data === null) ? data : +data;
if(LANG.isNumber(number)) {
return number;
}
else {
Y.log("Could not parse data to type Number", "warn", "number");
return null;
}
}
});
// Add Parsers shortcut
Y.namespace("Parsers").number = Y.Number.parse;
Y.namespace("DataType");
Y.DataType.Number = Y.Number;