Skip to the content

address-plusアドレスプラス

Parse, validate, format and compare addresses locally, add country modules and mount an optional native form field.

address-plus extends the parse-address style with typed results, validation, formatting and country modules. About the name

Contents

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

NameKindWhat it is
AddressAbbreviationstypeWhat getAddressAbbreviations returns: one map per kind of abbreviation.
AddressComparisonOptionstypeOptions for comparing addresses: what to normalize before comparing, whether to allow small typos, and whether every field must match exactly.
AddressComparisonResulttypeWhat compareAddresses returns: the verdict, the match type and the similarity.
AddressComparisonTestCasetypeA comparison case in the package's JSON test files: two addresses and the match expected.
AddressDifferencetypeOne part on which two addresses differ, with both values and the kind of difference.
AddressFormattingOptionstypeOptions for formatAddress and cleanAddress: what to abbreviate, capitals, the unit, the country and the line separator.
AddressFormattingTestCasetypeA formatting case in the package's JSON test files: an address and the text expected.
AddressMatchTypetypeHow strongly two addresses match, from exact to none.
AddressParsertypeThe shape of the default export: the four parsers parse-address's users call on one object.
AddressParsingTestCasetypeA parsing case in the package's JSON test files: an address and the fields expected from it.
AddressSimilarityResulttypeHow alike two addresses are: an overall score from 0 to 1, a score for each part, and the differences.
AddressValidationResulttypeWhat validateAddress returns.
AddressValidationTestCasetypeA validation case in the package's JSON test files: an address and the verdict and codes expected.
AustralianAddressFieldstypeThe fields an Australian address fills beside the shared ones.
AustralianPostcodeRangetypeOne block of postcodes Australia Post allocates to a state or territory: every postcode from from to to, inclusive, written as four digits.
AustralianStatetypeAn 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).
AustralianStateCodetypeThe code of an Australian state or territory, as Australia Post writes it on the last line of an address.
BatchParseErrortypeOne address a batch could not parse: its index, the input and the reason.
BatchParseOptionstypeOptions for the batch parsers: the parse options, plus whether to stop at the first error and whether to include the statistics.
BatchParseResulttypeWhat a batch parser returns: the results in order, the errors and the statistics.
BatchParseStatstypeThe counts and timing of a batch: how many were parsed, how many failed, and how long it took.
BatchProcessingTestCasetypeA batch case in the package's JSON test files: several addresses and the counts expected.
buildRegexFromDictfunctionA regular expression matching any key of a dictionary as a whole word, longest first.
CA_PROVINCE_ALTERNATIVESconstantOther ways Canadian provinces are written (old and informal abbreviations such as PQ, Que., Nfld.), in lower case, to their codes.
CA_PROVINCE_NAMESconstantEvery Canadian province and territory by its English or French name, to its code.
CA_PROVINCE_NAMES_ENconstantEvery Canadian province and territory by its English name in lower case, to its two-letter code.
CA_PROVINCE_NAMES_FRconstantEvery Canadian province and territory by its French name in lower case, to its two-letter code.
CA_PROVINCESconstantEvery name and other spelling of a Canadian province, to its code: the names and the alternatives together.
CA_REGIONSconstantEvery name and other spelling of a Canadian province or territory as a Region object, for fuzzy matching by normalizeRegion.
CA_STREET_TYPESconstantEvery street type Canada Post lists, in English and French, with common spellings, in lower case, to the abbreviation the parser reports.
CanadaPostFormattingOptionstypeOptions for formatCanadaPost: which lines to include, bilingual labels, and whether to set the letter case the Canada Post way.
CANADIAN_POSTAL_CODE_PATTERNconstantA Canadian postal code with the letters Canada Post assigns, with or without its space.
CANADIAN_POSTAL_LIBERAL_PATTERNconstantA Canadian postal code of any letters, for finding one before it is checked.
capitalizeStreetNamefunctionCapitalizes a street name the way it is signed.
capitalizeWordsfunctionCapitalizes the first letter of each word.
CITY_PATTERNSconstantPatterns for a city of one or more words at the end of a text, after a space, used where no comma marks it.
cleanAddressfunctionTidies an address typed in a hurry: spaces, commas, letter case, the street type and the state, without changing what it says.
cleanAddressDetailedfunctionTidies an address like cleanAddress, and says what it changed.
CleanAddressOptionstypeOptions for cleanAddress: which tidying to do, and the letter case to set.
CleanAddressResulttypeWhat cleanAddressDetailed returns: the tidied address and what changed.
CleanAddressTestCasetypeA cleaning case in the package's JSON test files: an address and the tidied text expected.
COMMON_PARSER_PATTERNSconstantPattern 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_PATTERNconstantStreet names common enough that they must not be taken as part of a city's name.
compareAddressesfunctionCompares two parsed addresses field by field, allowing for abbreviations (Street and St), state names and codes, letter case and small typos.
CONNECTOR_WORDSconstantSmall words (of, the, and) that may be in lower case inside a facility's name written in title case.
COUNTRIESconstantThe country codes the parser reports: US, CA and JP.
CountryCodetypeA country code the parser reports: US, CA or JP.
CountryComparisontypeWhat 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).
CountryDifferencetypeOne 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.
CountryModuletypeA country's address module: its codes, how to tell its addresses apart, and its parser, validator, formatter and comparer.
CountryValidationtypeWhat a country module's validator returns: the errors and the warnings it found.
defaultconstantThe 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.
detectCountryfunctionWhich country a parsed address is in, from its postal code, then its state or province.
DIRECTION_EXPANSIONSconstantEach directional abbreviation in lower case, to the word in full.
DIRECTIONAL_MAPconstantEach directional word, in English or French, in lower case, to its abbreviation (northwest and nord-ouest to NW and NO).
FACILITY_DELIMITER_PATTERNconstantA facility's name followed by a comma or a dash and then the address.
FACILITY_DELIMITER_PATTERNSconstantThe ways a facility's name is set off from an address: in parentheses, before a delimiter, or as a trailing island.
FACILITY_INDICATORSconstantWords that mark a place's name as a facility (center, tower, hospital, université), in lower case.
FACILITY_PATTERNSconstantThe patterns that find a facility's name, in English and French.
findMunicipalitiesByNamefunctionThe municipalities a Japanese name could mean: several when the name is shared (府中市 is in Tokyo and in Hiroshima).
findMunicipalitiesByRomajifunctionThe municipalities a romaji name could mean, written with or without macrons and designators (Chiyoda-ku, Chiyoda City, Sapporo-shi Chuo-ku, Chuo-ku, Sapporo).
findMunicipalityByCodefunctionThe municipality with a JIS X 0402 code, a designated city's own code included.
findPrefecturefunctionThe prefecture a name, reading, romaji spelling or JIS code refers to: 東京都, 東京, トウキョウト, Tokyo, Osaka Prefecture, 13.
formatAddressfunctionWrites a parsed address back out as lines and as one line, with abbreviations or in full.
formatCanadaPostfunctionWrites 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.
formatJapanesefunctionWrites a Japanese address in Japanese order, as an envelope is addressed: 〒100-0005, then 東京都千代田区丸の内1-2-3, then サンプルビル5階501号室.
formatJapaneseEnglishfunctionWrites a Japanese address in English order, as a form from abroad expects: building, room, block, town, municipality, prefecture, postal code, Japan.
FormattedAddresstypeA formatted address: its lines, and the same on one line.
formatUSPSfunctionWrites 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_PREPOSITIONSconstantFrench 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 ).
FrenchAddressFieldstypeThe fields an address in France fills beside the shared ones.
FrenchCollectivitytypeAn 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.
FrenchDepartmenttypeA department of France in the tables: its code (75, 2A, 971), its name and its region's, from INSEE's Code officiel géographique.
FrenchPostalCountrytypeThe 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.
FrenchPostcodetypeA 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.
FuzzyMatchOptionstypeSettings for fuzzy string matching: the lowest similarity that counts, the largest edit distance, and phonetic matching.
GENERAL_DELIVERY_PATTERNSconstantGeneral delivery written alone or before a city.
GermanAddressFieldstypeThe fields an address in Germany fills beside the shared ones.
GermanPostcodetypeA postcode taken apart: the Land it is in, and whether GeoNames' list has it.
GermanStatetypeA 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).
GermanStateCodetypeThe code of one of the sixteen Länder of Germany, as ISO 3166-2:DE writes it after DE-.
getAddressAbbreviationsfunctionEvery abbreviation the formatters use: street types, directionals, secondary units, states and provinces.
getAddressSimilarityfunctionThe similarity of two parsed addresses, part by part, without a verdict: the score and each part's score, and the differences.
getPostalPrefixesForPrefecturefunctionThe three-digit postal prefixes a prefecture's codes begin with, the reverse of getPrefectureFromJapanesePostalCode.
getPostalPrefixesForProvincefunctionThe postal code prefixes a province or territory uses, the reverse of getProvinceFromPostalCode.
getPrefectureFromJapanesePostalCodefunctionThe 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.
getProvinceFromPostalCodefunctionThe 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.
getStateFromZipfunctionThe state or territory a US ZIP code is in.
getValidationErrorsfunctionThe errors validateAddress finds, without the rest of its result.
getZipPrefixesForStatefunctionThe 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.
hasValidAddressComponentsfunctionWhether a string looks like an address at all: a number and a street, a PO box, a postal code or another recognised part.
INTERSECTION_PATTERNSconstantThe regular expressions and pattern builders the intersection parser uses to find the city and each street with its type.
ISLAND_TYPE_PATTERNconstantThe words for an island, for addresses on one (Island, Isle, Île).
isSameAddressfunctionWhether two parsed addresses are the same place, by the same rules as compareAddresses.
isValidAddressfunctionWhether an address passes validateAddress.
JapaneseAddressFieldstypeThe fields a Japanese address fills on top of the shared ones.
JapaneseEnglishFormattingOptionstypeOptions for formatJapaneseEnglish.
JapaneseFormattingOptionstypeOptions for formatJapanese.
JapaneseMunicipalitytypeA 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.
JapanesePrefecturetypeA prefecture (都道府県) in the tables: its JIS code, official name, katakana reading and romaji.
JapaneseValidationtypeWhat validateJapaneseAddress returns: the errors and the warnings found.
JP_DESIGNATED_CITIESconstantThe twenty designated cities (政令指定都市) as municipalities of their own.
JP_MUNICIPALITIESconstantEvery 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_EXCEPTIONSconstantThe postal codes that deliver to another prefecture than the rest of their three-digit prefix, each to that prefecture's JIS code.
JP_POSTAL_PREFIXESconstantEach three-digit postal prefix, to the JIS code of the prefecture most of its codes deliver to.
JP_PREFECTURESconstantThe 47 prefectures in JIS X 0401 order, each with its code, official name, katakana reading and romaji.
kanjiNumeralsToDigitsfunctionTurns the kanji numerals that stand for block, floor or room numbers into digits: 一丁目二番三号 becomes 1丁目2番3号.
looksJapanesefunctionWhether 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).
municipalitiesOffunctionEvery municipality of a prefecture, the designated cities included.
MUSIC_SQUARE_EAST_PATTERNconstantNashville's Music Square East, whose name ends in a directional word that is part of it.
normalizeJapaneseAddressTextfunctionMakes 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.
normalizeRegionfunctionFinds the US state or Canadian province a name, code or misspelling means: Calfornia, Que., British Columbia, nfld.
normalizeStateProvinceNamefunctionThe code of a US state or Canadian province written in full, in lower case.
normalizeTextfunctionLower-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_PATTERNconstantWords in parentheses inside an address; group 1 is what is inside them.
parseAddressfunctionParses a street address.
parseAddressesfunctionParses many street addresses with parseAddress, in order.
parseAddressesBatchfunctionParses many street addresses with parseAddress, and reports which failed and how long it took.
ParsedAddresstypeWhat parseLocation returns: every part it found, each absent when the address has none.
ParsedIntersectiontypeWhat parseIntersection returns: two streets, each with its name, type and directionals, and the place.
parseDirectionalfunctionTakes a leading directional off a street (NW Main St), abbreviated.
parseFacilityfunctionTakes a facility's name (a building, a park, a hospital) off the start of an address.
parseInformalAddressfunctionReads 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.
parseInformalAddressesfunctionParses many loosely written addresses with parseInformalAddress, in order.
parseInformalAddressesBatchfunctionParses many loosely written addresses with parseInformalAddress, and reports which failed and how long it took.
parseIntersectionfunctionParses an intersection of two streets, joined by &, and, at or @, with the city, state and ZIP that may follow.
parseIntersectionsfunctionParses many intersections with parseIntersection, in order.
parseIntersectionsBatchfunctionParses many intersections with parseIntersection, and reports which failed and how long it took.
parseJapaneseAddressfunctionParses a Japanese address, in Japanese script or in romaji, into the Japanese fields and the shared ones.
parseLocationfunctionParses a US, Canadian or Japanese address into its parts.
parseLocationsfunctionParses many addresses with parseLocation, in order.
parseLocationsBatchfunctionParses many addresses with parseLocation, and reports which failed and how long it took.
ParseOptionstypeOptions for every parser: the country, strict postal codes, snake_case keys and the rest.
parseParentheticalfunctionTakes words in parentheses out of an address, such as (Rear Entrance).
parsePostalCodefunctionTakes a ZIP code, ZIP+4 or Canadian postal code off the end of a text.
parseSecondaryUnitfunctionTakes a secondary unit (apartment, suite, floor and the rest) off a street line.
parseStateProvincefunctionTakes a US state or Canadian province off the end of a text, by code or by name.
parseStreetNumberfunctionTakes the house number off the start of a street line, with a fraction or a letter if it has one.
parseStreetTypefunctionTakes the street type off the end of a street, abbreviated the USPS way.
PO_BOX_PATTERNSconstantThe 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_PROVINCEconstantEach first letter of a Canadian postal code, to the province or territory it is assigned to.
PostalValidationResulttypeWhat validatePostalCode returns: whether the code is well formed, its type, and the code written the standard way.
PROVINCE_EXPANSIONSconstantEach 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_ENconstantEach Canadian province's code in lower case, to its English name in lower case.
PROVINCE_EXPANSIONS_FRconstantEach Canadian province's code in lower case, to its French name in lower case.
RegiontypeA US state or Canadian province: its code, its country and its name, as normalizeRegion matches them.
SECONDARY_UNIT_PATTERNconstantA unit at the end of a street line: group 1 is the street before it, group 2 the unit.
SECONDARY_UNIT_TYPESconstantEach 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.
setValidatedPostalCodefunctionSets 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.
StateCodetypeA US state, DC or territory code that getStateFromZip can return.
STREET_NAME_ACRONYMSconstantAcronyms written in capitals inside a street name (US, FBI), from their lower-case form, for capitalizeStreetName.
STREET_TYPE_DETECTION_PATTERNconstantWhether a text has a common street type in it, used to judge that a parse found a street.
STREET_TYPE_EXPANSIONSconstantEach USPS street type abbreviation in lower case, to the word in full.
STREET_TYPE_PROPER_CASEconstantEach street type abbreviation in lower case, to the way the parser reports it (Ave, Xing).
SubRegiontypeAn administrative part of a city (a borough, a parish, a ward, an arrondissement) that may be written where the city is expected.
TERRITORY_POSTAL_PREFIXESconstantThe first three characters of each territory's postal codes, since the territories share a first letter.
TERRITORY_POSTAL_RANGESconstantThe patterns that tell the Northwest Territories' X codes from Nunavut's, by their first three characters.
TestCasetypeAny case in the package's JSON test files.
TestCaseBasetypeThe fields every case in the package's JSON test files has: a name or description, the input, what is expected and the options.
UKAddressFieldstypeThe fields an address in the United Kingdom fills beside the shared ones.
UKNationtypeA 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).
UKNationCodetypeThe code of one of the four nations of the United Kingdom, as ISO 3166-2:GB writes it after GB-.
UKPostcodetypeA postcode taken apart: the outward code (area and district) and the inward code (sector and unit), and where it delivers.
UNIT_TYPE_KEYWORDSconstantThe 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_PATTERNconstantA unit's designator and value: groups 1 and 2 (apt 123, `Apt.
US_REGIONSconstantEvery name and other spelling of a US state, DC or territory as a Region object, for fuzzy matching by normalizeRegion.
US_STATE_ALTERNATIVESconstantOther ways US states are written (shortened forms, old abbreviations, D.C.), in lower case, to their codes.
US_STATE_EXPANSIONSconstantEach US state's code in lower case, to its name in lower case: the reverse of US_STATE_NAMES.
US_STATE_NAMESconstantEvery US state, DC and territory by its name in lower case, to its two-letter code.
US_STATESconstantEvery name and other spelling of a US state in lower case, to its code: US_STATE_NAMES and US_STATE_ALTERNATIVES together.
US_STREET_TYPESconstantEvery street type USPS Publication 28 lists, and the common spellings of each, in lower case, to its USPS abbreviation in lower case.
USPSFormattingOptionstypeOptions for formatUSPS: which lines to include, and whether to set the letter case the USPS way.
validateAddressfunctionChecks 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.
validateJapaneseAddressfunctionChecks 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.
validatePostalCodefunctionChecks the shape of a US ZIP code or a Canadian postal code.
VALIDATION_PATTERNSconstantSmall regular expressions the validators share: letters, digits, a house number at the start, and the like.
ValidationErrortypeOne finding of a validator: the field it is about, its code, a message, and how serious it is.
ValidationOptionstypeOptions 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_NUMBERSconstantHouse numbers written as words (One, Twenty), as one alternation for a regular expression, so One Microsoft Way is read as number 1.
ZIP_CODE_PATTERNconstantA US ZIP code with an optional ZIP+4.
ZIP_CODE_REGEX_PATTERNconstantThe source of ZIP_CODE_PATTERN, for building larger patterns.
ZIP_VALIDATION_PATTERNSconstantThe shape of something that could be a ZIP code.

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/address-plus 1.7.0.