Added BaDoink profile scraper. Improved convert wrapper.

This commit is contained in:
DebaucheryLibrarian
2021-02-03 21:03:35 +01:00
parent cd417f40a8
commit 79b51eca67
5 changed files with 87 additions and 9 deletions

View File

@@ -61,7 +61,8 @@ function kgToLbs(kgs) {
function convertManyApi(input, to) {
const curatedInput = input
.replace('\'', 'ft')
.replace('"', 'in');
.replace(/"|''/, 'in')
.replace(/\d+ft\s*\d+\s*$/, match => `${match}in`); // height without any inch symbol
return Math.round(convertMany(curatedInput).to(to)) || null;
}
@@ -76,7 +77,9 @@ function convertApi(input, fromOrTo, to) {
return convertManyApi(input, fromOrTo);
}
return Math.round(convert(input).from(fromOrTo).to(to)) || null;
const inputNumber = Number(typeof input === 'string' ? input.match(/\d+(\.\d+)?/)?.[0] : input);
return Math.round(convert(inputNumber).from(fromOrTo).to(to)) || null;
} catch (error) {
logger.error(error);
return null;