![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
@opengovsg/countries-regions-codes
Advanced tools
Utility for converting between country and region codes
A utility for converting between country/region codes. We currently support 6 schemes:
'name'
Plaintext English'icao'
International Civil Aviation Organization'iso2'
ISO 3166-1 alpha-2 (link)'iso3'
ISO 3166-1 alpha-3 (link)'flag'
Emojis 🇦🇪 🇪🇸 🇸🇬 🇲🇵 🇳🇱'phone'
Prefixes for international dialing (link)npm install @opengovsg/countries-regions-codes
countries-regions-codes
provides a chained API:
import { convert } from '@opengovsg/countries-regions-codes'
convert('SGP').from('icao').to('iso2') // 'SG'
Schemes don't always have 1-1 mappings. In such cases, we support many-to-one mappings as expected
// United States Minor Outlying Islands
convert('UM').from('iso2').to('icao') // 'USA'
// United States
convert('US').from('iso2').to('icao') // 'USA'
and choose a sensible default for one-to-many mappings. Where ambiguous, we choose the territory with a larger population. The full list of alternates can be seen here
convert('USA').from('icao').to('name') // 'United States'
Where a scheme has no representation for an option provided by another scheme, we throw an error.
// Refugee (Status) exists in icao but not iso2
convert('XXB').from('icao').to('iso2') // throws
Additionally, if you require the full enums, e.g. to use in a validator / to iterate over with your own logic, you can access them as a de-duped, sorted list:
import { schemes } from '@opengovsg/countries-regions-codes'
console.log(schemes.icao) // ['AFG', 'ALB', 'AZM', ...]
console.log(schemes.iso2) // ['AF', 'AL', 'AS', ...]
Array items in schemes
and return type from convert()
are strongly-typed thanks to type-narrowing.
const possiblePhonePrefix: string = '+66'
const wellTypedIso3 = convert(possiblePhonePrefix).from('phone').to('iso3')
// TS complains - wellTypedIso3 is known to be 'AFG' | 'ALB' | 'AZM' ...
if (wellTypedIso3 === 'Thailand')
FAQs
Utility for converting between country and region codes
We found that @opengovsg/countries-regions-codes demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.