1 ---
2 sidebar_label: "Addresses"
3 ---
4
5 import { TypeList } from "docs-ui"
6
7 export const metadata = {
8 title: `Address Utilities - Admin Components`,
9 }
10
11 # {metadata.title}
12
13 <Note>
14
15 These utilities are available since Medusa [v2.21.0](https://github.com/medusajs/medusa/releases/tag/v2.21.0).
16
17 </Note>
18
19 The `@medusajs/dashboard/lib` subpath exports the utilities that the Medusa Admin uses to display and compare addresses. Use them in your [admin extensions](!docs!/learn/fundamentals/admin) to show an order's or customer's address the same way the Medusa Admin does.
20
21 ```tsx
22 import {
23 getFormattedAddress,
24 getFormattedCountry,
25 isSameAddress,
26 } from "@medusajs/dashboard/lib"
27 ```
28
29 ---
30
31 ## getFormattedAddress
32
33 Returns an address as an array of lines, ordered the way the Medusa Admin displays them: the full name, the company, the two address lines, a combined city, province, and postal code line, and the country's display name. Render each item of the array on its own line.
34
35 ```tsx
36 import { getFormattedAddress } from "@medusajs/dashboard/lib"
37
38 const ShippingAddress = ({ order }) => {
39 const lines = getFormattedAddress({
40 address: order.shipping_address,
41 })
42
43 return (
44 <div>
45 {lines.map((line, index) => (
46 <span key={index}>{line}</span>
47 ))}
48 </div>
49 )
50 }
51 ```
52
53 ### Parameters
54
55 <TypeList
56 types={[
57 {
58 name: "input",
59 type: "`object`",
60 optional: false,
61 description: "An object holding the address to format.",
62 },
63 {
64 name: "input.address",
65 type: "`AdminOrderAddress | null | undefined`",
66 optional: false,
67 description: "The address to format. Pass an address of an order, customer, or any other resource that has the same shape.",
68 },
69 ]}
70 />
71
72 ### Returns
73
74 Returns a `string[]` of the address's lines. The array is empty when you don't pass an address.
75
76 <Note>
77
78 When the address has no `country` object, the utility resolves the country's display name from the `country_code`. If the code isn't a supported country, it falls back to the uppercase code.
79
80 </Note>
81
82 ---
83
84 ## getFormattedCountry
85
86 Returns a country's display name from its ISO 2 code.
87
88 ```tsx
89 import { getFormattedCountry } from "@medusajs/dashboard/lib"
90
91 getFormattedCountry("us") // "United States"
92 ```
93
94 ### Parameters
95
96 <TypeList
97 types={[
98 {
99 name: "countryCode",
100 type: "`string | null | undefined`",
101 optional: false,
102 description: "The country's lowercase ISO 2 code.",
103 },
104 ]}
105 />
106
107 ### Returns
108
109 Returns a `string` of the country's display name. It returns the passed code when the country isn't supported, and an empty string when you don't pass a code.
110
111 ---
112
113 ## isSameAddress
114
115 Returns whether two addresses hold the same values. It compares the first name, last name, both address lines, city, postal code, province, and country code. It ignores the company and phone.
116
117 ```tsx
118 import { isSameAddress } from "@medusajs/dashboard/lib"
119
120 const isSame = isSameAddress(
121 order.shipping_address,
122 order.billing_address
123 )
124 ```
125
126 ### Parameters
127
128 <TypeList
129 types={[
130 {
131 name: "a",
132 type: "`AdminOrderAddress | null | undefined`",
133 optional: false,
134 description: "The first address to compare.",
135 },
136 {
137 name: "b",
138 type: "`AdminOrderAddress | null | undefined`",
139 optional: false,
140 description: "The second address to compare.",
141 },
142 ]}
143 />
144
145 ### Returns
146
147 Returns a `boolean` that is `true` when the compared fields match. It returns `false` when either address is missing.