create helper functions #53

Closed
boiii wants to merge 2 commits from boiii/traxxx:minor-refactor into master
1 changed files with 20 additions and 4 deletions
Showing only changes of commit 4c9cbe11aa - Show all commits

View File

@ -342,6 +342,25 @@ 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) {
if (!profile) {
return null;
@ -375,10 +394,7 @@ async function curateProfile(profile, actor) {
curatedProfile.tattoos = profile.tattoos?.trim() || null;
curatedProfile.piercings = profile.piercings?.trim() || null;
curatedProfile.gender = (/female/i.test(profile.gender) && 'female')
|| (/shemale|trans/i.test(profile.gender) && 'transsexual')
|| (/male/i.test(profile.gender) && 'male')
|| null;
curatedProfile.gender = tryParseGender(profile.gender);
const dateOfBirth = profile.dateOfBirth || profile.birthdate;