From 4c9cbe11aafddeaba37d55b8c48ae41f8654ce96 Mon Sep 17 00:00:00 2001 From: boi12321 Date: Sat, 27 May 2023 17:49:19 +0200 Subject: [PATCH] refactor gender parsing function --- src/actors.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/actors.js b/src/actors.js index 71cbf38e..6f021b8a 100755 --- a/src/actors.js +++ b/src/actors.js @@ -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;