Added Top Web Models profile scraper.
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
const { convert, convertMany } = require('convert');
|
||||
|
||||
const logger = require('../logger')(__filename);
|
||||
|
||||
function inchesToCm(inches) {
|
||||
if (!inches) return null;
|
||||
|
||||
@@ -54,6 +58,31 @@ function kgToLbs(kgs) {
|
||||
return Math.round(Number(kilos) / 0.453592);
|
||||
}
|
||||
|
||||
function convertManyApi(input, to) {
|
||||
const curatedInput = input
|
||||
.replace('\'', 'ft')
|
||||
.replace('"', 'in');
|
||||
|
||||
return Math.round(convertMany(curatedInput).to(to)) || null;
|
||||
}
|
||||
|
||||
function convertApi(input, fromOrTo, to) {
|
||||
if (!input) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
if (typeof input === 'string' && to === undefined) {
|
||||
return convertManyApi(input, fromOrTo);
|
||||
}
|
||||
|
||||
return Math.round(convert(input).from(fromOrTo).to(to)) || null;
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
cmToFeetInches,
|
||||
cmToInches,
|
||||
@@ -62,4 +91,5 @@ module.exports = {
|
||||
inchesToCm,
|
||||
lbsToKg,
|
||||
kgToLbs,
|
||||
convert: convertApi,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user