Skip to content

Instantly share code, notes, and snippets.

@timwingfield
Created July 5, 2012 22:28
Show Gist options
  • Save timwingfield/3056886 to your computer and use it in GitHub Desktop.
Save timwingfield/3056886 to your computer and use it in GitHub Desktop.
revealing module in javascript
ProjectNamespace.Helpers.Converters = (function() {
var convertToDate, convertToFloat, convertToInteger, isValidDate;
isValidDate = function(d) {
if (Object.prototype.toString.call(d) === "[object Date]") {
return !isNaN(d.getTime());
}
return false;
};
convertToDate = function(input) {
var d;
d = new Date(input);
if (isValidDate(d)) return d;
};
convertToInteger = function(value) {
return parseInt(value) || null;
};
convertToFloat = function(value) {
return parseFloat(value) || null;
};
return {
convertToDate: convertToDate,
convertToInteger: convertToInteger,
convertToFloat: convertToFloat
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment