Created
July 5, 2012 22:28
-
-
Save timwingfield/3056886 to your computer and use it in GitHub Desktop.
revealing module in javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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