create helper functions #53
|
@ -33,6 +33,7 @@ const capitalize = require('./utils/capitalize');
|
||||||
const resolvePlace = require('./utils/resolve-place');
|
const resolvePlace = require('./utils/resolve-place');
|
||||||
const { resolveLayoutScraper } = require('./scrapers/resolve');
|
const { resolveLayoutScraper } = require('./scrapers/resolve');
|
||||||
const getRecursiveParameters = require('./utils/get-recursive-parameters');
|
const getRecursiveParameters = require('./utils/get-recursive-parameters');
|
||||||
|
const dayjs = require('dayjs');
|
||||||
|
|
||||||
const hairColors = {
|
const hairColors = {
|
||||||
'jet-black': 'black',
|
'jet-black': 'black',
|
||||||
|
@ -334,6 +335,32 @@ function curateProfileEntry(profile) {
|
||||||
return curatedProfileEntry;
|
return curatedProfileEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Date} birthDate
|
||||||
|
*/
|
||||||
|
function isAdult(birthDate) {
|
||||||
|
return dayjs(birthDate).diff(new Date(), "years") >= 18;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tries to parse gender from string, or null if not found
|
||||||
|
*
|
||||||
|
* @param {String} text
|
||||||
|
* @returns {String | null}
|
||||||
|
*/
|
||||||
|
function tryParseGender(text) {
|
||||||
|
if (/female/i.test(profile.gender)) {
|
||||||
|
return 'female';
|
||||||
|
}
|
||||||
|
else if (/shemale|trans/i.test(profile.gender)) {
|
||||||
|
return 'transsexual';
|
||||||
|
}
|
||||||
|
else if (/male/i.test(profile.gender)) {
|
||||||
|
return 'male';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
async function curateProfile(profile, actor) {
|
async function curateProfile(profile, actor) {
|
||||||
if (!profile) {
|
if (!profile) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -367,15 +394,12 @@ async function curateProfile(profile, actor) {
|
||||||
curatedProfile.tattoos = profile.tattoos?.trim() || null;
|
curatedProfile.tattoos = profile.tattoos?.trim() || null;
|
||||||
curatedProfile.piercings = profile.piercings?.trim() || null;
|
curatedProfile.piercings = profile.piercings?.trim() || null;
|
||||||
|
|
||||||
curatedProfile.gender = (/female/i.test(profile.gender) && 'female')
|
curatedProfile.gender = tryParseGender(profile.gender);
|
||||||
|| (/shemale|trans/i.test(profile.gender) && 'transsexual')
|
|
||||||
|| (/male/i.test(profile.gender) && 'male')
|
|
||||||
|| null;
|
|
||||||
|
|
||||||
const dateOfBirth = profile.dateOfBirth || profile.birthdate;
|
const dateOfBirth = profile.dateOfBirth || profile.birthdate;
|
||||||
|
|
||||||
curatedProfile.dateOfBirth = (!Number.isNaN(Number(dateOfBirth)) // possibly valid date
|
curatedProfile.dateOfBirth = (!Number.isNaN(Number(dateOfBirth)) // possibly valid date
|
||||||
&& new Date() - dateOfBirth > 567648000000 // over 18
|
&& isAdult(dateOfBirth) // over 18
|
||||||
&& dateOfBirth)
|
&& dateOfBirth)
|
||||||
|| null;
|
|| null;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue