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

country-region-data

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

country-region-data - npm Package Compare versions

Comparing version 1.4.4 to 1.4.5

142

gruntfile.js

@@ -5,91 +5,95 @@ var _ = require('underscore');

var findDuplicates = function (sourceArray, prop) {
var duplicates = [];
var groupedByCount = _.countBy(sourceArray, function (item) { return item[prop]; });
var duplicates = [];
var groupedByCount = _.countBy(sourceArray, function (item) {
return item[prop];
});
for (var name in groupedByCount) {
if (groupedByCount[name] > 1) {
var whereClause = [];
whereClause[prop] = name;
_.where(sourceArray, whereClause).map(function (item) { duplicates.push(item); });
}
}
for (var name in groupedByCount) {
if (groupedByCount[name] > 1) {
var whereClause = [];
whereClause[prop] = name;
_.where(sourceArray, whereClause).map(function (item) {
duplicates.push(item);
});
}
}
return _.uniq(_.pluck(duplicates, prop));
return _.uniq(_.pluck(duplicates, prop));
};
var getJSON = function (grunt) {
var content = '';
try {
content = grunt.file.readJSON("data.json");
} catch (e) {
grunt.fail.fatal("data.json is not valid JSON. Error: " + e);
}
return content;
var content = '';
try {
content = grunt.file.readJSON("data.json");
} catch (e) {
grunt.fail.fatal("data.json is not valid JSON. Error: " + e);
}
return content;
};
module.exports = function(grunt) {
module.exports = function (grunt) {
function validate () {
var content = getJSON(grunt);
function validate () {
var content = getJSON(grunt);
// check country names and country shortcodes are unique
var duplicateCountryNames = findDuplicates(content, 'countryName');
if (duplicateCountryNames.length > 0) {
grunt.fail.fatal('The country names are not unique - duplicates: ' + duplicateCountryNames);
}
var duplicateCountryShortCodes = findDuplicates(content, 'countryShortCode');
if (duplicateCountryShortCodes.length > 0) {
grunt.fail.fatal('The country short codes are not unique - duplicates: ' + duplicateCountryShortCodes);
}
// check country names and country shortcodes are unique
var duplicateCountryNames = findDuplicates(content, 'countryName');
if (duplicateCountryNames.length > 0) {
grunt.fail.fatal('The country names are not unique - duplicates: ' + duplicateCountryNames);
}
var duplicateCountryShortCodes = findDuplicates(content, 'countryShortCode');
if (duplicateCountryShortCodes.length > 0) {
grunt.fail.fatal('The country short codes are not unique - duplicates: ' + duplicateCountryShortCodes);
}
// now check region names and short codes are unique for each country
content.forEach(function (countryData) {
var duplicateRegionNames = findDuplicates(countryData.regions, 'name');
if (duplicateRegionNames.length > 0) {
grunt.fail.fatal('The region names for ' + countryData.countryName + ' are not unique - duplicates: ' + duplicateRegionNames);
}
});
console.log("PASS!");
}
// now check region names and short codes are unique for each country
content.forEach(function (countryData) {
var duplicateRegionNames = findDuplicates(countryData.regions, 'name');
if (duplicateRegionNames.length > 0) {
grunt.fail.fatal('The region names for ' + countryData.countryName + ' are not unique - duplicates: ' + duplicateRegionNames);
}
});
console.log("PASS!");
}
function findIncomplete () {
var content = getJSON(grunt);
function findIncomplete () {
var content = getJSON(grunt);
var incompleteCountries = [];
content.forEach(function (countryData) {
for (var i=0; i<countryData.regions.length; i++) {
if (!_.has(countryData.regions[i], 'shortCode')) {
incompleteCountries.push(countryData.countryName);
break;
}
}
});
var incompleteCountries = [];
content.forEach(function (countryData) {
for (var i = 0; i < countryData.regions.length; i++) {
if (!_.has(countryData.regions[i], 'shortCode')) {
incompleteCountries.push(countryData.countryName);
break;
}
}
});
if (incompleteCountries.length > 0) {
console.log('\nThe following countries are missing region short codes: \n-', incompleteCountries.join('\n- '));
console.log('\n(' + incompleteCountries.length + ' countries)');
} else {
console.log('All regions now have short codes. Nice!');
}
}
if (incompleteCountries.length > 0) {
console.log('\nThe following countries are missing region short codes: \n-', incompleteCountries.join('\n- '));
console.log('\n(' + incompleteCountries.length + ' countries)');
} else {
console.log('All regions now have short codes. Nice!');
}
}
function umdify () {
var content = getJSON(grunt);
function umdify () {
var content = getJSON(grunt);
var output = libumd("return " + JSON.stringify(content, null, 2) + ";", {
globalAlias: "countryRegionData",
indent: 2
});
var output = libumd("return " + JSON.stringify(content, null, 2) + ";", {
globalAlias: "countryRegionData",
indent: 2
});
grunt.file.write("data.js", output);
grunt.file.write("data.js", output);
console.log('Successfully made a UMD module!');
}
console.log('Successfully made a UMD module!');
}
grunt.registerTask("default", ['validate']);
grunt.registerTask("validate", validate);
grunt.registerTask("findIncomplete", findIncomplete);
grunt.registerTask("umdify", umdify);
grunt.registerTask("default", ['validate']);
grunt.registerTask("validate", validate);
grunt.registerTask("findIncomplete", findIncomplete);
grunt.registerTask("umdify", umdify);
};
{
"name": "country-region-data",
"version": "1.4.4",
"version": "1.4.5",
"description": "List of countries, regions, and their shortcodes.",

@@ -5,0 +5,0 @@ "main": "data.json",

## country-region-data
[![Build Status](https://travis-ci.org/benkeen/country-region-data.svg?branch=master)](https://travis-ci.org/benkeen/country-region-data)
[![Build Status](https://travis-ci.com/country-regions/country-region-data.svg?branch=master)](https://travis-ci.org/country-regions/country-region-data)

@@ -9,4 +9,4 @@ This repo contains a static JSON file of country names, country short codes, country regions, and country region short

I created this repo to house the raw data used for the [country-region-selector](https://github.com/benkeen/country-region-selector),
[react-country-region-selector](https://github.com/benkeen/react-country-region-selector) scripts. I didn't want to
I created this repo to house the raw data used for the [country-region-selector](https://github.com/country-regions/country-region-selector),
[react-country-region-selector](https://github.com/country-regions/react-country-region-selector) scripts. I didn't want to
duplicate it in multiple places and hey, it seemed like this could be useful as a standalone repo.

@@ -64,2 +64,3 @@

- `1.4.5` - Nov 28, 2018. Data updates.
- `1.4.4` - July 8, 2018. Data updates.

@@ -66,0 +67,0 @@ - `1.4.3` - May 29, 2018. More data updates.

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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