react-all-countries 1.0.0

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/index.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ export interface Country {
2
+ name: string;
3
+ shortName: string;
4
+ phonePrefix: string;
5
+ timezones: string;
6
+ flag: string;
7
+ }
8
+
9
+ declare const countries: Country[];
10
+
11
+ export function getCountries(): Country[];
12
+ export function getCountryByCode(code: string): Country | undefined;
13
+ export function getCountryByName(name: string): Country | undefined;
14
+ export function getCountriesByCallingCode(phonePrefix: string | number): Country[];
15
+ export function searchCountries(query: string): Country[];
16
+
17
+ export default countries;
18
+ export { countries };
package/index.js ADDED
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+
3
+ const countries = require("./data/countries.json");
4
+
5
+ /**
6
+ * @returns {typeof countries}
7
+ */
8
+ function getCountries() {
9
+ return countries;
10
+ }
11
+
12
+ /**
13
+ * Find a country by ISO alpha-2 shortName (case-insensitive).
14
+ * @param {string} code
15
+ * @returns {(typeof countries)[number] | undefined}
16
+ */
17
+ function getCountryByCode(code) {
18
+ if (!code) return undefined;
19
+ const normalized = String(code).trim().toUpperCase();
20
+ return countries.find((c) => c.shortName.toUpperCase() === normalized);
21
+ }
22
+
23
+ /**
24
+ * Find a country by name (case-insensitive).
25
+ * @param {string} name
26
+ * @returns {(typeof countries)[number] | undefined}
27
+ */
28
+ function getCountryByName(name) {
29
+ if (!name) return undefined;
30
+ const normalized = String(name).trim().toLowerCase();
31
+ return countries.find((c) => c.name.toLowerCase() === normalized);
32
+ }
33
+
34
+ /**
35
+ * Find countries by phone prefix (with or without leading +).
36
+ * @param {string | number} phonePrefix
37
+ * @returns {typeof countries}
38
+ */
39
+ function getCountriesByCallingCode(phonePrefix) {
40
+ if (phonePrefix === undefined || phonePrefix === null) return [];
41
+ const digits = String(phonePrefix).replace(/^\+/, "").trim();
42
+ const withPlus = digits ? `+${digits}` : "";
43
+ return countries.filter(
44
+ (c) => c.phonePrefix === withPlus || c.phonePrefix === digits
45
+ );
46
+ }
47
+
48
+ /**
49
+ * Search countries by partial name match (case-insensitive).
50
+ * @param {string} query
51
+ * @returns {typeof countries}
52
+ */
53
+ function searchCountries(query) {
54
+ if (!query) return [];
55
+ const normalized = String(query).trim().toLowerCase();
56
+ return countries.filter((c) => c.name.toLowerCase().includes(normalized));
57
+ }
58
+
59
+ module.exports = countries;
60
+ module.exports.countries = countries;
61
+ module.exports.default = countries;
62
+ module.exports.getCountries = getCountries;
63
+ module.exports.getCountryByCode = getCountryByCode;
64
+ module.exports.getCountryByName = getCountryByName;
65
+ module.exports.getCountriesByCallingCode = getCountriesByCallingCode;
66
+ module.exports.searchCountries = searchCountries;
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "react-all-countries",
3
+ "version": "1.0.0",
4
+ "description": "All countries data with name, shortName, phonePrefix, and timezones",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./index.d.ts",
10
+ "require": "./index.js",
11
+ "import": "./index.js",
12
+ "default": "./index.js"
13
+ },
14
+ "./data/countries.json": "./data/countries.json"
15
+ },
16
+ "files": [
17
+ "index.js",
18
+ "index.d.ts",
19
+ "data/countries.json",
20
+ "README.md"
21
+ ],
22
+ "keywords": [
23
+ "countries",
24
+ "country",
25
+ "flags",
26
+ "calling-codes",
27
+ "timezone",
28
+ "iso",
29
+ "react",
30
+ "world"
31
+ ],
32
+ "repository": {
33
+ "type": "git",
34
+ "url": ""
35
+ },
36
+ "engines": {
37
+ "node": ">=14"
38
+ },
39
+ "author": "Abdulla al mamun",
40
+ "license": "ISC"
41
+ }