countrynormalizer 0.0.1 β†’ 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 JackMcE
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,7 +1,23 @@
1
1
  # 🌎 Country Data Lookup And Normalizer 🌍
2
2
 
3
+ [![CI](https://github.com/JackMcE/CountryNormalizer/actions/workflows/ci.yml/badge.svg)](https://github.com/JackMcE/CountryNormalizer/actions/workflows/ci.yml)
4
+ [![npm version](https://img.shields.io/npm/v/countrynormalizer.svg)](https://www.npmjs.com/package/countrynormalizer)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
6
+ [![Coverage](https://codecov.io/gh/JackMcE/CountryNormalizer/branch/main/graph/badge.svg)](https://codecov.io/gh/JackMcE/CountryNormalizer)
7
+ [![npm downloads](https://img.shields.io/npm/dm/countrynormalizer.svg)](https://www.npmjs.com/package/countrynormalizer)
8
+
3
9
  A simple library for consolidation and reverse lookup of common ISO country data fields and calling codes all in one place.
4
10
 
11
+ ## Installation
12
+
13
+ ```bash
14
+ npm install countrynormalizer
15
+ ```
16
+
17
+ ```bash
18
+ bun add countrynormalizer
19
+ ```
20
+
5
21
  Developers routinely need to mix and match pieces of country data across an application.
6
22
 
7
23
  Some common examples are:
@@ -34,12 +50,13 @@ The guaranteed unique fields are:
34
50
  * `formal_order`: The naturally spoken order of a country's formal name from the ISO 3166 standard. For instance, the `english_clean` for the Netherlands is `Netherlands, Kingdom of the`, while the `formal_order` is `Kingdom of the Netherlands` β€” the way the country would be referenced in formal international or political conversation.
35
51
  * `common_reference`: Maps country names to how they would be referred to in normal casual conversation. So `Kingdom of the Netherlands` is just `Netherlands`. The `Holy See` is `Vatican City`. You can probably use common sense to arrive at most of these.
36
52
  * `flag_emoji`: The Unicode standard dictates that all ISO 3166 countries shall have an emoji flag. As such you can search the emoji of a flag as input and retrieve all data for that country.
53
+ * `tld (top-level domain)` - Searches for the countries top-level domain match.
37
54
 
38
55
  The returned country structure will match the `AllCountryFields` type and look like this...
39
56
 
40
57
  ```
41
58
  {
42
- common_reference: "United States of America",
59
+ common_reference: "United States",
43
60
  english_clean: "United States of America",
44
61
  formal_order: "United States of America",
45
62
  alpha_2: "US",
@@ -65,7 +82,7 @@ A common example of this is calling codes. Most of North America uses the `+1` c
65
82
 
66
83
  ```
67
84
  {
68
- "common_reference": "United States of America",
85
+ "common_reference": "United States",
69
86
  "english_clean": "United States of America",
70
87
  "formal_order": "United States of America",
71
88
  "alpha_2": "US",
@@ -82,7 +99,7 @@ A common example of this is calling codes. Most of North America uses the `+1` c
82
99
  "continent": "North America"
83
100
  },
84
101
  {
85
- "common_reference": "United States Minor Outlying Islands",
102
+ "common_reference": "US Territories",
86
103
  "english_clean": "United States Minor Outlying Islands",
87
104
  "formal_order": "United States Minor Outlying Islands",
88
105
  "alpha_2": "UM",
@@ -144,6 +161,82 @@ This function still supports singular lookup. Entering something like `findAllMa
144
161
 
145
162
  Entering a text value into this function that yields no results will return an empty (`[]`) array.
146
163
 
164
+ ### Get Countries Contact Fields:
165
+ It is common for applications to want to get the contact fields such as calling code blocks for the country, the flag of the country for visual identification, or top-level domains.
166
+
167
+ In order to keep a smaller object available to work with and for tree-shaking consumer facing apps you can call `getContactFieldsByAlpha2(alpha2: string): ContactCountryFields | null` in order to get a response object of only the countries contact fields.
168
+
169
+ ```
170
+ {
171
+ "tld": ".gn",
172
+ "flag_emoji": "πŸ‡¬πŸ‡³",
173
+ "calling_code": [
174
+ "224"
175
+ ]
176
+ }
177
+ ```
178
+
179
+ If the input does not match a valid ISO Alpha 2 value function returns `null`. The inputs ARE NOT keyed and open ended. Since this kind of data lookup is often times done based on open ended user input it is easier to simply check any string coming in and handle it vs making applications have to typecheck the input lookup.
180
+
181
+ ### Get All Countries For Continent:
182
+ In cases where you need to make a location selection you may want to query all countries located on a continent.
183
+
184
+ You can use `getCountriesByContinent(searchContinent: ContinentNames): ContinentTrimmedFields[]` function. This function requires a specifically matched enum input of continent names. It can be imported via `ContinentNames`.
185
+
186
+ This function returns a trimmed down set of country data for each country on the continent. You'll receive all the guaranteed unique identifier and display fields, with globally standardized contact data trimmed away. For example the response for Antarctica would look like this...
187
+
188
+ ```
189
+ [
190
+ {
191
+ "english_clean": "Antarctica",
192
+ "formal_order": "Antarctica",
193
+ "alpha_2": "AQ",
194
+ "alpha_3": "ATA",
195
+ "num_code": 10,
196
+ "tld": ".aq",
197
+ "flag_emoji": "πŸ‡¦πŸ‡Ά"
198
+ },
199
+ {
200
+ "english_clean": "Bouvet Island",
201
+ "formal_order": "Bouvet Island",
202
+ "alpha_2": "BV",
203
+ "alpha_3": "BVT",
204
+ "num_code": 74,
205
+ "tld": ".bv",
206
+ "flag_emoji": "πŸ‡§πŸ‡»"
207
+ },
208
+ {
209
+ "english_clean": "Heard Island and McDonald Islands",
210
+ "formal_order": "Heard Island and McDonald Islands",
211
+ "alpha_2": "HM",
212
+ "alpha_3": "HMD",
213
+ "num_code": 334,
214
+ "tld": ".hm",
215
+ "flag_emoji": "πŸ‡­πŸ‡²"
216
+ },
217
+ {
218
+ "english_clean": "South Georgia and the South Sandwich Islands",
219
+ "formal_order": "South Georgia and the South Sandwich Islands",
220
+ "alpha_2": "GS",
221
+ "alpha_3": "SGS",
222
+ "num_code": 239,
223
+ "tld": ".gs",
224
+ "flag_emoji": "πŸ‡¬πŸ‡Έ"
225
+ },
226
+ {
227
+ "english_clean": "Svalbard and Jan Mayen",
228
+ "formal_order": "Svalbard and Jan Mayen",
229
+ "alpha_2": "SJ",
230
+ "alpha_3": "SJM",
231
+ "num_code": 744,
232
+ "tld": ".sj",
233
+ "flag_emoji": "πŸ‡ΈπŸ‡―"
234
+ }
235
+ ]
236
+ ```
237
+
238
+ If you need absolutely all information about every country on a continent use the `findAllMatchedCountries()` function with a continent entered.
239
+
147
240
  ## To-Do List:
148
241
  This package was started as part of language classification and news analytics projects I'm working on in my personal time.
149
242
 
@@ -151,7 +244,7 @@ I've enjoyed building it out but wanted to publish something for starters so I d
151
244
 
152
245
  Over the next few weeks (hopefully) I plan to build out the following...
153
246
 
154
- * tld search support should be added to unique lookups since these are unique values.
247
+ * ~~tld search support should be added to unique lookups since these are unique values.~~
155
248
  * Optimize the search order of data when performing lookups.
156
249
  * Clean up some of the `common_reference` values. A lot of these are executive decisions I quickly made and could be better researched or refined.
157
250
  * Provide better documentation on the data sources for each of these fields to help assure people of data validity and no collisions of unique data points.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { findCountryByUnique, findAllMatchedCountries } from "./src/findCountryByUnqiue";
2
- import type { AllCountryFields } from "./types/core";
3
- export { findCountryByUnique, findAllMatchedCountries };
4
- export type { AllCountryFields };
2
+ import { getContactFieldsByAlpha2 } from "./src/getCountryContactData";
3
+ import { getCountriesByContinent } from "./src/getCountriesByContinent";
4
+ import type { AllCountryFields, ContactCountryFields, ContinentNames, ContinentTrimmedFields } from "./types/core";
5
+ export { findCountryByUnique, findAllMatchedCountries, getContactFieldsByAlpha2, getCountriesByContinent, };
6
+ export type { AllCountryFields, ContactCountryFields, ContinentNames, ContinentTrimmedFields, };