@traveller-api/circle-fetcher
Advanced tools
Comparing version 0.1.2 to 0.1.4
@@ -12,24 +12,31 @@ "use strict"; | ||
var _a, _b, _c; | ||
const $home = $(homeElm); | ||
const hotelNumber = Number((_b = (_a = $home | ||
.find('[id^="hotel_no_"]') | ||
.attr('id')) === null || _a === void 0 ? void 0 : _a.replace(/^hotel_no_/, '')) !== null && _b !== void 0 ? _b : ''); | ||
const id = (_c = $home.find('[id^="hotel_no_"]').attr('value')) !== null && _c !== void 0 ? _c : ''; | ||
const { name, city, roomType } = (0, parsers_1.parseHomeTitle)($home.find('.title').text()); | ||
const tags = $home | ||
.find('.info span') | ||
.get() | ||
.map((info) => $(info).text()); | ||
const home = { | ||
hotelNumber, | ||
id, | ||
name, | ||
city, | ||
roomType, | ||
tags, | ||
}; | ||
return home; | ||
}); | ||
try { | ||
const $home = $(homeElm); | ||
const hotelNumber = Number((_b = (_a = $home | ||
.find('[id^="hotel_no_"]') | ||
.attr('id')) === null || _a === void 0 ? void 0 : _a.replace(/^hotel_no_/, '')) !== null && _b !== void 0 ? _b : ''); | ||
const id = (_c = $home.find('[id^="hotel_no_"]').attr('value')) !== null && _c !== void 0 ? _c : ''; | ||
const { name, city, roomType } = (0, parsers_1.parseHomeTitle)($home.find('.title').text()); | ||
const tags = $home | ||
.find('.info span') | ||
.get() | ||
.map((info) => $(info).text()); | ||
const home = { | ||
hotelNumber, | ||
id, | ||
name, | ||
city, | ||
roomType, | ||
tags, | ||
}; | ||
return home; | ||
} | ||
catch (e) { | ||
console.error(e); | ||
return null; | ||
} | ||
}) | ||
.filter((home) => home !== null); | ||
return homes; | ||
}; | ||
exports.parseHomesPage = parseHomesPage; |
@@ -5,3 +5,3 @@ "use strict"; | ||
const parseHomeTitle = (input) => { | ||
const regex = /^【(.+?)\s*\/\s*(.+?)】(.+)$/; | ||
const regex = /^(※.+?※)?【(.+?)\s*\/\s*(.+?)】(.+)$/; | ||
const match = regex.exec(input); | ||
@@ -11,5 +11,5 @@ if (!match) { | ||
} | ||
const [, city = '', roomType = '', name = ''] = match; | ||
const [, , city = '', roomType = '', name = ''] = match; | ||
return { name, city, roomType }; | ||
}; | ||
exports.parseHomeTitle = parseHomeTitle; |
{ | ||
"name": "@traveller-api/circle-fetcher", | ||
"version": "0.1.2", | ||
"version": "0.1.4", | ||
"engines": { | ||
@@ -38,3 +38,3 @@ "node": "16" | ||
"jest": "^29.3.1", | ||
"prettier": "^2.7.1", | ||
"prettier": "^2.8.8", | ||
"rimraf": "^4.4.1", | ||
@@ -44,3 +44,3 @@ "ts-jest": "^29.0.3", | ||
}, | ||
"gitHead": "1a56e67adb7acd369c87dfd378090597b511ac70" | ||
"gitHead": "016f12e5675a6ccd91cfdde4c530fea801d04e91" | ||
} |
21702
541