@@ -64,7 +64,7 @@ const ipinfoWrapper = new IPinfoWrapper("MY_TOKEN");
6464
6565const ipAddress = process .argv [2 ] || " 1.1.1.1" ;
6666
67- ipinfoWrapper .lookupIp (ipAddress ).then (ipinfo => console .log (ipinfo ))
67+ ipinfoWrapper .lookupIp (ipAddress ).then (( ipinfo ) => console .log (ipinfo ));
6868```
6969
70702 . Run ` ipinfo.js ` (without an IP) to lookup 1.1.1.1
@@ -97,9 +97,10 @@ desirable for the error to bubble up. For example, if your program is performing
9797a lookup to find the country code of an IP:
9898
9999` ` ` typescript
100- const countryCode = ipinfoWrapper.lookupIp(" 1.1.1.1" )
101- .then(ipinfo => ipinfo.countryCode)
102- .catch(error => " N/A" );
100+ const countryCode = ipinfoWrapper
101+ .lookupIp(" 1.1.1.1" )
102+ .then(( ipinfo) => ipinfo.countryCode)
103+ .catch((error) => "N/A");
103104```
104105
105106### Caching
@@ -115,7 +116,7 @@ const { IPinfoWrapper, LruCache } = require("node-ipinfo");
115116
116117const cacheOptions = {
117118 max: 5000 ,
118- ttl: 24 * 1000 * 60 * 60,
119+ ttl: 24 * 1000 * 60 * 60
119120};
120121
121122const cache = new LruCache(cacheOptions);
@@ -133,8 +134,9 @@ A timeout of `0` disables the timeout feature.
133134```typescript
134135const { IPinfoWrapper } = require("node-ipinfo");
135136
136- // 10 second timeout.
137- const ipinfoWrapper = new IPinfoWrapper(" MY_TOKEN" , null, 10000);
137+ const timeout = 10 * 1000 ; // 10 seconds
138+
139+ const ipinfoWrapper = new IPinfoWrapper("MY_TOKEN", undefined, timeout);
138140```
139141
140142### Internationalization
@@ -144,70 +146,55 @@ When looking up an IP address, the response object includes `response.country` w
144146```typescript
145147const { IPinfoWrapper } = require("node-ipinfo");
146148
147- const countries = {
148- "US": "United States",
149- "FR": "France",
150- "BD": "Bangladesh",
151- ...
152- }
153-
154- const countriesFlags = {
155- "US": {"emoji": "🇺🇸","unicode": "U+1F1FA U+1F1F8"},
156- "AD": {"emoji": "🇦🇩", "unicode": "U+1F1E6 U+1F1E9"},
157- "AE": {"emoji": "🇦🇪", "unicode": "U+1F1E6 U+1F1EA"},
158- ...
159- }
160-
161- const countriesCurrencies = {
162- "US" : { "code": "USD" ,"symbol": "$"},
163- "AD": {"code": "EUR", "symbol": "€"},
164- "AE": {"code": "AED", "symbol": "د.إ"},
165- ...
166- }
167-
168- const continents = {
169- "US": {"code": "NA", "name": "North America"},
170- "BD": {"code": "AS", "name": "Asia"},
171- "BE": {"code": "EU", "name": "Europe"},
172- ...
173- }
174-
175- const euCountries = ["FR","ES","BE", ...]
149+ const internationalization = {
150+ countries: {
151+ US: "United States",
152+ FR: "France",
153+ BD: "Bangladesh"
154+ // ...
155+ },
156+ countriesFlags: {
157+ US: { emoji: "🇺🇸", unicode: "U+1 F1 FA U+1 F1 F8 " },
158+ AD: { emoji: "🇦🇩", unicode: "U+1 F1 E6 U+1 F1 E9 " },
159+ AE: { emoji: "🇦🇪", unicode: "U+1 F1 E6 U+1 F1 EA" }
160+ // ...
161+ },
162+ countriesCurrencies: {
163+ US: { code: "USD", symbol: "$" },
164+ AD: { code: "EUR", symbol: "€" },
165+ AE: { code: "AED", symbol: "د.إ" }
166+ // ...
167+ },
168+ continents: {
169+ US: { code: "NA", name: "North America" },
170+ BD: { code: "AS", name: "Asia" },
171+ BE: { code: "EU", name: "Europe" }
172+ // ...
173+ },
174+ euCountries: ["FR", "ES", "BE"]
175+ };
176176
177177const ipinfoWrapper = new IPinfoWrapper(
178178 "MY_TOKEN",
179179 undefined,
180180 undefined,
181- {
182- countries: countries,
183- countriesFlags: countriesFlags,
184- countriesCurrencies: countriesCurrencies,
185- ...
186- }
181+ internationalization
187182);
188183
189- ipinfoWrapper.lookupIp("1.1.1.1").then(response => {
190- // country code, e.g. ' US'
191- console.log(response.countryCode);
192-
193- // country name, e.g. ' United States'
194- console.log(response.country);
195-
196- // whether part of the EU, e.g. false
197- console.log(response.isEU);
198-
199- // emoji and unicode of country flag { emoji: ' 🇺🇸' , unicode: ' U+1F1FA U+1F1F8' }
200- console.log(response.countryFlag)
201-
202- // country' s flag image URL e.g. https://cdn.ipinfo.io/static/images/countries-flags/US.svg
203- console.log(response.countryFlagURL)
204-
205- // code and symbol of country currency { code: ' USD' , symbol: ' $' }
206- console.log(response.countryCurrency)
184+ ipinfoWrapper.lookupIp("8 .8 .8 .8 ").then((response) => console.log(response)) ;
185+ ` ` `
207186
208- // code and name of continent { code: ' NA' , name: ' North America' }
209- console.log(response.continent)
210- });
187+ ` ` `
188+ {
189+ ip: " 8.8.8.8" ,
190+ // ...
191+ countryCode: ' US' ,
192+ countryFlag: { emoji: ' 🇺🇸' , unicode: ' U+1F1FA U+1F1F8' },
193+ countryFlagURL: ' https://cdn.ipinfo.io/static/images/countries-flags/US.svg' ,
194+ countryCurrency: { code: ' USD' , symbol: ' $' },
195+ continent: { code: ' NA' , name: ' North America' },
196+ isEU: false
197+ }
211198` ` `
212199
213200# ## Location Information
0 commit comments