@mailwoman/record 10.0.0 → 10.2.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.
@@ -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.
@@ -59,40 +29,46 @@ export interface OrganizationName {
59
29
  /**
60
30
  * The `doing business as` / trade-name clause, canonicalized, when one was present.
61
31
  */
62
- dba?: string
32
+ dba: string | null
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
- jurisdiction?: string
55
+ jurisdiction?: string | null
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,15 +211,14 @@ 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
- input: string | null | undefined,
221
+ input: string | null,
248
222
  options?: CanonicalizeOptions
249
223
  ): OrganizationName | null {
250
224
  if (typeof input !== "string" || !input.trim()) return null
@@ -255,15 +229,7 @@ export function canonicalizeOrganizationName(
255
229
 
256
230
  const { canonical, designations } = canonicalizeFragment(legalPart ?? "", designationSet)
257
231
 
258
- const result: OrganizationName = { raw, canonical, designations }
259
-
260
- if (dbaParts.length) {
261
- const dba = canonicalizeFragment(dbaParts.join(" "), designationSet).canonical
262
-
263
- if (dba) {
264
- result.dba = dba
265
- }
266
- }
232
+ const dba = dbaParts.length ? canonicalizeFragment(dbaParts.join(" "), designationSet).canonical : null
267
233
 
268
- return result
234
+ return { raw, canonical, designations, dba: dba || null }
269
235
  }
package/out/address.d.ts CHANGED
@@ -2,42 +2,18 @@
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
- */
19
- import { type ComponentDict, type FormatAddressOptions } from "@mailwoman/codex/address-format";
20
- /**
21
- * A geographic coordinate (WGS84 decimal degrees).
22
- */
23
- export interface GeoCoordinate {
24
- latitude: number;
25
- longitude: number;
26
- }
27
- /**
28
- * The resolution tier that produced a coordinate, mirroring mailwoman's geocoder (`address_point` > `interpolated` >
29
- * `street` > `admin`). Kept as a local plain union so this package stays decoupled from the heavy geocoder runtime; a
30
- * `GeocodeResult.resolution_tier` maps in directly. (`street` = a street centroid for a street-only query, #1042 —
31
- * coarser than a house-number estimate, finer than an admin centroid.)
32
5
  */
33
- export type ResolutionTier = "address_point" | "interpolated" | "street" | "admin" | "venue" | "plus_code";
6
+ import type { ResolutionTier } from "@mailwoman/annotations/geo";
7
+ import { type FormatAddressOptions } from "@mailwoman/codex/address/format";
8
+ import type { ComponentDict } from "@mailwoman/codex/address/render";
9
+ import type { GeoCoordinate } from "@mailwoman/spatial";
34
10
  /**
35
11
  * One resolved admin-hierarchy ancestor (most specific first), for spelling-invariant blocking.
36
12
  */
37
13
  export interface HierarchyNode {
38
14
  tag: string;
39
15
  value: string;
40
- placeID?: string;
16
+ placeID: string | null;
41
17
  }
42
18
  /**
43
19
  * A resolved geocode attached to an address record — the location signal the matcher scores on.
@@ -46,72 +22,81 @@ export interface AddressGeocode {
46
22
  coordinate: GeoCoordinate;
47
23
  tier: ResolutionTier;
48
24
  /**
49
- * Calibrated uncertainty radius in meters; `null` for the admin tier (no sub-locality estimate).
25
+ * Gives the uncertainty radius in meters.
26
+ *
27
+ * It is `null` on the admin tier and whenever the tier reports none.
50
28
  */
51
29
  uncertaintyMeters: number | null;
52
30
  /**
53
- * Resolved admin hierarchy, locality → country (most specific first).
31
+ * Lists the resolved admin hierarchy from the locality up to the country.
54
32
  */
55
- hierarchy?: HierarchyNode[];
33
+ hierarchy: HierarchyNode[] | null;
56
34
  /**
57
- * A delivery point, not a building — weakens location agreement even at a precise coordinate.
35
+ * Marks a delivery point, such as a PO box, rather than a building,
36
+ * so the coordinate does not locate the addressee.
58
37
  */
59
- poBox?: boolean;
38
+ poBox: boolean | null;
60
39
  /**
61
- * A multi-unit building where many records share one coordinate — weakens unit-level agreement.
40
+ * Marks a multi-unit building whose records share one coordinate,
41
+ * so the coordinate cannot distinguish units.
62
42
  */
63
- multiUnit?: boolean;
43
+ multiUnit: boolean | null;
64
44
  }
