Skip to content

Commit

Permalink
Merge pull request #48 from ItsVipra/improve-pronoun-field-matching
Browse files Browse the repository at this point in the history
Switch to a regex-only pronoun field matching
  • Loading branch information
ItsVipra authored Jul 17, 2023
2 parents de65c96 + 96c530c commit 3fa73ed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 2 additions & 5 deletions src/libs/pronouns.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sanitizeHtml from "sanitize-html";

const fieldMatchers = [/\bpro.*nouns?\b/i, "pronomen"];
const fieldMatchers = [/\bpro.*nouns?\b/i, /\bpronomen\b/i, /(i )?go(es)? by/i];
const knownPronounUrls = [
/pronouns\.page\/(@(?<username>\w+))?:?(?<pronouns>[\w/:]+)?/,
/pronouns\.within\.lgbt\/(?<pronouns>[\w/]+)/,
Expand Down Expand Up @@ -44,10 +44,7 @@ export async function extractFromStatus(status) {
async function extractFromField(field) {
let pronounsRaw;
for (const matcher of fieldMatchers) {
if (typeof matcher === "string" && field.name.toLowerCase().includes(matcher)) {
pronounsRaw = field.value;
break;
} else if (field.name.match(matcher)) {
if (field.name.match(matcher)) {
pronounsRaw = field.value;
break;
}
Expand Down
6 changes: 5 additions & 1 deletion tests/extractPronouns.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ const validFields = [
"professional nouns",
"pronomen",
"Pronouns / Pronomen",
"Pronomen (DE)",
"Pronouns (EN)",
"i go by",
"go by",
];
const invalidFields = ["pronounciation"];
const invalidFields = ["pronounciation", "pronomenverwaltung"];

for (const field of validFields) {
extract(`${field} is extracted`, async () => {
Expand Down

0 comments on commit 3fa73ed

Please sign in to comment.