@mailwoman/record 10.0.0 → 10.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # @mailwoman/record
2
2
 
3
- **Record schema and per-field normalizers** for the geocode-first entity
4
- resolution matcher. Address-first design: the canonical `PostalAddress` record
5
- composes parsed address components, the formatter's match key, and a resolved
6
- geocode. Organization and contact records build on the same canonical record.
3
+ This package provides the **record schema and per-field normalizers** for the
4
+ geocode-first entity resolution matcher. The design starts from the address. The
5
+ canonical `PostalAddress` record combines parsed address components, the
6
+ formatter's match key, and a resolved geocode. Organization and contact records build on the same canonical record.
7
7
 
8
8
  ```ts
9
9
  import { PostalAddress, parsePersonName, canonicalizeOrganizationName } from "@mailwoman/record";
@@ -50,24 +50,24 @@ import { canonicalizeOrganizationName, type CanonicalizeOrgOpts } from "@mailwom
50
50
 
51
51
  ## Design
52
52
 
53
- - **Plain data, no classes.** Records are plain TypeScript objects with
53
+ - **Plain data without classes.** Records are plain TypeScript objects with
54
54
  branded types where needed.
55
- - **Address-first.** The `PostalAddress` is the canonical record — the geocode-first
56
- matcher resolves places, not strings.
55
+ - **Address-first.** `PostalAddress` is the canonical record, because the
56
+ geocode-first matcher resolves places and not strings.
57
57
  - **Domain-scoped.** Organization canonicalization supports jurisdiction and
58
58
  domain context (e.g., `{jurisdiction: "ID"}` for Indonesian legal designations,
59
- `{domain: "healthcare"}` to protect PT/SCA from collision with medical
59
+ `{domain: "healthcare"}` to keep PT/SCA from colliding with medical
60
60
  abbreviations).
61
- - **Lean dependencies.** Only depends on `@mailwoman/formatter` for the
62
- canonical key.
61
+ - **Lean dependencies.** The package depends only on `@mailwoman/formatter`, for
62
+ the canonical key.
63
63
 
64
64
  ## Related
65
65
 
66
- - [`@mailwoman/match`](../match) — the fuzzy matcher that consumes these records
67
- - [`@mailwoman/formatter`](../formatter) — `canonicalKey` used by `PostalAddress`
68
- - [`@mailwoman/registry`](../registry) — high-level `resolveEntities` that uses records
66
+ - [`@mailwoman/match`](../match): the fuzzy matcher that consumes these records.
67
+ - [`@mailwoman/formatter`](../formatter): provides the `canonicalKey` that `PostalAddress` uses.
68
+ - [`@mailwoman/registry`](../registry): the high-level `resolveEntities` that uses records.
69
69
  - [Geocode-First Record Matching](https://mailwoman.ai/articles/concepts/geocode-first-record-matching/)
70
70
 
71
71
  ## License
72
72
 
73
- [AGPL-3.0-only](https://www.gnu.org/licenses/agpl-3.0.html)
73
+ [AGPL-3.0-only](https://www.gnu.org/licenses/AGPL-3.0.html)
package/lib/address.ts CHANGED
@@ -2,39 +2,12 @@
2
2
  * @copyright Sister Software
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
- *
6
- * The canonical address record — the matcher's unit of address identity, and the canonical record
7
- * the organization and contact records build on.
8
- *
9
- * It is plain data: parser components + the formatter's match key + an optional resolved geocode,
10
- * composed into one object. No ORM, no decorators, no schema-generation implementation — if we need a
11
- * database we reach for Kysely at the call site, not a model layer here.
12
- *
13
- * The geocode fields mirror mailwoman's `GeocodeResult` (tier + calibrated uncertainty + hierarchy)
14
- * on purpose: that is the location signal the Fellegi-Sunter scorer weights its distance evidence
15
- * by — two records sharing a `address_point` coordinate is strong agreement; sharing an
16
- * `interpolated` centroid is weak; a PO-box / multi-unit coordinate is barely location agreement
17
- * at all (the NAACCR precedent, see the geocode-first record-matching concept doc).
18
5
  */
19
6
 
20
- import { type ComponentDict, type FormatAddressOptions, formatAddress } from "@mailwoman/codex/address-format"
21
- import { canonicalKey } from "@mailwoman/codex/address-key"
22
-
23
- /**
24
- * A geographic coordinate (WGS84 decimal degrees).
25
- */
26
- export interface GeoCoordinate {
27
- latitude: number
28
- longitude: number
29
- }
30
-
31
- /**
32
- * The resolution tier that produced a coordinate, mirroring mailwoman's geocoder (`address_point` > `interpolated` >
33
- * `street` > `admin`). Kept as a local plain union so this package stays decoupled from the heavy geocoder runtime; a
34
- * `GeocodeResult.resolution_tier` maps in directly. (`street` = a street centroid for a street-only query, #1042 —
35
- * coarser than a house-number estimate, finer than an admin centroid.)
36
- */
37
- export type ResolutionTier = "address_point" | "interpolated" | "street" | "admin" | "venue" | "plus_code"
7
+ import type { ResolutionTier } from "@mailwoman/annotations/geo"
8
+ import { type ComponentDict, type FormatAddressOptions, formatAddress } from "@mailwoman/codex/address/format"
9
+ import { canonicalKey } from "@mailwoman/codex/address/key"
10
+ import type { GeoCoordinate } from "@mailwoman/spatial"
38
11
 
39
12
  /**
40
13
  * One resolved admin-hierarchy ancestor (most specific first), for spelling-invariant blocking.
@@ -51,47 +24,58 @@ export interface HierarchyNode {
51
24
  export interface AddressGeocode {
52
25
  coordinate: GeoCoordinate
53
26
  tier: ResolutionTier
27
+
54
28
  /**
55
- * Calibrated uncertainty radius in meters; `null` for the admin tier (no sub-locality estimate).
29
+ * Gives the uncertainty radius in meters.
30
+ *
31
+ * It is `null` on the admin tier and whenever the tier reports none.
56
32
  */
57
33
  uncertaintyMeters: number | null
34
+
58
35
  /**
59
- * Resolved admin hierarchy, locality → country (most specific first).
36
+ * Lists the resolved admin hierarchy from the locality up to the country.
60
37
  */
61
38
  hierarchy?: HierarchyNode[]
39
+
62
40
  /**
63
- * A delivery point, not a building — weakens location agreement even at a precise coordinate.
41
+ * Marks a delivery point, such as a PO box, rather than a building,
42
+ * so the coordinate does not locate the addressee.
64
43
  */
65
44
  poBox?: boolean
45
+
66
46
  /**
67
- * A multi-unit building where many records share one coordinate — weakens unit-level agreement.
47
+ * Marks a multi-unit building whose records share one coordinate,
48
+ * so the coordinate cannot distinguish units.
68
49
  */
69
50
  multiUnit?: boolean
70
51
  }
71
52
 
72
53
  /**
73
- * The canonical address record. Composes the parser's components, the formatter's match key, an optional human-readable
74
- * form, and an optional resolved geocode. Plain data — no behavior.
54
+ * Describes the canonical address record with parsed components plus a match key.
55
+ *
56
+ * It may also include formatted text, raw input or a resolved geocode.
75
57
  */
76
58
  export interface PostalAddress {
77
59
  /**
78
- * Parsed address components (`ComponentTag`-keyed).
60
+ * Holds the parsed address components keyed by component tag.
79
61
  */
80
62
  components: ComponentDict
63
+
81
64
  /**
82
- * Normalized, deterministic match key for blocking (from `@mailwoman/formatter`).
65
+ * Holds the normalized, deterministic match key used for blocking, built by
66
+ * `canonicalKey` from `@mailwoman/codex/address/key`.
83
67
  */
84
68
  canonicalKey: string
69
+
85
70
  /**
86
- * Optional human-readable single-line form, for display.
71
+ * Gives a human-readable single-line form for display.
87
72
  */
88
73
  formatted?: string
89
- /**
90
- * Resolved location, when geocoded.
91
- */
74
+
92
75
  geocode?: AddressGeocode
76
+
93
77
  /**
94
- * The original free-text input, when known (provenance).
78
+ * Keeps the original free-text input for provenance.
95
79
  */
96
80
  raw?: string
97
81
  }
@@ -101,26 +85,33 @@ export interface PostalAddress {
101
85
  */
102
86
  export interface ToPostalAddressOptions {
103
87
  /**
104
- * Country (ISO-2 or name) for formatting. Defaults to the `country` component, else unset.
88
+ * Supplies the country for formatting as an ISO-2 code or a name.
89
+ * It defaults to the `country` component.
105
90
  */
106
91
  country?: string
92
+
107
93
  /**
108
- * The original free-text input to retain as provenance.
94
+ * Supplies the original free-text input to keep as provenance.
109
95
  */
110
96
  raw?: string
97
+
111
98
  /**
112
- * Also compute a human-readable `formatted` string. Default `true`.
99
+ * Indicates whether to compute the `formatted` string.
100
+ * It defaults to `true`.
113
101
  */
114
102
  format?: boolean
103
+
115
104
  /**
116
- * Formatting options forwarded to the formatter. Defaults to single-line (`", "`).
105
+ * Passes options to the formatter, defaulting to a single line joined with `", "`.
117
106
  */
118
107
  formatOptions?: FormatAddressOptions
119
108
  }
120
109
 
121
110
  /**
122
- * Build a canonical {@linkcode PostalAddress} from parsed components: fills the match key (always) and a human-readable
123
- * form (unless disabled). Attach a geocode separately with {@linkcode withGeocode} once the address is resolved.
111
+ * Builds a {@linkcode PostalAddress} from parsed components, always filling the match key
112
+ * and, unless `format` is `false`, the formatted address.
113
+ *
114
+ * Attach a geocode separately with {@linkcode withGeocode}.
124
115
  */
125
116
  export function toPostalAddress(components: ComponentDict, opts: ToPostalAddressOptions = {}): PostalAddress {
126
117
  const country = opts.country ?? components.country ?? ""
package/lib/name.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { TextSpliterator } from "spliterator"
2
+
1
3
  /**
2
4
  * @copyright Sister Software
3
5
  * @license AGPL-3.0
@@ -14,19 +16,21 @@
14
16
  *
15
17
  * Scope + honesty (per the name-canonicalization research pass):
16
18
  *
17
- * - Western / romanized names only. Cultural given-family ORDER variation (East-Asian family-first)
19
+ * - Western / romanized names only. Cultural given-family order variation (East-Asian family-first)
18
20
  * and transliteration are not handled here — a documented follow-up.
19
- * - Nickname → canonical-root mapping is intentionally NOT done at parse time: it is lossy and
21
+ * - Nickname → canonical-root mapping is intentionally not done at parse time: it is lossy and
20
22
  * gendered (Bobbie → Robert _or_ Roberta), so equivalence belongs in the matcher as a fuzzy
21
- * agreement level, not a destructive rewrite. We only _extract_ a parenthetical/quoted
23
+ * agreement level rather than a destructive rewrite. We only _extract_ a parenthetical/quoted
22
24
  * nickname.
23
- * - A CRF parser (probablepeople) is the gold-standard reference but too heavy to port; this
25
+ * - A CRF parser (probablepeople) is the gold-standard reference but too heavy to port. this
24
26
  * positional parser covers the documented hard cases (inversion, particles, generational +
25
27
  * professional suffixes) without a model.
26
28
  */
27
29
 
28
30
  /**
29
- * A parsed person name. All fields optional — the parser fills what it can identify.
31
+ * A parsed person name.
32
+ *
33
+ * All fields optional — the parser fills what it can identify.
30
34
  */
31
35
  export interface PersonName {
32
36
  /**
@@ -60,7 +64,9 @@ export interface PersonName {
60
64
  }
61
65
 
62
66
  /**
63
- * Titles / salutations that lead a name. Matched case-insensitively, trailing `.` ignored.
67
+ * Titles / salutations that lead a name.
68
+ *
69
+ * Matched case-insensitively, trailing `.` ignored.
64
70
  */
65
71
  const TITLES = new Set([
66
72
  "airman",
@@ -161,8 +167,10 @@ const SUFFIXES = new Set([
161
167
  ])
162
168
 
163
169
  /**
164
- * Surname particles. Consecutive particles fold together (`de` + `la` → `de la`), and the next non-particle token
165
- * begins the bare surname.
170
+ * Surname particles.
171
+ *
172
+ * Consecutive particles fold together (`de` + `la` → `de la`), and the next
173
+ * non-particle token begins the bare surname.
166
174
  */
167
175
  const PARTICLES = new Set([
168
176
  "al",
@@ -204,8 +212,10 @@ const norm = (token: string): string => token.replace(/\.$/, "").toLowerCase()
204
212
  const countChar = (s: string, c: string): number => s.split(c).length - 1
205
213
 
206
214
  /**
207
- * Parse a full name into components. Returns `null` for empty input. Best-effort and non-throwing — ambiguous input
208
- * degrades gracefully rather than erroring.
215
+ * Parse a full name into components.
216
+ *
217
+ * @returns `null` for empty input.
218
+ * Best-effort and non-throwing — ambiguous input degrades gracefully rather than erroring.
209
219
  */
210
220
  export function parsePersonName(input: string | null | undefined): PersonName | null {
211
221
  if (!isPresent(input)) return null
@@ -234,7 +244,7 @@ export function parsePersonName(input: string | null | undefined): PersonName |
234
244
  // 2. Resolve a single comma: "Last, First" inversion, unless the tail is a known suffix
235
245
  // ("John Smith, Jr."), in which case keep order and treat the tail as a suffix.
236
246
  if (countChar(working, ",") === 1) {
237
- const [head, tail] = working.split(",").map((p) => p.trim())
247
+ const [head, tail] = TextSpliterator.from(working, { delimiter: "," }).toArray()
238
248
 
239
249
  if (tail && tail.split(/\s+/).every((t) => SUFFIXES.has(norm(t)))) {
240
250
  result.suffix = tail
@@ -244,11 +254,11 @@ export function parsePersonName(input: string | null | undefined): PersonName |
244
254
  }
245
255
  }
246
256
 
247
- const tokens = working.split(/\s+/).filter((value) => value.length > 0)
257
+ const tokens = working.split(/\s+/).filter((value) => value.length)
248
258
 
249
259
  if (!tokens.length) return Object.keys(result).length ? result : null
250
260
 
251
- // 3. Leading titles → prefix.
261
+ // 3. Titles at the start become the prefix.
252
262
  const prefixParts: string[] = []
253
263
 
254
264
  while (tokens.length > 1 && TITLES.has(norm(tokens[0]!))) {
@@ -259,7 +269,7 @@ export function parsePersonName(input: string | null | undefined): PersonName |
259
269
  result.prefix = prefixParts.join(" ")
260
270
  }
261
271
 
262
- // 4. Trailing suffixes → suffix (a single name token must remain).
272
+ // 4. Suffixes at the end become the suffix, while one name token must remain.
263
273
  const suffixParts: string[] = []
264
274
 
265
275
  while (tokens.length > 1 && SUFFIXES.has(norm(tokens.at(-1)!))) {
@@ -272,7 +282,8 @@ export function parsePersonName(input: string | null | undefined): PersonName |
272
282
 
273
283
  if (!tokens.length) return result
274
284
 
275
- // 5. Locate the surname particle run; everything from it onward is the (particled) surname.
285
+ // 5. Locate the surname particle run.
286
+ // Everything from it onward is the (particled) surname.
276
287
  let particleStart = -1
277
288
 
278
289
  for (let i = 0; i < tokens.length; i++) {
@@ -327,14 +338,18 @@ export function parsePersonName(input: string | null | undefined): PersonName |
327
338
  }
328
339
 
329
340
  /**
330
- * The ORDER a person name prints in. Western / romanized only, the same scope {@linkcode parsePersonName} declares: a
331
- * family-first system is not this order reversed, and inventing one here would be worse than having none.
341
+ * The order a person name prints in.
342
+ *
343
+ * Western / romanized only, the same scope {@linkcode parsePersonName} declares.
344
+ * A family-first system does not use this order in reverse.
345
+ * An invented order here would be worse than having none.
332
346
  */
333
347
  const NAME_ORDER: readonly (keyof PersonName)[] = ["prefix", "given", "middle", "familyParticle", "family", "suffix"]
334
348
 
335
349
  /**
336
- * The parts {@linkcode formatPersonName} prints for the short style — what a person is addressed by, without the title,
337
- * the nickname or the letters after.
350
+ * The parts {@linkcode formatPersonName} prints for the short style.
351
+ *
352
+ * What a person is addressed by, without the title, the nickname or the letters after.
338
353
  */
339
354
  const SHORT_NAME_ORDER: readonly (keyof PersonName)[] = ["given", "familyParticle", "family"]
340
355
 
@@ -346,12 +361,15 @@ export type PersonNameStyle = "full" | "short"
346
361
  /**
347
362
  * Render a {@linkcode PersonName} back to a string — the inverse of {@linkcode parsePersonName}.
348
363
  *
349
- * `"full"` prints every part the parser identified except the nickname, which is an alternative to the given name
350
- * rather than an addition to it. `"short"` prints what a person is addressed by, which is the form a display label and
351
- * a match key want.
364
+ * `"full"` prints every part the parser identified except the nickname.
365
+ * A nickname is an alternative to the given name rather than an addition to it.
366
+ *
367
+ * `"short"` prints what a person is addressed by.
368
+ * Display labels and match keys use this form.
352
369
  *
353
- * The particle travels WITH the surname in both styles. The parser stores it separately so the matcher can compare
354
- * `Vega` independently of `de la`; printing them apart would produce a name nobody wrote.
370
+ * The particle travels with the surname in both styles.
371
+ * The parser stores it separately so the matcher can compare `Vega` independently of `de la`;
372
+ * printing them apart would produce a form absent from the input name.
355
373
  */
356
374
  export function formatPersonName(name: PersonName | null | undefined, style: PersonNameStyle = "full"): string {
357
375
  if (!name) return ""
@@ -3,42 +3,12 @@
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
- * Organization-name canonicalization — reduce a company name to a stable, comparable key.
7
- *
8
- * Winkler's record-linkage recipe: words of little distinguishing power (the legal designation —
9
- * `Corporation`, `Limited`, `LLC`) are normalized away before matching, so `Acme Corp` and `Acme
10
- * Corporation, LLC` collapse to the same key. We also split off a `doing business as` clause and
11
- * normalize connectives (`&` → `and`), punctuation, accents, and a leading `The`.
12
- *
13
- * **The collision problem (#668).** A legal-form token in one jurisdiction is a meaningful word in
14
- * another domain. `PT` is Indonesia's `Perseroan Terbatas` (its LLC) — and US-healthcare
15
- * shorthand for _Physical Therapy_. `SCA` / `SCS` are French/Belgian/Luxembourg commandite forms
16
- * — and, in a clinic's name, _Sudden Cardiac Arrest_ / _Spinal Cord Stimulator_. A single
17
- * universal strip-list can't be right for both: strip `PT` and you corrupt `Lakeside PT`; keep it
18
- * and you leave the legal form on an Indonesian company. So the strip-set is computed on **two
19
- * axes**:
20
- *
21
- * - **jurisdiction** (ISO 3166-1 alpha-2, e.g. from the resolved address country) — _adds_ the legal
22
- * forms valid in that country. Collision-prone forms (`pt`, `sca`, `scs`) live here, admitted only
23
- * behind a known jurisdiction, NOT in the universal base.
24
- * - **domain** (an ingest-config tag, e.g. `healthcare`) — _protects_ domain-meaningful tokens from
25
- * ever being stripped, even when a jurisdiction pack would add them. Domain protection wins.
26
- *
27
- * `effective = (base ∪ jurisdiction-pack) − domain-protect-pack`. With no options the set is the
28
- * universal base and behavior is byte-for-byte unchanged — the new axes are strictly opt-in.
29
- *
30
- * Evidence honesty (per the name-canonicalization research pass): the PERSON-name side is well
31
- * sourced; the ORGANIZATION side is a known evidence gap. This is a solid _canonicalization_
32
- * baseline (the strip-designations principle is Winkler-grounded; the designation list draws on
33
- * the ISO 20275 Entity Legal Forms register and `cleanco`). The jurisdiction/domain packs below
34
- * are grounded seeds, not exhaustive — extend them per ISO 20275 as locales are added. The harder
35
- * org-_matching_ problems — acronym ↔ expansion (`IBM` ↔ `International Business Machines`),
36
- * DBA/alias resolution beyond the simple clause, subsidiary/parent, and TF-IDF n-gram token
37
- * matching — are deferred to a follow-up (a dedicated org-matching research pass + the matcher
38
- * epic).
6
+ * Canonicalizes organization names by removing legal designations. It normalizes DBA clauses plus punctuation and accents.
7
+ * It also folds connectives and leading articles. Jurisdiction adds local legal forms. Domain rules preserve
8
+ * ambiguous terms that could otherwise be stripped.
39
9
  */
40
10
 
41
- import { foldForKey } from "@mailwoman/codex/address-key"
11
+ import { foldForKey } from "@mailwoman/codex/address/key"
42
12
 
43
13
  /**
44
14
  * A canonicalized organization name.
@@ -63,36 +33,42 @@ export interface OrganizationName {
63
33
  }
64
34
 
65
35
  /**
66
- * A domain pack name. Each protects the abbreviations that are meaningful in that domain from being stripped as legal
67
- * forms (see {@link DOMAIN_PROTECTED}). `general` protects nothing — the explicit "no domain" choice. Add a pack here
68
- * (and to {@link DOMAIN_PROTECTED}) per ingest domain.
36
+ * Names a domain pack.
37
+ *
38
+ * Each pack leaves domain-specific abbreviations in the organization name
39
+ * instead of stripping them as legal forms.
40
+ * The `general` pack adds no domain-specific abbreviations.
69
41
  */
70
42
  export type DesignationDomain = "general" | "healthcare"
71
43
 
72
44
  /**
73
- * Context for {@link canonicalizeOrganizationName}. Omit both fields for the universal base behavior.
45
+ * Context for {@link canonicalizeOrganizationName}; omit both fields for the universal base behavior.
74
46
  */
75
47
  export interface CanonicalizeOptions {
76
48
  /**
77
- * ISO 3166-1 alpha-2 country code of the org's jurisdiction (typically the resolved address country). Adds that
78
- * country's legal forms — including collision-prone ones held out of the base — to the strip-set. Case-insensitive;
79
- * unknown codes add nothing.
49
+ * ISO 3166-1 alpha-2 country code for the organization's jurisdiction.
50
+ *
51
+ * Its country pack adds that jurisdiction's legal forms to the strip set.
52
+ * The comparison ignores case.
53
+ * Unknown codes add no pack.
80
54
  */
81
55
  jurisdiction?: string
82
56
  /**
83
- * Ingest domain. Protects domain-meaningful abbreviations (e.g. `healthcare` protects `pt` / `sca` / `scs`) from
84
- * being stripped, overriding any jurisdiction pack that would add them.
57
+ * Ingest domain that keeps domain-specific abbreviations in organization names.
58
+ *
59
+ * The `healthcare` domain leaves `pt` in the name.
60
+ * It also leaves `sca` and `scs`.
61
+ * These rules take precedence over jurisdiction packs.
85
62
  */
86
63
  domain?: DesignationDomain
87
64
  }
88
65
 
89
66
  /**
90
- * Universal legal-entity designations — the forms that are safe to strip regardless of jurisdiction or domain because
91
- * they don't collide with common domain abbreviations. Normalized to lowercase with punctuation removed (so `L.L.C.` →
92
- * `llc`). Drawn from the ISO 20275 register + `cleanco`'s common set. Stripped as whole tokens wherever they occur.
93
- * Deliberately excludes name-meaningful words (`group`, `holdings`, `partners`, `associates`) AND the collision-prone
94
- * forms (`pt`, `sca`, `scs`) — those last live in {@link JURISDICTION_DESIGNATIONS}, admitted only behind a known
95
- * jurisdiction.
67
+ * Universal legal-entity designations, normalized to lowercase without punctuation
68
+ * and stripped as whole tokens.
69
+ *
70
+ * Name-meaningful words and the collision-prone forms that live in
71
+ * {@link JURISDICTION_DESIGNATIONS} are deliberately absent.
96
72
  */
97
73
  const BASE_DESIGNATIONS = new Set([
98
74
  "inc",
@@ -144,16 +120,14 @@ const BASE_DESIGNATIONS = new Set([
144
120
  "doo",
145
121
  "ood",
146
122
  "ead",
147
- // Belgian forms — safe to add to the base (no domain collision).
123
+ // Belgian forms, safe in the base because they collide with no domain.
148
124
  "bvba",
149
125
  "sprl",
150
126
  ])
151
127
 
152
128
  /**
153
- * Jurisdiction-conditional legal forms (ISO 3166-1 alpha-2 → forms), added only when the jurisdiction is known. This is
154
- * where the collision-prone tokens live: `pt` (Indonesia), `sca` / `scs` (French/Belgian/Luxembourg commandite forms).
155
- * Stripping these is correct ONLY when we know the org's country — never in the universal base. Grounded seeds, not
156
- * exhaustive; extend per ISO 20275.
129
+ * Jurisdiction-conditional legal forms (ISO 3166-1 alpha-2 → forms) added only when the jurisdiction
130
+ * is known, holding the collision-prone tokens (`pt`, `sca`, `scs`) that the base must not strip.
157
131
  */
158
132
  const JURISDICTION_DESIGNATIONS: Record<string, readonly string[]> = {
159
133
  ID: ["pt", "tbk", "ud"], // Perseroan Terbatas / Terbuka (listed) / Usaha Dagang
@@ -165,10 +139,8 @@ const JURISDICTION_DESIGNATIONS: Record<string, readonly string[]> = {
165
139
  }
166
140
 
167
141
  /**
168
- * Domain protect-sets (domain → tokens never stripped). Overrides any jurisdiction pack: a token here stays in the name
169
- * even if the org's jurisdiction would treat it as a legal form. `healthcare` guards the clinical abbreviations that
170
- * collide with jurisdiction-conditional legal forms — `pt` (Physical Therapy), `sca` (Sudden Cardiac Arrest), `scs`
171
- * (Spinal Cord Stimulator) — plus a couple of always-clinical ones for future-proofing.
142
+ * Domain guard-sets (domain → tokens never stripped) that override any jurisdiction pack,
143
+ * e.g. `healthcare` keeps `pt`, `sca`, and `scs` from being stripped as legal forms.
172
144
  */
173
145
  const DOMAIN_PROTECTED: Record<DesignationDomain, readonly string[]> = {
174
146
  general: [],
@@ -176,9 +148,10 @@ const DOMAIN_PROTECTED: Record<DesignationDomain, readonly string[]> = {
176
148
  }
177
149
 
178
150
  /**
179
- * Compute the effective designation strip-set for the given context: `(base ∪ jurisdiction-pack) −
180
- * domain-protect-pack`. Returns the shared base set unchanged when no context is given (the byte-stable default), so
181
- * the common path allocates nothing.
151
+ * Compute the effective strip-set `(base ∪ jurisdiction-pack) − domain-guard-pack`.
152
+ *
153
+ * @returns the shared base set unchanged when no context is given (the byte-stable default),
154
+ * so the common path allocates no set.
182
155
  */
183
156
  function resolveDesignations(options?: CanonicalizeOptions): ReadonlySet<string> {
184
157
  const jurisdiction = options?.jurisdiction?.trim().toUpperCase()
@@ -210,8 +183,10 @@ function resolveDesignations(options?: CanonicalizeOptions): ReadonlySet<string>
210
183
  const DBA_PATTERN = /\s+(?:d\/b\/a|dba|doing business as|t\/a|trading as|a\/k\/a|aka|fka|f\/k\/a)\s+/i
211
184
 
212
185
  /**
213
- * Canonicalize one name fragment: lowercase, strip accents, connectives → `and`, drop punctuation, remove a leading
214
- * `the`, strip legal designations, collapse whitespace. Returns the key plus the designations it removed.
186
+ * Canonicalize one name fragment: lowercase, strip accents, connectives → `and`,
187
+ * drop punctuation, remove a leading `the`, strip legal designations, collapse whitespace.
188
+ *
189
+ * @returns the key plus the designations it removed.
215
190
  */
216
191
  function canonicalizeFragment(
217
192
  fragment: string,
@@ -236,12 +211,11 @@ function canonicalizeFragment(
236
211
  }
237
212
 
238
213
  /**
239
- * Canonicalize an organization name: split off any `doing business as` clause, then reduce the legal name to a
240
- * designation-stripped key. Returns `null` for empty input.
214
+ * Canonicalize an organization name: split off any `doing business as` clause,
215
+ * then reduce the legal name to a designation-stripped key.
241
216
  *
242
- * Pass {@link CanonicalizeOptions} to resolve the jurisdiction × domain collision (#668): a `jurisdiction` adds that
243
- * country's legal forms, a `domain` protects its meaningful abbreviations. With no options the universal base set is
244
- * used and the result is byte-for-byte the legacy behavior.
217
+ * Returns `null` for empty input. {@link CanonicalizeOptions} resolves conflicts
218
+ * between jurisdiction and domain rules.
245
219
  */
246
220
  export function canonicalizeOrganizationName(
247
221
  input: string | null | undefined,