itsa-jsext
Version:
Extensions to native javascript-objects, all within the itsa_ namespace
18 lines (16 loc) • 604 B
JavaScript
const DATEPATTERN = /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/,
isValidDate = function(item) {
return DATEPATTERN.test(item);
};
/**
* Returns true if the item is a date
*
* @method itsa_isDate
* @static
* @param item {any} the item to test.
* @param [stringified] {Boolean} whether a stringified value should be tested as a valid Date pattern.
* @return {Boolean} true if the item is a date
*/
Date.itsa_isDate = function (item, stringified) {
return (Object.prototype.toString.call(item)==="[object Date]") || !!(stringified && (typeof item==="string") && isValidDate(item));
};