Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 25x 25x 29x 29x 29x 29x 25x | import { Address, Country } from '@bigcommerce/checkout-sdk'; import { find, isEmpty } from 'lodash'; import { LocalizedGeography } from '../geography'; const localizeAddress = <T1 extends Address>( address: T1, countries?: Country[] ): T1 & LocalizedGeography => { const country = find(countries, { code: address.countryCode }); const states = !country || isEmpty(country.subdivisions) ? [] : country.subdivisions; const state = find(states, { code: address.stateOrProvinceCode }); return { ...address, localizedCountry: country ? country.name : address.country, localizedProvince: state ? state.name : address.stateOrProvince, }; }; export default localizeAddress; |