2 Commits

Author SHA1 Message Date
boi12321
4c9cbe11aa refactor gender parsing function 2023-05-27 17:49:19 +02:00
boi12321
6b92b2020d refactor age check 2023-05-27 17:46:31 +02:00
3 changed files with 891 additions and 339 deletions

1188
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -48,14 +48,14 @@
"babel-loader": "^8.0.6", "babel-loader": "^8.0.6",
"babel-preset-airbnb": "^5.0.0", "babel-preset-airbnb": "^5.0.0",
"css-loader": "^6.5.0", "css-loader": "^6.5.0",
"eslint": "^8.2.0", "eslint": "^8.1.0",
"eslint-config-airbnb": "^19.0.0", "eslint-config-airbnb": "^18.2.1",
"eslint-config-airbnb-base": "^15.0.0", "eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.20.1", "eslint-plugin-import": "^2.20.1",
"eslint-plugin-jsx-a11y": "^6.2.3", "eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.18.3", "eslint-plugin-react": "^7.18.3",
"eslint-plugin-vue": "^8.0.3", "eslint-plugin-vue": "^8.0.3",
"eslint-watch": "^8.0.0", "eslint-watch": "^7.0.0",
"eslint-webpack-plugin": "^3.1.0", "eslint-webpack-plugin": "^3.1.0",
"mini-css-extract-plugin": "^2.4.3", "mini-css-extract-plugin": "^2.4.3",
"node-sass": "^6.0.1", "node-sass": "^6.0.1",

View File

@@ -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;