Gathering detailed insights and metrics for @harcorp/react-select-country-list
Gathering detailed insights and metrics for @harcorp/react-select-country-list
npm install @harcorp/react-select-country-list
Typescript
Module System
Node Version
NPM Version
77.6
Supply Chain
98.7
Quality
75.8
Maintenance
100
Vulnerability
100
License
Total Downloads
2,591
Last Day
3
Last Week
13
Last Month
53
Last Year
1,097
Minified
Minified + Gzipped
Latest Version
0.2.3
Package Id
@harcorp/react-select-country-list@0.2.3
Unpacked Size
1.37 MB
Size
333.12 kB
File Count
11
NPM Version
8.19.3
Node Version
16.19.1
Publised On
15 Sept 2023
Cumulative downloads
Total Downloads
Last day
-81.3%
3
Compared to previous day
Last week
-23.5%
13
Compared to previous week
Last month
1.9%
53
Compared to previous month
Last year
-26.6%
1,097
Compared to previous year
This package take country-list as reference, and make it more friendly to react-select
Maps ISO 3166-1-alpha-2 codes to English country names and match react-select options props.
Uses data from https://www.iso.org/iso-3166-country-codes.html
1npm install react-select-country-list --save
or
1yarn add react-select-country-list
1import React, { useState, useMemo } from 'react' 2import Select from 'react-select' 3import countryList from 'react-select-country-list' 4 5function CountrySelector() { 6 const [value, setValue] = useState('') 7 const options = useMemo(() => countryList().getData(), []) 8 9 const changeHandler = value => { 10 setValue(value) 11 } 12 13 return <Select options={options} value={value} onChange={changeHandler} /> 14} 15 16export default CountrySelector 17
All input is case-insensitive.
Expects the English country name.
Returns the code for that country.
If not found, it returns undefined
.
Expects a two-digit country code.
Returns the name for that country.
If not found, it returns undefined
.
Returns an array of all country codes.
Returns an array of all country names.
Returns a key-value object of all countries using the code as key.
Returns a key-value object of all countries using the name as key.
Returns an array of all country information, in the same format as it gets imported.
Due to different perspectives among different regions, this method can help developers customize the label of specific country. What's more, it can be chained with another methods above.
1// Make 'Viet Nam' -> 'Vietnam' 2countries.setLabel('VN', 'Vietnam').getLabel('VN') // 'Vietnam'
You may want an empty value option in the list, so here's the helper function for you. Again, it can be chained with another methods above.
1countries.setEmpty('Select a Country').getLabel('') // 'Select a Country'
We can even chain setLabel
and setEmpty
together to have list with an empty option and the modified label.
1countries.setLabel('VN', 'Vietnam').setEmpty('Select a Country').getLabel('VN') // 'Vietnam'
You may want to display native name of countries, this is the method for you. The data source of native names can be found here
1countries.native().getLabel('TW') // 臺灣
MIT
No vulnerabilities found.
No security vulnerabilities found.