65
45
  /**
66
- * The canonical address record. Composes the parser's components, the formatter's match key, an optional human-readable
67
- * form, and an optional resolved geocode. Plain data — no behavior.
46
+ * Describes the canonical address record with parsed components plus a match key.
47
+ *
48
+ * It may also include formatted text, raw input or a resolved geocode.
68
49
  */
69
50
  export interface PostalAddress {
70
51
  /**
71
- * Parsed address components (`ComponentTag`-keyed).
52
+ * Holds the parsed address components keyed by component tag.
72
53
  */
73
54
  components: ComponentDict;
74
55
  /**
75
- * Normalized, deterministic match key for blocking (from `@mailwoman/formatter`).
56
+ * Holds the normalized, deterministic match key used for blocking, built by
57
+ * `canonicalKey` from `@mailwoman/codex/address/key`.
76
58
  */
77
59
  canonicalKey: string;
78
60
  /**
79
- * Optional human-readable single-line form, for display.
61
+ * Gives a human-readable single-line form for display.
80
62
  */
81
- formatted?: string;
63
+ formatted: string | null;
64
+ geocode: AddressGeocode | null;
82
65
  /**
83
- * Resolved location, when geocoded.
66
+ * Keeps the original free-text input for provenance.
84
67
  */
85
- geocode?: AddressGeocode;
86
- /**
87
- * The original free-text input, when known (provenance).
88
- */
89
- raw?: string;
68
+ raw: string | null;
90
69
  }
91
70
  /**
92
71
  * Options for {@linkcode toPostalAddress}.
93
72
  */
94
73
  export interface ToPostalAddressOptions {
95
74
  /**
96
- * Country (ISO-2 or name) for formatting. Defaults to the `country` component, else unset.
75
+ * Supplies the country for formatting as an ISO-2 code or a name.
76
+ *
77
+ * @defaultValue the `country` component.
97
78
  */
98
- country?: string;
79
+ country?: string | null;
99
80
  /**
100
- * The original free-text input to retain as provenance.
81
+ * Supplies the original free-text input to keep as provenance.
101
82
  */
102
- raw?: string;
83
+ raw?: string | null;
103
84
  /**
104
- * Also compute a human-readable `formatted` string. Default `true`.
85
+ * Indicates whether to compute the `formatted` string.
86
+ *
87
+ * @defaultValue `true`
105
88
  */
106
89
  format?: boolean;
107
90
  /**
108
- * Formatting options forwarded to the formatter. Defaults to single-line (`", "`).
91
+ * Passes options to the formatter, defaulting to a single line joined with `", "`.
109
92
  */
110
93
  formatOptions?: FormatAddressOptions;
111
94
  }
112
95
  /**
113
- * Build a canonical {@linkcode PostalAddress} from parsed components: fills the match key (always) and a human-readable
114
- * form (unless disabled). Attach a geocode separately with {@linkcode withGeocode} once the address is resolved.
96
+ * Builds a {@linkcode PostalAddress} from parsed components, always filling the match key
97
+ * and, unless `format` is `false`, the formatted address.
98
+ *
99
+ * Attach a geocode separately with {@linkcode withGeocode}.
115
100
  */
116
101
  export declare function toPostalAddress(components: ComponentDict, opts?: ToPostalAddressOptions): PostalAddress;
117
102
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../lib/address.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,oBAAoB,EAAiB,MAAM,iCAAiC,CAAA;AAG9G;;GAEG;AACH,MAAM,WAAW,aAAa;IAC7B,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;CACjB;AAED;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,eAAe,GAAG,cAAc,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,WAAW,CAAA;AAE1G;;GAEG;AACH,MAAM,WAAW,aAAa;IAC7B,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,UAAU,EAAE,aAAa,CAAA;IACzB,IAAI,EAAE,cAAc,CAAA;IACpB;;OAEG;IACH,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAA;IAChC;;OAEG;IACH,SAAS,CAAC,EAAE,aAAa,EAAE,CAAA;IAC3B;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;IACf;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC7B;;OAEG;IACH,UAAU,EAAE,aAAa,CAAA;IACzB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAA;IACpB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;OAEG;IACH,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;CACZ;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACtC;;OAEG;IACH,OAAO,CAAC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EAAE,aAAa,CAAA;IAEzB;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAA;IAEpB;;OAEG;IACH,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IAExB,OAAO,EAAE,cAAc,GAAG,IAAI,CAAA;IAE9B;;OAEG;IACH,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACtC;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAEvB;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAEnB;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAEhB;;OAEG;IACH,aAAa,CAAC,EAAE,oBAAoB,CAAA;CACpC;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,aAAa,EAAE,IAAI,GAAE,sBAA2B,GAAG,aAAa,CAa3G;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,cAAc,GAAG,aAAa,CAEzF"}
package/out/address.js CHANGED
@@ -2,42 +2,25 @@
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
- import { formatAddress } from "@mailwoman/codex/address-format";
20
- import { canonicalKey } from "@mailwoman/codex/address-key";
6
+ import { formatAddress } from "@mailwoman/codex/address/format";
7
+ import { canonicalKey } from "@mailwoman/codex/address/key";
21
8
  /**
22
- * Build a canonical {@linkcode PostalAddress} from parsed components: fills the match key (always) and a human-readable
23
- * form (unless disabled). Attach a geocode separately with {@linkcode withGeocode} once the address is resolved.
9
+ * Builds a {@linkcode PostalAddress} from parsed components, always filling the match key
10
+ * and, unless `format` is `false`, the formatted address.
11
+ *
12
+ * Attach a geocode separately with {@linkcode withGeocode}.
24
13
  */
25
14
  export function toPostalAddress(components, opts = {}) {
26
15
  const country = opts.country ?? components.country ?? "";
27
- const record = {
16
+ const formatted = opts.format === false ? null : formatAddress(components, country, opts.formatOptions ?? { separator: ", " });
17
+ return {
28
18
  components,
29
19
  canonicalKey: canonicalKey(components),
20
+ formatted: formatted || null,
21
+ geocode: null,
22
+ raw: opts.raw ?? null,
30
23
  };
31
- if (opts.raw !== undefined) {
32
- record.raw = opts.raw;
33
- }
34
- if (opts.format !== false) {
35
- const formatted = formatAddress(components, country, opts.formatOptions ?? { separator: ", " });
36
- if (formatted) {
37
- record.formatted = formatted;
38
- }
39
- }
40
- return record;
41
24
  }
42
25
  /**
43
26
  * Attach (or replace) a resolved geocode on an address record, returning a new record.
@@ -1 +1 @@
1
- {"version":3,"file":"address.js","sourceRoot":"","sources":["../lib/address.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAiD,aAAa,EAAE,MAAM,iCAAiC,CAAA;AAC9G,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAoG3D;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,UAAyB,EAAE,IAAI,GAA2B,EAAE;IAC3F,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,UAAU,CAAC,OAAO,IAAI,EAAE,CAAA;IAExD,MAAM,MAAM,GAAkB;QAC7B,UAAU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SAAS,EAAE,SAAS,IAAI,IAAI;QAC5B,OAAO,EAAE,IAAI;QACb,GAAG,EAAE,IAAI,CAAC,GAAG,IAAI,IAAI;KACrB,CAAA;AACF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,MAAqB,EAAE,OAAuB;IACzE,OAAO,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,CAAA;AAC9B,CAAC"}
package/out/name.d.ts CHANGED
@@ -14,54 +14,59 @@
14
14
  *
15
15
  * Scope + honesty (per the name-canonicalization research pass):
16
16
  *
17
- * - Western / romanized names only. Cultural given-family ORDER variation (East-Asian family-first)
17
+ * - Western / romanized names only. Cultural given-family order variation (East-Asian family-first)
18
18
  * 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
19
+ * - Nickname → canonical-root mapping is intentionally not done at parse time: it is lossy and
20
20
  * 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
21
+ * agreement level rather than a destructive rewrite. We only _extract_ a parenthetical/quoted
22
22
  * nickname.
23
- * - A CRF parser (probablepeople) is the gold-standard reference but too heavy to port; this
23
+ * - A CRF parser (probablepeople) is the gold-standard reference but too heavy to port. this
24
24
  * positional parser covers the documented hard cases (inversion, particles, generational +
25
25
  * professional suffixes) without a model.
26
26
  */
27
27
  /**
28
- * A parsed person name. All fields optional — the parser fills what it can identify.
28
+ * A parsed person name.
29
+ *
30
+ * Every field is nullable.
31
+ * The parser fills what it can identify.
29
32
  */
30
33
  export interface PersonName {
31
34
  /**
32
35
  * Title / salutation that preceded the name (`Dr`, `Mr`, `Capt`).
33
36
  */
34
- prefix?: string;
37
+ prefix: string | null;
35
38
  /**
36
39
  * First / given name.
37
40
  */
38
- given?: string;
41
+ given: string | null;
39
42
  /**
40
43
  * Middle name(s) or initial.
41
44
  */
42
- middle?: string;
45
+ middle: string | null;
43
46
  /**
44
47
  * Surname, _without_ any particle (`Vega`, not `de la Vega`).
45
48
  */
46
- family?: string;
49
+ family: string | null;
47
50
  /**
48
51
  * Surname particle, stored separately (`de la`, `van der`, `von`).
49
52
  */
50
- familyParticle?: string;
53
+ familyParticle: string | null;
51
54
  /**
52
55
  * Generational or professional suffix (`Jr`, `III`, `PhD`, `MD`).
53
56
  */
54
- suffix?: string;
57
+ suffix: string | null;
55
58
  /**
56
59
  * A parenthetical or quoted nickname (`"Gob"` in `George "Gob" Bluth`).
57
60
  */
58
- nickname?: string;
61
+ nickname: string | null;
59
62
  }
60
63
  /**
61
- * Parse a full name into components. Returns `null` for empty input. Best-effort and non-throwing — ambiguous input
62
- * degrades gracefully rather than erroring.
64
+ * Parse a full name into components.
65
+ *
66
+ * @returns `null` for empty input.
67
+ * Best-effort and non-throwing — ambiguous input degrades gracefully rather than erroring.
63
68
  */
64
- export declare function parsePersonName(input: string | null | undefined): PersonName | null;
69
+ export declare function parsePersonName(input: string | null): PersonName | null;
65
70
  /**
66
71
  * How much of the name to print.
67
72
  */
@@ -69,12 +74,15 @@ export type PersonNameStyle = "full" | "short";
69
74
  /**
70
75
  * Render a {@linkcode PersonName} back to a string — the inverse of {@linkcode parsePersonName}.
71
76
  *
72
- * `"full"` prints every part the parser identified except the nickname, which is an alternative to the given name
73
- * rather than an addition to it. `"short"` prints what a person is addressed by, which is the form a display label and
74
- * a match key want.
77
+ * `"full"` prints every part the parser identified except the nickname.
78
+ * A nickname is an alternative to the given name rather than an addition to it.
79
+ *
80
+ * `"short"` prints what a person is addressed by.
81
+ * Display labels and match keys use this form.
75
82
  *
76
- * The particle travels WITH the surname in both styles. The parser stores it separately so the matcher can compare
77
- * `Vega` independently of `de la`; printing them apart would produce a name nobody wrote.
83
+ * The particle travels with the surname in both styles.
84
+ * The parser stores it separately so the matcher can compare `Vega` independently of `de la`;
85
+ * printing them apart would produce a form absent from the input name.
78
86
  */
79
- export declare function formatPersonName(name: PersonName | null | undefined, style?: PersonNameStyle): string;
87
+ export declare function formatPersonName(name: Partial<PersonName> | null, style?: PersonNameStyle): string;
80
88
  //# sourceMappingURL=name.d.ts.map
package/out/name.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"name.d.ts","sourceRoot":"","sources":["../lib/name.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CACjB;AAkJD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,UAAU,GAAG,IAAI,CAqHnF;AAcD;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,OAAO,CAAA;AAE9C;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,GAAG,SAAS,EAAE,KAAK,GAAE,eAAwB,GAAG,MAAM,CAe7G"}
1
+ {"version":3,"file":"name.d.ts","sourceRoot":"","sources":["../lib/name.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IAC1B;;OAEG;IACH,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB;;OAEG;IACH,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB;;OAEG;IACH,MAAM,EAAE,MAAM,GAAG,IA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