From a8f68f4993488462ccf74ed9b86f91fe8b1daa79 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Tue, 29 Dec 2020 23:44:38 +0100 Subject: [PATCH] Fixed boolean handling in actor profile curation. --- src/actors.js | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/src/actors.js b/src/actors.js index 3310107c..13bdeab0 100644 --- a/src/actors.js +++ b/src/actors.js @@ -75,8 +75,30 @@ const ethnicities = { white: 'white', }; +function getBoolean(value) { + if (typeof value === 'boolean') { + return value; + } + + if (typeof value === 'string') { + if (/yes/i.test(value)) { + return true; + } + + if (/no/i.test(value)) { + return true; + } + } + + return null; +} + function getMostFrequent(items) { const { mostFrequent } = items.reduce((acc, item) => { + if (item === undefined || item === null) { + return acc; + } + const slug = slugify(item); acc.counts[slug] = (acc.counts[slug] || 0) + 1; @@ -347,25 +369,10 @@ async function curateProfile(profile, actor) { curatedProfile.penisLength = Number(profile.penisLength) || profile.penisLength?.match?.(/\d+/)?.[0] || null; curatedProfile.penisGirth = Number(profile.penisGirth) || profile.penisGirth?.match?.(/\d+/)?.[0] || null; - curatedProfile.circumcised = (typeof profile.circumcised === 'boolean' && profile.circumcised) - ?? (/yes/i.test(profile.circumcised) && true) - ?? (/no/i.test(profile.circumcised) && false) - ?? null; - - curatedProfile.naturalBoobs = (typeof profile.naturalBoobs === 'boolean' && profile.naturalBoobs) - ?? (/yes/i.test(profile.naturalBoobs) && true) - ?? (/no/i.test(profile.naturalBoobs) && false) - ?? null; - - curatedProfile.hasTattoos = (typeof profile.hasTattoos === 'boolean' && profile.hasTattoos) - ?? (/yes/i.test(profile.hasTattoos) && true) - ?? (/no/i.test(profile.hasTattoos) && true) - ?? null; - - curatedProfile.hasPiercings = (typeof profile.hasPiercings === 'boolean' && profile.hasPiercings) - ?? (/yes/i.test(profile.hasPiercings) && true) - ?? (/no/i.test(profile.hasPiercings) && true) - ?? null; + curatedProfile.circumcised = getBoolean(profile.circumcised); + curatedProfile.naturalBoobs = getBoolean(profile.naturalBoobs); + curatedProfile.hasTattoos = getBoolean(profile.hasTattoos); + curatedProfile.hasPiercings = getBoolean(profile.hasPiercings); if (argv.resolvePlace) { const [placeOfBirth, placeOfResidence] = await Promise.all([