country-code-kit 1.0.1 → 1.0.4
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 +38 -27
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# country-kit
|
|
2
2
|
|
|
3
|
-
Zero-dependency TypeScript package with all **249 ISO 3166-1 countries** — alpha-2 code, English name,
|
|
3
|
+
Zero-dependency TypeScript package with all **249 ISO 3166-1 countries** — alpha-2 code, English name, flag emoji, and ITU dial code — plus fast lookup and search helpers. Ships dual ESM + CJS builds with full type declarations. Works in Node and browsers, tree-shakeable, ~10 KB.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm
|
|
8
|
+
npm i country-code-kit
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
@@ -18,27 +18,34 @@ import {
|
|
|
18
18
|
getCountryByFlag,
|
|
19
19
|
getFlag,
|
|
20
20
|
getName,
|
|
21
|
+
getDialCode,
|
|
22
|
+
getCountriesByDialCode,
|
|
21
23
|
isValidCode,
|
|
22
24
|
searchCountries,
|
|
23
25
|
codeToFlag,
|
|
24
26
|
flagToCode,
|
|
25
27
|
} from "country-kit";
|
|
26
28
|
|
|
27
|
-
countries.length;
|
|
28
|
-
getCountryByCode("in");
|
|
29
|
-
getCountryByName("Japan");
|
|
30
|
-
getCountryByFlag("🇩🇪");
|
|
29
|
+
countries.length; // 249
|
|
30
|
+
getCountryByCode("in"); // { code: "IN", name: "India", flag: "🇮🇳", dialCode: "+91" }
|
|
31
|
+
getCountryByName("Japan"); // { code: "JP", name: "Japan", flag: "🇯🇵", dialCode: "+81" }
|
|
32
|
+
getCountryByFlag("🇩🇪"); // { code: "DE", name: "Germany", flag: "🇩🇪", dialCode: "+49" }
|
|
31
33
|
|
|
32
|
-
getFlag("BD");
|
|
33
|
-
getName("FR");
|
|
34
|
-
|
|
34
|
+
getFlag("BD"); // "🇧🇩"
|
|
35
|
+
getName("FR"); // "France"
|
|
36
|
+
getDialCode("BD"); // "+880"
|
|
37
|
+
getDialCode("AQ"); // null (territory with no assigned dial code)
|
|
38
|
+
isValidCode("zz"); // false
|
|
39
|
+
|
|
40
|
+
getCountriesByDialCode("+1");
|
|
41
|
+
// [{ code: "US", ... }, { code: "CA", ... }, ...] — all territories sharing +1
|
|
35
42
|
|
|
36
43
|
searchCountries("uni");
|
|
37
44
|
// [United Arab Emirates, United Kingdom, United States, ...]
|
|
38
45
|
// ranked: exact match → prefix match → substring match
|
|
39
46
|
|
|
40
|
-
codeToFlag("NP");
|
|
41
|
-
flagToCode("🇳🇵");
|
|
47
|
+
codeToFlag("NP"); // "🇳🇵" (no lookup table needed)
|
|
48
|
+
flagToCode("🇳🇵"); // "NP"
|
|
42
49
|
```
|
|
43
50
|
|
|
44
51
|
CommonJS works too:
|
|
@@ -49,27 +56,31 @@ const { getName } = require("country-kit");
|
|
|
49
56
|
|
|
50
57
|
## API
|
|
51
58
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
|
55
|
-
| `
|
|
56
|
-
| `
|
|
57
|
-
| `
|
|
58
|
-
| `
|
|
59
|
-
| `
|
|
60
|
-
| `
|
|
61
|
-
| `
|
|
62
|
-
| `
|
|
59
|
+
|
|
60
|
+
| Function | Returns |
|
|
61
|
+
| ---------------------------------- | ---------------------------------------------------------------------- |
|
|
62
|
+
| `countries` | `readonly Country[]` — all 249 entries |
|
|
63
|
+
| `getCountryByCode(code)` | `Country | undefined` (case-insensitive) |
|
|
64
|
+
| `getCountryByName(name)` | `Country | undefined` (case-insensitive) |
|
|
65
|
+
| `getCountryByFlag(flag)` | `Country | undefined` |
|
|
66
|
+
| `getFlag(code)` / `getName(code)` | `string | undefined` |
|
|
67
|
+
| `getDialCode(code)` | `string | null | undefined` — `null` for territories with no dial code |
|
|
68
|
+
| `getCountriesByDialCode(dialCode)` | `Country[]` — all countries sharing a dial code (e.g. `"+1"`) |
|
|
69
|
+
| `isValidCode(code)` | `boolean` |
|
|
70
|
+
| `searchCountries(query)` | `Country[]` ranked by match quality |
|
|
71
|
+
| `codeToFlag(code)` | `string` (throws on invalid input) |
|
|
72
|
+
| `flagToCode(flag)` | `string | undefined` |
|
|
73
|
+
|
|
63
74
|
|
|
64
75
|
```ts
|
|
65
76
|
interface Country {
|
|
66
|
-
code: string;
|
|
67
|
-
name: string;
|
|
68
|
-
flag: string;
|
|
77
|
+
code: string; // ISO 3166-1 alpha-2, e.g. "IN"
|
|
78
|
+
name: string; // English short name, e.g. "India"
|
|
79
|
+
flag: string; // Flag emoji, e.g. "🇮🇳"
|
|
80
|
+
dialCode: string | null; // ITU calling code incl. "+", e.g. "+880". Null for territories with no assigned code.
|
|
69
81
|
}
|
|
70
82
|
```
|
|
71
83
|
|
|
72
|
-
|
|
73
84
|
## License
|
|
74
85
|
|
|
75
|
-
MIT
|
|
86
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "country-code-kit",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "v1.0.4",
|
|
4
4
|
"description": "Zero-dependency list of all 249 ISO 3166-1 countries with code, name, and flag emoji. Lookup and search helpers included. Tree-shakeable, works in Node and browsers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"country",
|