react-all-countries 1.0.0 → 1.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 +14 -17
- package/index.d.ts +1 -4
- package/index.js +12 -12
- 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
|
-
|
|
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,
|
|
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`
|
|
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,10 @@ 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
11
|
export function getCountries(): Country[];
|
|
12
12
|
export function getCountryByCode(code: string): Country | undefined;
|
|
13
13
|
export function getCountryByName(name: string): Country | undefined;
|
|
14
14
|
export function getCountriesByCallingCode(phonePrefix: string | number): Country[];
|
|
15
15
|
export function searchCountries(query: string): Country[];
|
|
16
|
-
|
|
17
|
-
export default countries;
|
|
18
|
-
export { countries };
|
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
const countries = require(
|
|
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(/^\+/,
|
|
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 =
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
59
|
+
module.exports = {
|
|
60
|
+
countries,
|
|
61
|
+
getCountries,
|
|
62
|
+
getCountryByCode,
|
|
63
|
+
getCountryByName,
|
|
64
|
+
getCountriesByCallingCode,
|
|
65
|
+
searchCountries,
|
|
66
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-all-countries",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "All countries data with name, shortName, phonePrefix, and
|
|
3
|
+
"version": "1.0.1",
|
|
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": {
|