react-all-countries 1.0.0 → 1.0.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.
Files changed (4) hide show
  1. package/README.md +14 -17
  2. package/index.d.ts +10 -8
  3. package/index.js +12 -12
  4. package/package.json +2 -2
package/README.md CHANGED
@@ -11,31 +11,28 @@ npm install react-all-countries
11
11
  ## Usage
12
12
 
13
13
  ```js
14
- const countries = require("react-all-countries");
15
-
16
- const {
17
- getCountryByCode,
18
- getCountryByName,
19
- getCountriesByCallingCode,
20
- searchCountries,
21
- } = require("react-all-countries");
14
+ import { countries, getCountryByCode } from "react-all-countries";
22
15
 
23
16
  console.log(countries.length); // 254
17
+ console.log(countries);
18
+ // [
19
+ // {
20
+ // name: 'Bangladesh',
21
+ // shortName: 'BD',
22
+ // phonePrefix: '+880',
23
+ // timezones: 'UTC+06:00',
24
+ // flag: 'https://flags.restcountries.com/v5/svg/bd.svg'
25
+ // },
26
+ // ...
27
+ // ]
24
28
 
25
29
  const bd = getCountryByCode("BD");
26
- // {
27
- // name: 'Bangladesh',
28
- // shortName: 'BD',
29
- // phonePrefix: '+880',
30
- // timezones: 'UTC+06:00',
31
- // flag: 'https://flags.restcountries.com/v5/svg/bd.svg'
32
- // }
33
30
  ```
34
31
 
35
32
  ### React example
36
33
 
37
34
  ```jsx
38
- import countries, { getCountryByCode } from "react-all-countries";
35
+ import { countries, getCountryByCode } from "react-all-countries";
39
36
 
40
37
  function CountrySelect() {
41
38
  return (
@@ -72,7 +69,7 @@ interface Country {
72
69
 
73
70
  | Export | Description |
74
71
  |--------|-------------|
75
- | `countries` / default | Full country array |
72
+ | `countries` | Full country array (JSON) |
76
73
  | `getCountries()` | Same as `countries` |
77
74
  | `getCountryByCode(code)` | Find by `shortName` |
78
75
  | `getCountryByName(name)` | Find by exact `name` |
package/index.d.ts CHANGED
@@ -6,13 +6,15 @@ export interface Country {
6
6
  flag: string;
7
7
  }
8
8
 
9
- declare const countries: Country[];
9
+ export declare const countries: Country[];
10
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[];
11
+ export declare function getCountries(): Country[];
12
+ export declare function getCountryByCode(code: string): Country | undefined;
13
+ export declare function getCountryByName(name: string): Country | undefined;
14
+ export declare function getCountriesByCallingCode(
15
+ phonePrefix: string | number
16
+ ): Country[];
17
+ export declare function searchCountries(query: string): Country[];
16
18
 
17
- export default countries;
18
- export { countries };
19
+ declare const _default: Country[];
20
+ export default _default;
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
- const countries = require("./data/countries.json");
3
+ const countries = require('./data/countries.json');
4
4
 
5
5
  /**
6
6
  * @returns {typeof countries}
@@ -38,8 +38,8 @@ function getCountryByName(name) {
38
38
  */
39
39
  function getCountriesByCallingCode(phonePrefix) {
40
40
  if (phonePrefix === undefined || phonePrefix === null) return [];
41
- const digits = String(phonePrefix).replace(/^\+/, "").trim();
42
- const withPlus = digits ? `+${digits}` : "";
41
+ const digits = String(phonePrefix).replace(/^\+/, '').trim();
42
+ const withPlus = digits ? `+${digits}` : '';
43
43
  return countries.filter(
44
44
  (c) => c.phonePrefix === withPlus || c.phonePrefix === digits
45
45
  );
@@ -56,11 +56,11 @@ function searchCountries(query) {
56
56
  return countries.filter((c) => c.name.toLowerCase().includes(normalized));
57
57
  }
58
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;
59
+ exports.__esModule = true;
60
+ exports.countries = countries;
61
+ exports.getCountries = getCountries;
62
+ exports.getCountryByCode = getCountryByCode;
63
+ exports.getCountryByName = getCountryByName;
64
+ exports.getCountriesByCallingCode = getCountriesByCallingCode;
65
+ exports.searchCountries = searchCountries;
66
+ exports.default = countries;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-all-countries",
3
- "version": "1.0.0",
4
- "description": "All countries data with name, shortName, phonePrefix, and timezones",
3
+ "version": "1.0.2",
4
+ "description": "All countries data with name, shortName, phonePrefix, timezones, and flag",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "exports": {