@sebgroup/frontend-tools
Version:
A set of frontend tools
43 lines (38 loc) • 1.41 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var isValidDate = require('../isValidDate/isValidDate.js');
/**
* Retrives a date object based on various inputs
* @param value The date value to use to retrive the date
* @returns The date object
*/
function toDate(value,
/** DEPRACATED! The input format has been depracated. The default javascript Date object string constructor will be used instead */
inputFormat) {
if (inputFormat) {
console.warn("The inputFormat has been depracated. The default javascript Date object string constructor will be used instead");
}
switch (true) {
case !value:
return null;
case value instanceof Date: {
return isValidDate.isValidDate(value) ? value : null;
}
case typeof value === "string":
case typeof value === "number": {
const newDate = new Date(value);
return isValidDate.isValidDate(newDate) ? newDate : null;
}
case typeof value === "object" &&
Array.isArray(value) &&
value.length > 1:
{
const newDate = new Date(...value);
return isValidDate.isValidDate(newDate) ? newDate : null;
}
default:
return null;
}
}
exports.toDate = toDate;
//# sourceMappingURL=toDate.js.map