create helper functions #53
			
				
			
		
		
		
	|  | @ -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; | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue