/** * Canonical phone normalisation: cotton-rules' `phone` * (crates/cotton-rules/src/phone.rs, the `phonenumber` crate), asked through * the rules module. The rows the Mac imported carry the ids its readings * made, and now the object reads a number with the very same crate and * metadata, so the two cannot differ. * * A number written with its country code (a leading `+` or `00`) is parsed and * kept as its E.164 digits, so the trunk 0 a person writes after the code goes. * A number without one stays its digits as typed, unless a region is given (the * owner's own number's country) and it is a valid number there. Either way the * result is 8–15 ASCII digits, no `+`, or null. */import { rule } from"../rules/index.ts";/** An ISO 3166 region code, as the rule names it ("IN", "GB"). */exporttypeRegion = string;/** Presentation (whitespace, `-`, `(`, `)`, `.`) out. */exportfunction stripPresentation(raw: string): string {return rule<string>("phone.strip", raw);}/** 8–15 ASCII digits, or null. */exportfunction normalizePhone(raw: string): string | null {return normalizePhoneIn(raw, null);}/** The region a canonical number is valid in, or null. */exportfunction regionOf(digits: string): Region | null {return rule<Region | null>("phone.region", digits);}/** `normalizePhone`, read in `region` when the number carries no country code. */exportfunction normalizePhoneIn(raw: string, region: Region | null): string | null {return rule<string | null>("phone.normalize", region === null ? { raw } : { raw, region });}