countrynormalizer 0.0.1
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 +160 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4344 -0
- package/dist/src/findCountryByUnqiue.d.ts +52 -0
- package/dist/src/utils/callingCodesValidator.d.ts +1 -0
- package/dist/src/utils/domainValidator.d.ts +1 -0
- package/dist/types/core.d.ts +17 -0
- package/package.json +33 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { AllCountryFields } from "../types/core";
|
|
2
|
+
/**
|
|
3
|
+
* Searches all guaranteed unique country data fields and returns the single matching country.
|
|
4
|
+
*
|
|
5
|
+
* Fields searched (in order):
|
|
6
|
+
* - ISO 3166-1 numeric code (`num_code`)
|
|
7
|
+
* - ISO 3166-1 alpha-2 (`alpha_2`)
|
|
8
|
+
* - ISO 3166-1 alpha-3 (`alpha_3`)
|
|
9
|
+
* - `english_clean` β English country name from the ISO 3166 standard
|
|
10
|
+
* - `formal_order` β naturally spoken order of the formal country name
|
|
11
|
+
* - `flag_emoji` β Unicode flag emoji for the country
|
|
12
|
+
* - `common_reference` β casual/colloquial country name
|
|
13
|
+
*
|
|
14
|
+
* This will **not** search non-unique fields like calling codes, continents, or demonyms.
|
|
15
|
+
* Use {@link findAllMatchedCountries} for those lookups.
|
|
16
|
+
*
|
|
17
|
+
* String inputs must be at least 2 characters. Numeric inputs must be positive.
|
|
18
|
+
*
|
|
19
|
+
* @param needle - The search value: a country name, ISO code, numeric code, or flag emoji.
|
|
20
|
+
* @returns The matching country data, or `null` if no match is found.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* findCountryByUnique("US"); // Returns United States data
|
|
24
|
+
* findCountryByUnique(840); // Returns United States data (by numeric code)
|
|
25
|
+
* findCountryByUnique("πΊπΈ"); // Returns United States data (by flag emoji)
|
|
26
|
+
* findCountryByUnique("xx"); // Returns null
|
|
27
|
+
*/
|
|
28
|
+
export declare const findCountryByUnique: (needle: string | number) => AllCountryFields | null;
|
|
29
|
+
/**
|
|
30
|
+
* Searches all country data fields β including non-unique fields β and returns every
|
|
31
|
+
* country that matches the given needle.
|
|
32
|
+
*
|
|
33
|
+
* Unlike {@link findCountryByUnique}, this also searches across:
|
|
34
|
+
* - `calling_code` β phone calling codes (e.g. `"+1"`, `"44"`)
|
|
35
|
+
* - `continent` β continent name (e.g. `"Asia"`)
|
|
36
|
+
* - `demonym_male` / `demonym_female` β demonyms (e.g. `"Canadian"`)
|
|
37
|
+
* - `tld` β top-level domain (e.g. `".uk"`)
|
|
38
|
+
*
|
|
39
|
+
* All unique fields (`alpha_2`, `alpha_3`, `english_clean`, `formal_order`,
|
|
40
|
+
* `common_reference`, `flag_emoji`, `num_code`) are searched as well.
|
|
41
|
+
*
|
|
42
|
+
* @param needle - The search value: a country name, ISO code, numeric code, calling code,
|
|
43
|
+
* continent name, demonym, TLD, or flag emoji.
|
|
44
|
+
* @returns An array of all matching countries. Returns an empty array if no matches are found.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* findAllMatchedCountries("+1"); // All countries sharing calling code "1"
|
|
48
|
+
* findAllMatchedCountries("asia"); // All countries in Asia
|
|
49
|
+
* findAllMatchedCountries("GB"); // Single-item array with United Kingdom data
|
|
50
|
+
* findAllMatchedCountries("zzzzz"); // []
|
|
51
|
+
*/
|
|
52
|
+
export declare const findAllMatchedCountries: (needle: string | number) => AllCountryFields[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const hasMatchingCallingCode: (searchKey: string | number, callingCodes: string[]) => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const matchesCleanedDomain: (searchKey: string, countryDomain: string) => boolean;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface AllCountryFields {
|
|
2
|
+
common_reference: string;
|
|
3
|
+
english_clean: string;
|
|
4
|
+
formal_order: string;
|
|
5
|
+
alpha_2: string;
|
|
6
|
+
alpha_3: string;
|
|
7
|
+
num_code: number;
|
|
8
|
+
demonym_male: string;
|
|
9
|
+
demonym_female: string;
|
|
10
|
+
gendered_demonym: boolean;
|
|
11
|
+
tld: string;
|
|
12
|
+
flag_emoji: string;
|
|
13
|
+
calling_code: string[];
|
|
14
|
+
continent: string;
|
|
15
|
+
}
|
|
16
|
+
export type ContactCountryFields = Pick<AllCountryFields, "tld" | "flag_emoji" | "calling_code">;
|
|
17
|
+
export type UniqueCountryFields = Pick<AllCountryFields, "english_clean" | "formal_order" | "alpha_2" | "alpha_3" | "num_code">;
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "countrynormalizer",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "bun run build.ts",
|
|
20
|
+
"extract-data": "bun ./tools/build-data.ts"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/bun": "latest",
|
|
24
|
+
"@types/jest": "^30.0.0",
|
|
25
|
+
"@types/lodash": "^4.17.24",
|
|
26
|
+
"csvtojson": "^2.0.14",
|
|
27
|
+
"jest": "^30.2.0",
|
|
28
|
+
"lodash": "^4.17.23"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"typescript": "^5"
|
|
32
|
+
}
|
|
33
|
+
}
|