Reference
Parsing, formatting and shared types
import { … } from "@johnmorrisdotca/address-plus";
105.7 kB minified and gzipped, with everything it imports (measured with esbuild)
Exports
| Name | Kind | What it is |
|---|---|---|
AddressAbbreviations | type | What getAddressAbbreviations returns: one map per kind of abbreviation. |
AddressComparisonOptions | type | Options for comparing addresses: what to normalize before comparing, whether to allow small typos, and whether every field must match exactly. |
AddressComparisonResult | type | What compareAddresses returns: the verdict, the match type and the similarity. |
AddressComparisonTestCase | type | A comparison case in the package's JSON test files: two addresses and the match expected. |
AddressDifference | type | One part on which two addresses differ, with both values and the kind of difference. |
AddressFormattingOptions | type | Options for formatAddress and cleanAddress: what to abbreviate, capitals, the unit, the country and the line separator. |
AddressFormattingTestCase | type | A formatting case in the package's JSON test files: an address and the text expected. |
AddressMatchType | type | How strongly two addresses match, from exact to none. |
AddressParser | type | The shape of the default export: the four parsers parse-address's users call on one object. |
AddressParsingTestCase | type | A parsing case in the package's JSON test files: an address and the fields expected from it. |
AddressSimilarityResult | type | How alike two addresses are: an overall score from 0 to 1, a score for each part, and the differences. |
AddressValidationResult | type | What validateAddress returns. |
AddressValidationTestCase | type | A validation case in the package's JSON test files: an address and the verdict and codes expected. |
AustralianAddressFields | type | The fields an Australian address fills beside the shared ones. |
AustralianPostcodeRange | type | One block of postcodes Australia Post allocates to a state or territory: every postcode from from to to, inclusive, written as four digits. |
AustralianState | type | An Australian state or territory in the tables: Australia Post's code, the ISO 3166-2 code, and its name in English and in Japanese (from kuni, which takes them from Unicode CLDR and Wikidata). |
AustralianStateCode | type | The code of an Australian state or territory, as Australia Post writes it on the last line of an address. |
BatchParseError | type | One address a batch could not parse: its index, the input and the reason. |
BatchParseOptions | type | Options for the batch parsers: the parse options, plus whether to stop at the first error and whether to include the statistics. |
BatchParseResult | type | What a batch parser returns: the results in order, the errors and the statistics. |
BatchParseStats | type | The counts and timing of a batch: how many were parsed, how many failed, and how long it took. |
BatchProcessingTestCase | type | A batch case in the package's JSON test files: several addresses and the counts expected. |
buildRegexFromDict | function | A regular expression matching any key of a dictionary as a whole word, longest first. |
CA_PROVINCE_ALTERNATIVES | constant | Other ways Canadian provinces are written (old and informal abbreviations such as PQ, Que., Nfld.), in lower case, to their codes. |
CA_PROVINCE_NAMES | constant | Every Canadian province and territory by its English or French name, to its code. |
CA_PROVINCE_NAMES_EN | constant | Every Canadian province and territory by its English name in lower case, to its two-letter code. |
CA_PROVINCE_NAMES_FR | constant | Every Canadian province and territory by its French name in lower case, to its two-letter code. |
CA_PROVINCES | constant | Every name and other spelling of a Canadian province, to its code: the names and the alternatives together. |
CA_REGIONS | constant | Every name and other spelling of a Canadian province or territory as a Region object, for fuzzy matching by normalizeRegion. |
CA_STREET_TYPES | constant | Every street type Canada Post lists, in English and French, with common spellings, in lower case, to the abbreviation the parser reports. |
CanadaPostFormattingOptions | type | Options for formatCanadaPost: which lines to include, bilingual labels, and whether to set the letter case the Canada Post way. |
CANADIAN_POSTAL_CODE_PATTERN | constant | A Canadian postal code with the letters Canada Post assigns, with or without its space. |
CANADIAN_POSTAL_LIBERAL_PATTERN | constant | A Canadian postal code of any letters, for finding one before it is checked. |
capitalizeStreetName | function | Capitalizes a street name the way it is signed. |
capitalizeWords | function | Capitalizes the first letter of each word. |
CITY_PATTERNS | constant | Patterns for a city of one or more words at the end of a text, after a space, used where no comma marks it. |
cleanAddress | function | Tidies an address typed in a hurry: spaces, commas, letter case, the street type and the state, without changing what it says. |
cleanAddressDetailed | function | Tidies an address like cleanAddress, and says what it changed. |
CleanAddressOptions | type | Options for cleanAddress: which tidying to do, and the letter case to set. |
CleanAddressResult | type | What cleanAddressDetailed returns: the tidied address and what changed. |
CleanAddressTestCase | type | A cleaning case in the package's JSON test files: an address and the tidied text expected. |
COMMON_PARSER_PATTERNS | constant | Pattern builders the parsers share: a ZIP, a state or a postal code at the end of a text, and a city before a state. |
COMMON_STREET_NAMES_PATTERN | constant | Street names common enough that they must not be taken as part of a city's name. |
compareAddresses | function | Compares two parsed addresses field by field, allowing for abbreviations (Street and St), state names and codes, letter case and small typos. |
CONNECTOR_WORDS | constant | Small words (of, the, and) that may be in lower case inside a facility's name written in title case. |
COUNTRIES | constant | The country codes the parser reports: US, CA and JP. |
CountryCode | type | A country code the parser reports: US, CA or JP. |
CountryComparison | type | What a country module's comparer returns: whether the two addresses are the same delivery point, and every field that differs once both are in the same form (letter case, punctuation, a street type written out or abbreviated). |
CountryDifference | type | One way two addresses differ, as a country module's comparer reports it: the field, and its value in each address after both were put in the same form. |
CountryModule | type | A country's address module: its codes, how to tell its addresses apart, and its parser, validator, formatter and comparer. |
CountryValidation | type | What a country module's validator returns: the errors and the warnings it found. |
default | constant | The default export, shaped like parse-address's module: parseLocation, parseAddress, parseIntersection and parseInformalAddress on one object, so import parser from "@johnmorrisdotca/address-plus" works where parse-address was imported. |
detectCountry | function | Which country a parsed address is in, from its postal code, then its state or province. |
DIRECTION_EXPANSIONS | constant | Each directional abbreviation in lower case, to the word in full. |
DIRECTIONAL_MAP | constant | Each directional word, in English or French, in lower case, to its abbreviation (northwest and nord-ouest to NW and NO). |
FACILITY_DELIMITER_PATTERN | constant | A facility's name followed by a comma or a dash and then the address. |
FACILITY_DELIMITER_PATTERNS | constant | The ways a facility's name is set off from an address: in parentheses, before a delimiter, or as a trailing island. |
FACILITY_INDICATORS | constant | Words that mark a place's name as a facility (center, tower, hospital, université), in lower case. |
FACILITY_PATTERNS | constant | The patterns that find a facility's name, in English and French. |
findMunicipalitiesByName | function | The municipalities a Japanese name could mean: several when the name is shared (府中市 is in Tokyo and in Hiroshima). |
findMunicipalitiesByRomaji | function | The municipalities a romaji name could mean, written with or without macrons and designators (Chiyoda-ku, Chiyoda City, Sapporo-shi Chuo-ku, Chuo-ku, Sapporo). |
findMunicipalityByCode | function | The municipality with a JIS X 0402 code, a designated city's own code included. |
findPrefecture | function | The prefecture a name, reading, romaji spelling or JIS code refers to: 東京都, 東京, トウキョウト, Tokyo, Osaka Prefecture, 13. |
formatAddress | function | Writes a parsed address back out as lines and as one line, with abbreviations or in full. |
formatCanadaPost | function | Writes a parsed address the way Canada Post asks: capitals, the unit before the civic number joined by a hyphen, and the postal code two spaces after the province. |
formatJapanese | function | Writes a Japanese address in Japanese order, as an envelope is addressed: 〒100-0005, then 東京都千代田区丸の内1-2-3, then サンプルビル5階501号室. |
formatJapaneseEnglish | function | Writes a Japanese address in English order, as a form from abroad expects: building, room, block, town, municipality, prefecture, postal code, Japan. |
FormattedAddress | type | A formatted address: its lines, and the same on one line. |
formatUSPS | function | Writes a parsed address the way USPS Publication 28 asks: capitals, standard abbreviations, the unit on the street line, and the city, state and ZIP+4 on the last. |
FRENCH_PREPOSITIONS | constant | French particles that can open a street name, each with the space after it, to the way it is written there (de la as De la ). |
FrenchAddressFields | type | The fields an address in France fills beside the shared ones. |
FrenchCollectivity | type | An overseas collectivity of France in the tables: its code (987), the ISO 3166-1 country code an address in it reads as (PF) and its name. |
FrenchDepartment | type | A department of France in the tables: its code (75, 2A, 971), its name and its region's, from INSEE's Code officiel géographique. |
FrenchPostalCountry | type | The country an address in La Poste's base belongs to: FR for France (the metropolis and the overseas departments), MC for Monaco, and the ISO 3166-1 code of an overseas collectivity (PM, BL, MF, WF, PF, NC), which is French but has a country code of its own and is listed apart by the Universal Postal Union. |
FrenchPostcode | type | A postcode taken apart: the code of the department or territory its number belongs to, the country it delivers to, and whether La Poste's base has it. |
FuzzyMatchOptions | type | Settings for fuzzy string matching: the lowest similarity that counts, the largest edit distance, and phonetic matching. |
GENERAL_DELIVERY_PATTERNS | constant | General delivery written alone or before a city. |
GermanAddressFields | type | The fields an address in Germany fills beside the shared ones. |
GermanPostcode | type | A postcode taken apart: the Land it is in, and whether GeoNames' list has it. |
GermanState | type | A Land of Germany in the tables: its code, its ISO 3166-2 code, and its name in English and in Japanese (from kuni, which takes them from Unicode CLDR and Wikidata). |
GermanStateCode | type | The code of one of the sixteen Länder of Germany, as ISO 3166-2:DE writes it after DE-. |
getAddressAbbreviations | function | Every abbreviation the formatters use: street types, directionals, secondary units, states and provinces. |
getAddressSimilarity | function | The similarity of two parsed addresses, part by part, without a verdict: the score and each part's score, and the differences. |
getPostalPrefixesForPrefecture | function | The three-digit postal prefixes a prefecture's codes begin with, the reverse of getPrefectureFromJapanesePostalCode. |
getPostalPrefixesForProvince | function | The postal code prefixes a province or territory uses, the reverse of getProvinceFromPostalCode. |
getPrefectureFromJapanesePostalCode | function | The prefecture a Japanese postal code delivers to, from Japan Post's data: by its first three digits, and for the codes on the far side of a prefix that straddles a border, by the whole code. |
getProvinceFromPostalCode | function | The province or territory a Canadian postal code is in, from its first letter, and for the X codes of the north, its first three characters. |
getStateFromZip | function | The state or territory a US ZIP code is in. |
getValidationErrors | function | The errors validateAddress finds, without the rest of its result. |
getZipPrefixesForState | function | The ZIP code prefixes a state or territory uses, the reverse of getStateFromZip: three digits where a whole block of a hundred belongs to it, five where only part of one does. |
hasValidAddressComponents | function | Whether a string looks like an address at all: a number and a street, a PO box, a postal code or another recognised part. |
INTERSECTION_PATTERNS | constant | The regular expressions and pattern builders the intersection parser uses to find the city and each street with its type. |
ISLAND_TYPE_PATTERN | constant | The words for an island, for addresses on one (Island, Isle, Île). |
isSameAddress | function | Whether two parsed addresses are the same place, by the same rules as compareAddresses. |
isValidAddress | function | Whether an address passes validateAddress. |
JapaneseAddressFields | type | The fields a Japanese address fills on top of the shared ones. |
JapaneseEnglishFormattingOptions | type | Options for formatJapaneseEnglish. |
JapaneseFormattingOptions | type | Options for formatJapanese. |
JapaneseMunicipality | type | A municipality (市区町村) in the tables: its JIS code, its prefecture's code, its official name with the district for a town or village in one, its reading and its romaji. |
JapanesePrefecture | type | A prefecture (都道府県) in the tables: its JIS code, official name, katakana reading and romaji. |
JapaneseValidation | type | What validateJapaneseAddress returns: the errors and the warnings found. |
JP_DESIGNATED_CITIES | constant | The twenty designated cities (政令指定都市) as municipalities of their own. |
JP_MUNICIPALITIES | constant | Every municipality (市区町村) by JIS X 0402 code, with its prefecture, official name, reading and romaji; a designated city's wards are listed, and the city itself is in JP_DESIGNATED_CITIES. |
JP_POSTAL_EXCEPTIONS | constant | The postal codes that deliver to another prefecture than the rest of their three-digit prefix, each to that prefecture's JIS code. |
JP_POSTAL_PREFIXES | constant | Each three-digit postal prefix, to the JIS code of the prefecture most of its codes deliver to. |
JP_PREFECTURES | constant | The 47 prefectures in JIS X 0401 order, each with its code, official name, katakana reading and romaji. |
kanjiNumeralsToDigits | function | Turns the kanji numerals that stand for block, floor or room numbers into digits: 一丁目二番三号 becomes 1丁目2番3号. |
looksJapanese | function | Whether a text is a Japanese address: in Japanese script, ending with Japan, or naming a prefecture beside a Japanese postal code, a romaji designator (-ku, -shi) or a municipality written with an English word (Chiyoda City). |
municipalitiesOf | function | Every municipality of a prefecture, the designated cities included. |
MUSIC_SQUARE_EAST_PATTERN | constant | Nashville's Music Square East, whose name ends in a directional word that is part of it. |
normalizeJapaneseAddressText | function | Makes the text of a Japanese address uniform, as the parser reads it: widths folded, spaces tidied, numerals as digits, and 1の2の3, 1-2-3 or any other dash written 1-2-3. |
normalizeRegion | function | Finds the US state or Canadian province a name, code or misspelling means: Calfornia, Que., British Columbia, nfld. |
normalizeStateProvinceName | function | The code of a US state or Canadian province written in full, in lower case. |
normalizeText | function | Lower-cases a string, turns its periods, commas and semicolons into spaces, folds runs of spaces to one and trims it: the form the parsers compare words in. |
PARENTHETICAL_PATTERN | constant | Words in parentheses inside an address; group 1 is what is inside them. |
parseAddress | function | Parses a street address. |
parseAddresses | function | Parses many street addresses with parseAddress, in order. |
parseAddressesBatch | function | Parses many street addresses with parseAddress, and reports which failed and how long it took. |
ParsedAddress | type | What parseLocation returns: every part it found, each absent when the address has none. |
ParsedIntersection | type | What parseIntersection returns: two streets, each with its name, type and directionals, and the place. |
parseDirectional | function | Takes a leading directional off a street (NW Main St), abbreviated. |
parseFacility | function | Takes a facility's name (a building, a park, a hospital) off the start of an address. |
parseInformalAddress | function | Reads an address written loosely, as a fallback when parseLocation finds no street address: a description such as Downtown near City Hall is kept whole as the street, with any ZIP code after it. |
parseInformalAddresses | function | Parses many loosely written addresses with parseInformalAddress, in order. |
parseInformalAddressesBatch | function | Parses many loosely written addresses with parseInformalAddress, and reports which failed and how long it took. |
parseIntersection | function | Parses an intersection of two streets, joined by &, and, at or @, with the city, state and ZIP that may follow. |
parseIntersections | function | Parses many intersections with parseIntersection, in order. |
parseIntersectionsBatch | function | Parses many intersections with parseIntersection, and reports which failed and how long it took. |
parseJapaneseAddress | function | Parses a Japanese address, in Japanese script or in romaji, into the Japanese fields and the shared ones. |
parseLocation | function | Parses a US, Canadian or Japanese address into its parts. |
parseLocations | function | Parses many addresses with parseLocation, in order. |
parseLocationsBatch | function | Parses many addresses with parseLocation, and reports which failed and how long it took. |
ParseOptions | type | Options for every parser: the country, strict postal codes, snake_case keys and the rest. |
parseParenthetical | function | Takes words in parentheses out of an address, such as (Rear Entrance). |
parsePostalCode | function | Takes a ZIP code, ZIP+4 or Canadian postal code off the end of a text. |
parseSecondaryUnit | function | Takes a secondary unit (apartment, suite, floor and the rest) off a street line. |
parseStateProvince | function | Takes a US state or Canadian province off the end of a text, by code or by name. |
parseStreetNumber | function | Takes the house number off the start of a street line, with a fraction or a letter if it has one. |
parseStreetType | function | Takes the street type off the end of a street, abbreviated the USPS way. |
PO_BOX_PATTERNS | constant | The regular expressions the PO box parser uses: the box itself, a station after it, a box number first, and a trailing comma. |
POSTAL_CODE_TO_PROVINCE | constant | Each first letter of a Canadian postal code, to the province or territory it is assigned to. |
PostalValidationResult | type | What validatePostalCode returns: whether the code is well formed, its type, and the code written the standard way. |
PROVINCE_EXPANSIONS | constant | Each Canadian province's code in lower case, to its name in lower case: English by default, the French names under their own keys. |
PROVINCE_EXPANSIONS_EN | constant | Each Canadian province's code in lower case, to its English name in lower case. |
PROVINCE_EXPANSIONS_FR | constant | Each Canadian province's code in lower case, to its French name in lower case. |
Region | type | A US state or Canadian province: its code, its country and its name, as normalizeRegion matches them. |
SECONDARY_UNIT_PATTERN | constant | A unit at the end of a street line: group 1 is the street before it, group 2 the unit. |
SECONDARY_UNIT_TYPES | constant | Each secondary unit designator, abbreviated or in full, in lower case, to the word the parser reports in full: USPS Publication 28 Appendix C2, and Canada Post's French unit words, which stay French. |
setValidatedPostalCode | function | Sets a ZIP or postal code on a result, the way the parsers do: split into ZIP and ZIP+4, a Canadian code in capitals with one space, with zipValid set, and in strict mode only when the code is well formed. |
StateCode | type | A US state, DC or territory code that getStateFromZip can return. |
STREET_NAME_ACRONYMS | constant | Acronyms written in capitals inside a street name (US, FBI), from their lower-case form, for capitalizeStreetName. |
STREET_TYPE_DETECTION_PATTERN | constant | Whether a text has a common street type in it, used to judge that a parse found a street. |
STREET_TYPE_EXPANSIONS | constant | Each USPS street type abbreviation in lower case, to the word in full. |
STREET_TYPE_PROPER_CASE | constant | Each street type abbreviation in lower case, to the way the parser reports it (Ave, Xing). |
SubRegion | type | An administrative part of a city (a borough, a parish, a ward, an arrondissement) that may be written where the city is expected. |
TERRITORY_POSTAL_PREFIXES | constant | The first three characters of each territory's postal codes, since the territories share a first letter. |
TERRITORY_POSTAL_RANGES | constant | The patterns that tell the Northwest Territories' X codes from Nunavut's, by their first three characters. |
TestCase | type | Any case in the package's JSON test files. |
TestCaseBase | type | The fields every case in the package's JSON test files has: a name or description, the input, what is expected and the options. |
UKAddressFields | type | The fields an address in the United Kingdom fills beside the shared ones. |
UKNation | type | A nation of the United Kingdom in the tables: its code, its ISO 3166-2 code, and its name in English and in Japanese (from kuni, which takes them from Unicode CLDR and Wikidata). |
UKNationCode | type | The code of one of the four nations of the United Kingdom, as ISO 3166-2:GB writes it after GB-. |
UKPostcode | type | A postcode taken apart: the outward code (area and district) and the inward code (sector and unit), and where it delivers. |
UNIT_TYPE_KEYWORDS | constant | The secondary unit designators that take a value after them, as one alternation for a regular expression, longest first so that apartment is tried before apt: USPS Publication 28 Appendix C2, Canada Post's English and French unit words, and a few spellings people write. |
UNIT_TYPE_NUMBER_PATTERN | constant | A unit's designator and value: groups 1 and 2 (apt 123, `Apt. |
US_REGIONS | constant | Every name and other spelling of a US state, DC or territory as a Region object, for fuzzy matching by normalizeRegion. |
US_STATE_ALTERNATIVES | constant | Other ways US states are written (shortened forms, old abbreviations, D.C.), in lower case, to their codes. |
US_STATE_EXPANSIONS | constant | Each US state's code in lower case, to its name in lower case: the reverse of US_STATE_NAMES. |
US_STATE_NAMES | constant | Every US state, DC and territory by its name in lower case, to its two-letter code. |
US_STATES | constant | Every name and other spelling of a US state in lower case, to its code: US_STATE_NAMES and US_STATE_ALTERNATIVES together. |
US_STREET_TYPES | constant | Every street type USPS Publication 28 lists, and the common spellings of each, in lower case, to its USPS abbreviation in lower case. |
USPSFormattingOptions | type | Options for formatUSPS: which lines to include, and whether to set the letter case the USPS way. |
validateAddress | function | Checks an address: whether it has what an address needs, whether its ZIP or postal code is well formed and belongs to the state, province or prefecture named, and how sure the parser is. |
validateJapaneseAddress | function | Checks a parsed Japanese address against the tables: the postal code's shape, whether any code begins with its first three digits, whether it delivers to the prefecture named, and whether the municipality is a real one in that prefecture. |
validatePostalCode | function | Checks the shape of a US ZIP code or a Canadian postal code. |
VALIDATION_PATTERNS | constant | Small regular expressions the validators share: letters, digits, a house number at the start, and the like. |
ValidationError | type | One finding of a validator: the field it is about, its code, a message, and how serious it is. |
ValidationOptions | type | Options for the validators: which parts an address must have, which kinds are allowed, and whether a postal code that does not match its region is an error. |
WRITTEN_NUMBERS | constant | House numbers written as words (One, Twenty), as one alternation for a regular expression, so One Microsoft Way is read as number 1. |
ZIP_CODE_PATTERN | constant | A US ZIP code with an optional ZIP+4. |
ZIP_CODE_REGEX_PATTERN | constant | The source of ZIP_CODE_PATTERN, for building larger patterns. |
ZIP_VALIDATION_PATTERNS | constant | The shape of something that could be a ZIP code. |