Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-select-country-list

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-select-country-list - npm Package Compare versions

Comparing version 1.0.7 to 2.0.0

94

country-list.js

@@ -1,50 +0,68 @@

'use strict'
class CountryList {
constructor() {
this.data = require('./data.json')
this.labelMap = {}
this.valueMap = {}
var data = require('./data.json')
this.data.forEach(country => {
this.labelMap[country.label.toLowerCase()] = country.value
this.valueMap[country.value.toLowerCase()] = country.label
})
}
/**
* Precompute label and value lookups.
*/
var labelMap = {}
var valueMap = {}
data.forEach(function (country) {
labelMap[country.label.toLowerCase()] = country.value
valueMap[country.value.toLowerCase()] = country.label
})
getValue(label) {
return this.labelMap[label.toLowerCase()]
}
module.exports = CountryList
function CountryList () {
if (!(this instanceof CountryList)) return new CountryList()
};
getLabel(value) {
return this.valueMap[value.toLowerCase()]
}
CountryList.prototype.getValue = function getValue (label) {
return labelMap[label.toLowerCase()]
}
getLabels() {
return this.data.map(country => country.label)
}
CountryList.prototype.getLabel = function getLabel (value) {
return valueMap[value.toLowerCase()]
}
getValues() {
return this.data.map(country => country.value)
}
CountryList.prototype.getLabels = function getLabels () {
return data.map(function (country) {
return country.label
})
}
getLabelList() {
return this.labelMap
}
CountryList.prototype.getValues = function getValues () {
return data.map(function (country) {
return country.value
})
}
getValueList() {
return this.valueMap
}
CountryList.prototype.getValueList = function () {
return valueMap
getData() {
return this.data
}
setLabel(value, label) {
this.data.forEach(country => {
if (country.value === value) {
country.label = label
this.valueMap[country.value.toLowerCase()] = country.label
}
})
return this
}
setEmpty(label) {
this.data.unshift({
value: '',
label: label,
})
this.valueMap[''] = label
this.labelMap[label] = ''
return this
}
}
CountryList.prototype.getLabelList = function () {
return labelMap
const countryList = () => {
if (!(this instanceof CountryList)) return new CountryList()
}
CountryList.prototype.getData = function getData () {
return data
}
module.exports = countryList
{
"name": "react-select-country-list",
"version": "1.0.7",
"version": "2.0.0",
"description": "Maps ISO 3166-1-alpha-2 codes to English country names and match react-select options props",

@@ -9,10 +9,10 @@ "main": "country-list.js",

],
"dependencies": {},
"dependencies": {
"lodash": "^4.17.11"
},
"devDependencies": {
"csv-parser": "^1.11.0",
"standard": "^8.4.0",
"tap": "^7.1.2"
},
"scripts": {
"pretest": "standard",
"test": "tap test/*.js"

@@ -27,2 +27,3 @@ },

"countries",
"country-list",
"react-select"

@@ -29,0 +30,0 @@ ],

@@ -69,3 +69,3 @@ # react-select-country-list

### getLabel(code)
### getLabel(value)

@@ -96,4 +96,29 @@ Expects a two-digit country code.

### setLabel(value, label)
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.
#### Usage
```js
// Make 'Viet Nam' -> 'Vietnam'
countries.setLabel('VN', 'Vietnam').getLabel('VN') // 'Vietnam'
```
### setEmpty(label)
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.
#### Usage
```js
countries.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.
```js
countries.setLabel('VN', 'Vietnam').setEmpty('Select a Country').getLabel('VN') // 'Vietnam'
```
## License
MIT
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc