UNPKG

node-red-contrib-home-assistant-websocket

Version:
22 lines (21 loc) 583 B
"use strict"; 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'); }