AddressSource
interface AddressSource {
layout: Layout;
fixed: Partial<Record<FixedField, string>>;
format: FormatPart[][];
format_latin?: FormatPart[][];
upper: FormatField[];
example?: Partial<Record<'country' | 'first_name' | 'last_name' | 'email' | 'phone_number' | 'line1' | 'line2' | 'line3' | 'city' | 'state' | 'postcode', string>>;
example_latin?: Partial<Record<'country' | 'first_name' | 'last_name' | 'email' | 'phone_number' | 'line1' | 'line2' | 'line3' | 'city' | 'state' | 'postcode', string>>;
}A country's address: how it is typed in (layout), how it is written for reading (format), and a real one to preview both with (example).
To write an address, give each field in format its value and apply the rule on AddressSource.format. state is written by its name: an order stores the state's code, an abbreviation in the US, Canada and Australia, so look it up in states (?include=states) and write the stored value only where no option has it.
The first example is the start of the US's address, layout and fixed left out; the second is its example address written with it.
Example
{
"format": [
[{ "field": "first_name" }, { "text": " " }, { "field": "last_name" }],
[{ "field": "line1" }],
[{ "field": "line2" }],
[{ "field": "city" }, { "text": ", " }, { "field": "state" }, { "text": " " }, { "field": "postcode" }],
[{ "field": "country" }]
],
"upper": ["city", "state"],
"example": {
"first_name": "Jane",
"last_name": "Doe",
"line1": "1600 Pennsylvania Avenue NW",
"city": "Washington",
"state": "DC",
"postcode": "20500"
}
}Jane Doe
1600 Pennsylvania Avenue NW
Washington, District of Columbia 20500
United StatesProperties
layout: Layout
The form: rows of fields, in the order the country writes them.
fixed: Partial<Record<FixedField, string>>
The values every address in the country shares, which are not asked for and are submitted as they are. Empty in the US; Vatican City fixes its city and postcode.
format: FormatPart[][]
How the country writes an address for reading, in its own script: on an order page, a receipt or a label. Each line is parts, a field or text. To write one, leave out a field with no value; write a text part only where a field with a value follows it on the line and, unless it starts the line, one precedes it; where several would sit together, write only the last. A line that is text alone is written as it is, and a line left empty is dropped. {city}, {state} {postcode} with no state writes Mountain View 94043.
format_latin: FormatPart[][]
How it writes an address in Latin script, where that differs from format. Absent in the US, whose format is Latin already; Japan's puts the name first, given name first, and the postcode last. Use it when the address is in Latin script.
upper: FormatField[]
The fields the country's post writes in capitals on an envelope: city and state in the US. A page on a screen can leave them as they are.
example: Partial<Record<'country' | 'first_name' | 'last_name' | 'email' | 'phone_number' | 'line1' | 'line2' | 'line3' | 'city' | 'state' | 'postcode', string>>
A real address in the country, a public building's, in its own script: for previews. The state is its code, as a form submits it. On curated countries only.
example_latin: Partial<Record<'country' | 'first_name' | 'last_name' | 'email' | 'phone_number' | 'line1' | 'line2' | 'line3' | 'city' | 'state' | 'postcode', string>>
The same address in Latin script, for a country that writes in another script. It is written with format_latin where the country has one, and with format otherwise.