node-red-contrib-home-assistant-websocket
Version:
Node-RED integration with Home Assistant through websocket and REST API
22 lines (21 loc) • 583 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.toDate = toDate;
// Type guard for WithDateTime
function isWithDateTime(obj) {
return obj && typeof obj.dateTime === 'string';
}
// Type guard for WithDate
function isWithDate(obj) {
return obj && typeof obj.date === 'string';
}
// Function to handle the conversion at runtime
function toDate(obj) {
if (isWithDateTime(obj)) {
return new Date(obj.dateTime);
}
else if (isWithDate(obj)) {
return new Date(obj.date);
}
throw new Error('Invalid object');
}
;