Usage Examples
@openpronoun/core API
Section titled “@openpronoun/core API”Install the package:
npm install @openpronoun/coreparse(input)
Section titled “parse(input)”Converts free-text input into a structured PronounPreference. Returns null
for empty, whitespace-only, placeholder (N/A, TBD, -), or null input.
import { parse } from "@openpronoun/core";
parse("she/her");// [{ subjective: "she", objective: "her", possessive_adjective: "her",// possessive_pronoun: "hers", reflexive: "herself" }]
parse("they/them, she/her");// [{ subjective: "they", ... }, { subjective: "she", ... }]
parse("they/them/he/him");// two sets — concatenation split:// [{ subjective: "they", ... }, { subjective: "he", ... }]
parse("any pronouns");// [{ type: "any" }]
parse("no pronouns");// [{ type: "none" }]
parse("ask me");// [{ type: "ask" }]
parse("prefer not to disclose");// [{ type: "unspecified" }]
parse("she/her (professional contexts only)");// [{ subjective: "she", ..., context: "professional contexts only" }]
parse("he/him or she/her, just not they/them");// [{ subjective: "he", ... },// { subjective: "she", ... },// { subjective: "they", ..., exclude: true }]
parse("fox/foxs");// [{ type: "custom", display: "fox/foxs" }]
parse("N/A");// null
parse(null);// nullformat(preference, options?)
Section titled “format(preference, options?)”Converts a PronounPreference back into a display string.
import { parse, format } from "@openpronoun/core";
const pref = parse("she/her, they/them")!;
format(pref);// "She/Her, They/Them"
format(pref, { form: "expanded" });// "She/Her/Hers, They/Them/Theirs"
// Ranking: lower number = higher priorityconst ranked = parse("she/her, they/them")!.map((e, i) => ({ ...e, ranking: i === 0 ? 2 : 1,}));format(ranked);// "They/Them, She/Her"
// Context is rendered in parenthesesformat(parse("he/him (at work), they/them")!);// "He/Him (at work), They/Them"
// Excluded sets are omitted from short displayformat(parse("she/her, not they/them")!);// "She/Her"
// Excluded sets surfaced in detailed displayformat(parse("she/her, not they/them")!, { form: "detailed" });// "She/Her (not They/Them)"
// Special typesformat([{ type: "any" }]); // "Any pronouns"format([{ type: "none" }]); // "No pronouns (use name)"format([{ type: "ask" }]); // "Ask me my pronouns"format([{ type: "unspecified" }]); // "Unspecified"
// Custom entries are displayed as entered (with capitalization)format([{ type: "custom", display: "fae/faer" }]);// "Fae/Faer"format with privacy filtering
Section titled “format with privacy filtering”Entries with privacy level 1 or higher are hidden when audience is
"public".
import { format } from "@openpronoun/core";
const pref = [ { subjective: "she", objective: "her", possessive_adjective: "her", possessive_pronoun: "hers", reflexive: "herself", privacy: 0 }, { subjective: "they", objective: "them", possessive_adjective: "their", possessive_pronoun: "theirs", reflexive: "themselves", privacy: 1 },];
format(pref); // "She/Her, They/Them"format(pref, { audience: "public" }); // "She/Her"validate, validateOrThrow, validationErrors
Section titled “validate, validateOrThrow, validationErrors”import { validate, validateOrThrow, validationErrors } from "@openpronoun/core";
validate([{ subjective: "she", objective: "her", possessive_adjective: "her", possessive_pronoun: "hers", reflexive: "herself" }]);// true
validate("she/her");// false — raw strings are not a PronounPreference
validationErrors([{ subjective: "she" }]);// ["objective: Required", "possessive_adjective: Required", ...]
validateOrThrow([{ type: "any" }]);// [{ type: "any" }] — returns the value if valid, throws ZodError if notfilterByAudience
Section titled “filterByAudience”Strips entries the current audience is not allowed to see, based on the privacy
field.
import { filterByAudience } from "@openpronoun/core";
const pref = [ { subjective: "she", objective: "her", possessive_adjective: "her", possessive_pronoun: "hers", reflexive: "herself" }, { subjective: "they", objective: "them", possessive_adjective: "their", possessive_pronoun: "theirs", reflexive: "themselves", privacy: 1 },];
filterByAudience(pref, "public");// [{ subjective: "she", ... }] — they/them entry removed
filterByAudience(pref, "internal");// both entries returned — only "public" triggers filteringConstants
Section titled “Constants”import { PRONOUN_DICTIONARY, FORM_TO_SET, SPECIAL_KEYWORDS, PLACEHOLDER_STRINGS, FILLER_PATTERNS,} from "@openpronoun/core";
// All built-in English setsPRONOUN_DICTIONARY.map((e) => `${e.subjective}/${e.objective}`);// ["she/her", "he/him", "they/them", "it/it", "xe/xem", "ze/zir", ...]
// Reverse lookup: any form → its canonical setFORM_TO_SET.get("him");// { subjective: "he", objective: "him", ... }
FORM_TO_SET.get("theirs");// { subjective: "they", objective: "them", ... }
// All recognized special-keyword phrasesSPECIAL_KEYWORDS.any;// ["any", "any pronouns", "any/all", "all", "idc", ...]
SPECIAL_KEYWORDS.none;// ["none", "no pronouns", "use my name", ...]TypeScript types
Section titled “TypeScript types”import type { PronounPreference, PronounEntry, PronounSet, SpecialPreference, CustomEntry, FormatOptions, CanonicalEntry,} from "@openpronoun/core";
// PronounPreference is PronounEntry[]const pref: PronounPreference = [ { subjective: "they", objective: "them", possessive_adjective: "their", possessive_pronoun: "theirs", reflexive: "themselves", },];
// FormatOptionsconst opts: FormatOptions = { form: "expanded", audience: "public" };@openpronoun/react components
Section titled “@openpronoun/react components”The React package builds on @openpronoun/core and provides ready-made,
accessible components and hooks for collecting and displaying pronouns.
npm install @openpronoun/reactComponents at a glance
Section titled “Components at a glance”| Component | Purpose |
|---|---|
<PronounDisplay> | Read-only display of one or more entries (text or badge mode) |
<PronounBadge> | Single-entry pill badge, optionally removable |
<PronounSelector> | Multi-select picker with drag-to-reorder and custom pronoun editor |
<PronounForm> | All-in-one field: label + selector + helper text + preview |
<PronounDetailEditor> | Form for entering all five pronoun forms manually |
<OriginalTextBadge> | Shows the original freetext alongside structured output |
| Hook | Purpose |
|---|---|
usePronounState | Manages a PronounEntry[] list with add/remove/reorder |
usePronounParser | Debounced live parsing of freetext into entries |
Quick start
Section titled “Quick start”import { PronounForm } from "@openpronoun/react";
function ProfileForm() { const [pronouns, setPronouns] = useState([]); return ( <PronounForm label="Pronouns" helperText="Sharing is optional — we use this to address you correctly." value={pronouns} onChange={setPronouns} showPreview /> );}Display only
Section titled “Display only”import { PronounDisplay } from "@openpronoun/react";
// Short: "She/Her, They/Them"<PronounDisplay pronouns={user.pronouns} />
// Expanded: "She/Her/Hers"<PronounDisplay format="long" pronouns={user.pronouns} />
// Badge pills<PronounDisplay displayMode="badges" pronouns={user.pronouns} />
// Hides entries with privacy ≥ 1 (default: publicOnly=true)<PronounDisplay publicOnly pronouns={user.pronouns} />Theming and customization
Section titled “Theming and customization”Pass a partial theme object to override colors, fonts, border-radius, and
spacing. Built-in presets: defaultTheme, darkTheme, plumecareTheme,
memberDashboardTheme.
import { PronounSelector, darkTheme } from "@openpronoun/react";
<PronounSelector value={pronouns} onChange={setPronouns} theme={darkTheme}/>
// Or supply a partial override (deep-merged with defaultTheme):<PronounSelector value={pronouns} onChange={setPronouns} theme={{ colors: { primary: "#7c3aed" } }}/>Every component also accepts a classNames prop for granular CSS class
injection on individual sub-elements:
<PronounSelector classNames={{ root: "my-selector", tag: { container: "my-tag", label: "my-tag-label" }, option: { groupLabel: "my-group" }, }} value={pronouns} onChange={setPronouns}/>Live examples
Section titled “Live examples”React tab uses @openpronoun/react — click through Display, Selection, Form, Parser, and Themes to explore the full component library.
Vue — @openpronoun/core
- Short
- She/Her, They/Them
- Expanded
- She/Her/Hers, They/Them/Theirs
- Entries
- 2
Svelte — @openpronoun/core
- Short
- She/Her, They/Them
- Expanded
- She/Her/Hers, They/Them/Theirs
- Entries
- 2
Solid — @openpronoun/core
- Short
- She/Her, They/Them
- Expanded
- She/Her/Hers, They/Them/Theirs
- Entries
- 2
Preact — @openpronoun/core
- Short
- She/Her, They/Them
- Expanded
- She/Her/Hers, They/Them/Theirs
- Entries
- 2
Alpine.js — @openpronoun/core (SSR)
- Input
she/her, they/them- Short
- Expanded
- Entries
Alpine runs in the browser and can't import Node ESM directly — parsing happens at build time via Astro. For live re-parsing, proxy to an API route that calls @openpronoun/core server-side.
Vanilla JS — @openpronoun/core (SSR)
| Input | Short | Expanded | # |
|---|---|---|---|
she/her, they/them | She/Her, They/Them | She/Her/Hers, They/Them/Theirs | 2 |
any pronouns | Any pronouns | Any pronouns | 1 |
xe/xem | Xe/Xem | Xe/Xem/Xyrs | 1 |
he/him or she/her, just not they/them | He/Him, She/Her | He/Him/His, She/Her/Hers | 3 |
Rendered at build time — no JS bundle required. For interactive demos in plain JS, parse on the server and stream the result, or use one of the framework integrations above.