countrynormalizer 0.2.6 → 0.2.8
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/README.md +41 -37
- package/dist/index.d.ts +2 -1
- package/dist/index.js +523 -1508
- package/dist/src/findAllMatchedCountries.d.ts +25 -0
- package/dist/src/findCountryByUnqiue.d.ts +0 -24
- package/package.json +7 -3
package/README.md
CHANGED
|
@@ -22,12 +22,12 @@ Developers routinely need to mix and match pieces of country data across an appl
|
|
|
22
22
|
|
|
23
23
|
Some common examples are:
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
- Retrieve a country's full name based on an ISO Alpha 2 or Alpha 3 code.
|
|
26
|
+
- Turn a user-entered country name back into an ISO Alpha 2 or 3 code for API standardization.
|
|
27
|
+
- Load a country's flag/flag emoji based on a user input or phone number input.
|
|
28
|
+
- Standardize the name of a country or input from many different references to a country.
|
|
29
|
+
- List all countries on a continent for location selection.
|
|
30
|
+
- Find countries that correspond to a particular phone number's calling code.
|
|
31
31
|
|
|
32
32
|
There are lots of good libraries out there that handle one of these functions at a time. Turning ISO 3166-1 alpha-2 into full names, or phone number into country flags, and so on and so forth.
|
|
33
33
|
|
|
@@ -43,14 +43,14 @@ The `findCountryByUnique(needle: string | number): AllCountryFields | null` can
|
|
|
43
43
|
|
|
44
44
|
The guaranteed unique fields are:
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
46
|
+
- ISO 3166-1 number: The unique ISO 3166-1 number values where there are no duplicate values across all countries.
|
|
47
|
+
- ISO 3166-1 alpha-2: Two letter guaranteed unique country code values.
|
|
48
|
+
- ISO 3166-1 alpha-3: Three letter guaranteed unique country code values.
|
|
49
|
+
- `english_clean`: English country names from the ISO 3166 standard as listed on Wikipedia.
|
|
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.
|
|
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.
|
|
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.
|
|
54
54
|
|
|
55
55
|
The returned country structure will match the `AllCountryFields` type and look like this...
|
|
56
56
|
|
|
@@ -162,6 +162,7 @@ This function still supports singular lookup. Entering something like `findAllMa
|
|
|
162
162
|
Entering a text value into this function that yields no results will return an empty (`[]`) array.
|
|
163
163
|
|
|
164
164
|
### Get Countries Contact Fields:
|
|
165
|
+
|
|
165
166
|
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
|
|
|
167
168
|
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.
|
|
@@ -179,6 +180,7 @@ In order to keep a smaller object available to work with and for tree-shaking co
|
|
|
179
180
|
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
|
|
|
181
182
|
### Get All Countries For Continent:
|
|
183
|
+
|
|
182
184
|
In cases where you need to make a location selection you may want to query all countries located on a continent.
|
|
183
185
|
|
|
184
186
|
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`.
|
|
@@ -246,36 +248,38 @@ This is a massive array of objects for every country on Earth contained in the I
|
|
|
246
248
|
This may be helpful for understanding the data shapes, visualizing all the data, or shaping information in ways the package functions/APIs do not support natively.
|
|
247
249
|
|
|
248
250
|
## Data Sources:
|
|
251
|
+
|
|
249
252
|
This data is compiled from a wide array of sources. To give transparency to this I want to document the primary source or reason for each field.
|
|
250
253
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
254
|
+
- common_reference: A field for how people might commonly refer to a country in conversation or normal parlance shorthand. All special characters are removed except dashes, commas, and parentheses. This makes searching by standard keyboard entry easier. For example, `Türkiye` is commonly typed as `Turkey`. This field helps flatten and make searching for these countries easier. The naming conventions here are purely an executive decision by me, the maintainer. All values are unique.
|
|
255
|
+
- english_clean: This comes off of the "country name using title case" column on the wikipedia Alpha 2 documentation for ISO 3166: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
|
|
256
|
+
- formal_order: On Wikipedia and other sources for easy Alpabetization they order countries by common names. So "Netherlands, Kingdom of the", this just puts it in order as "Kingdom of the Netherlands."
|
|
257
|
+
- alpha_2: ISO 3166 Alpha 2 values as listed on wikipedia: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
|
|
258
|
+
- alpha_3: Taken from Wikipedia ISO 3166 master table: https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes
|
|
259
|
+
- num_code: Taken from Wikipedia ISO 3166 master table: https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes
|
|
260
|
+
- demonym_male: ChatGTP deep research compiled CSV dataset asking it to align ISO Alpha 3 codes to demonym by country for both male and female.
|
|
261
|
+
- demonym_female: ChatGTP deep research compiled CSV dataset asking it to align ISO Alpha 3 codes to demonym by country for both male and female.
|
|
262
|
+
- gendered_demonym: Manual alignment in Google Sheet by me comparing `demonym_male` and `demonym_male` for string differences and setting a boolean.
|
|
263
|
+
- tld: Taken from Wikipedia ISO 3166 master table: https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes
|
|
264
|
+
- flag_emoji: Used table available on Flagepedia and then cleaned up the data for easy usage in CSVs and JSON objects: https://flagpedia.net/emoji
|
|
265
|
+
- calling_code: ChatGPT compiled deep research task. Instructed to rely primarily on these data sources to make data easily worked with in a CSV and as JSON objects.
|
|
266
|
+
- - https://en.wikipedia.org/wiki/Trunk_prefix
|
|
267
|
+
- - https://en.wikipedia.org/wiki/List_of_telephone_country_codes
|
|
268
|
+
- - https://www.countrycode.org/
|
|
269
|
+
- continent: ChatGPT deep research compiled list asking to align all ISO Alpha 3 country codes to their continent.
|
|
267
270
|
|
|
268
271
|
## To-Do List:
|
|
272
|
+
|
|
269
273
|
This package was started as part of language classification and news analytics projects I'm working on in my personal time.
|
|
270
274
|
|
|
271
275
|
I've enjoyed building it out but wanted to publish something for starters so I don't let this languish on my personal computer for too long.
|
|
272
276
|
|
|
273
277
|
Over the next few weeks (hopefully) I plan to build out the following...
|
|
274
278
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
279
|
+
- ~~tld search support should be added to unique lookups since these are unique values.~~
|
|
280
|
+
- Optimize the search order of data when performing lookups.
|
|
281
|
+
- 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.
|
|
282
|
+
- ~~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.~~
|
|
283
|
+
- Flesh out more complete unit testing. I have a few running right now checking ISO number values but all data values should be validated.
|
|
284
|
+
- Add size optimized lookups for common operations. Currently the `complete.json` object used for country data is rather large and bloats this library. I want to make smaller, tree-shakable functions to handle only certain data queries on the fly.
|
|
285
|
+
- Set up a small website to visualize all this data in an accessible table for using alongside this library. Right now a lot of it is just compiled in a haphazard Google Doc where I did my initial organizing before translating a CSV into a JSON file.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { findCountryByUnique
|
|
1
|
+
import { findCountryByUnique } from "./src/findCountryByUnqiue";
|
|
2
|
+
import { findAllMatchedCountries } from "./src/findAllMatchedCountries";
|
|
2
3
|
import { getContactFieldsByAlpha2 } from "./src/getCountryContactData";
|
|
3
4
|
import { getCountriesByContinent } from "./src/getCountriesByContinent";
|
|
4
5
|
import { getAllCountries } from "./src/getAllCountries";
|