File indexing completed on 2024-12-29 04:51:02
0001 /* 0002 SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 function main(text) { 0008 var res = JsonLd.newLodgingReservation(); 0009 0010 var bookingRef = text.match(/(?:Booking no\.|Buchungs-Nr\.)\s+([A-Z0-9-]+)\s+/); 0011 if (!bookingRef) 0012 return null; 0013 res.reservationNumber = bookingRef[1]; 0014 var idx = bookingRef.index + bookingRef[0].length; 0015 0016 var arrivalDate = text.substr(idx).match(/(?:Arrival|Anreise)\s+(\d{1,2}\.\d{1,2}\.\d{4})\s+/) 0017 if (!arrivalDate) 0018 return null; 0019 res.checkinTime = JsonLd.toDateTime(arrivalDate[1] + " 15:00", "dd.MM.yyyy hh:mm", "en"); 0020 idx += arrivalDate.index + arrivalDate[0].length; 0021 0022 var departureDate = text.substr(idx).match(/(?:Departure|Abreise)\s+(\d{1,2}\.\d{1,2}\.\d{4})\s+/) 0023 if (!departureDate) 0024 return null; 0025 res.checkoutTime = JsonLd.toDateTime(departureDate[1] + " 10:00", "dd.MM.yyyy hh:mm", "en"); 0026 idx += departureDate.index + departureDate[0].length; 0027 0028 var geo = text.substr(idx).match(/<(http[^>]*google.com\/maps[^>]*)>/); 0029 res.reservationFor.geo = JsonLd.toGeoCoordinates(geo[1]); 0030 0031 var name = text.substr(idx).match(/\*(?:First name|Vorname)\*\s+([^\s{2}]+)\s{2,}/); 0032 if (!name) 0033 return null; 0034 res.underName.name = name[1]; 0035 idx += name.index + name[0].length; 0036 name = text.substr(idx).match(/\*(?:Last name|Nachname)\*\s+([^\s{2}]+)\s{2,}/); 0037 if (!name) 0038 return null; 0039 res.underName.name += ' ' + name[1]; 0040 idx += name.index + name[0].length; 0041 0042 var hotel = text.substr(idx).match(/(?:Your booked house|Ihr gebuchtes Haus)\s+/); 0043 if (!hotel) 0044 return null; 0045 idx += hotel.index + hotel[0].length; 0046 hotel = text.substr(idx).split(/\s{2,}/); 0047 res.reservationFor.name = hotel[0]; 0048 res.reservationFor.address.streetAddress = hotel[1]; 0049 var city = hotel[2].match(/(\d+)\s(.*)/); 0050 if (city) { 0051 res.reservationFor.address.postalCode = city[1]; 0052 res.reservationFor.address.addressLocality = city[2]; 0053 } else { 0054 res.reservationFor.address.addressLocality = hotel[2]; 0055 } 0056 res.reservationFor.address.addressCountry = hotel[3]; 0057 res.reservationFor.telephone = hotel[4]; 0058 res.reservationFor.email = hotel[5]; 0059 0060 return res; 0061 }