typed-countries
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "typed-countries", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "An array of the world's countries, complete with full TypeScript declaration support.", | ||
@@ -10,2 +10,10 @@ "main": "dist/index.js", | ||
"license": "MIT", | ||
"keywords": [ | ||
"country", | ||
"countries", | ||
"iso", | ||
"geoip", | ||
"postal codes", | ||
"zip codes" | ||
], | ||
"scripts": { | ||
@@ -12,0 +20,0 @@ "prepublish": "npm run build", |
@@ -16,3 +16,3 @@ # typed-countries | ||
## Usage | ||
## Importing | ||
@@ -37,2 +37,36 @@ You can import the package with ES6-style imports, or through Node's require: | ||
const countries = require("typed-countries").default; | ||
``` | ||
## Usage | ||
The export is an array of country objects, which means you can use all of the usual array operations on the country list: | ||
```js | ||
import { countries } from "typed-countries"; | ||
const usa = countries.find(c => c.iso === "US"); | ||
console.log(usa); | ||
// { | ||
// iso: 'US', | ||
// name: 'United States', | ||
// hasPostalCodes: true, | ||
// states: [ | ||
// { | ||
// iso: 'AL', | ||
// name: 'Alabama' | ||
// }, | ||
// ... | ||
// ], | ||
// zipRegex: "^\\d{5}([\\-]\\d{4})?$" | ||
// } | ||
``` | ||
If you're using TypeScript, you can also import the Country and State interfaces: | ||
```js | ||
import { countries, Country, State } from "typed-countries"; | ||
const usa: Country = countries.find(c => c.iso === "US"); | ||
const iowa: State = usa.states.find(c => c.iso === "IA"); | ||
``` |
84153
70