Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate calling codes (callingCodes) from international direct dialing info (idd) #389

Merged
merged 1 commit into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- sort `translations` alphabetically (#384)
### Build
- add `files` in `package.json` to reduce package size (#388)
- generate calling codes (`callingCodes`) from international direct dialing info (`idd`) (#389)

## [v4.0.0] - 2020-04-04
### Breaking changes
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Each line contains the country:
- land borders (`borders`)
- land area in km² (`area`)
- Emoji flag (`flag`)
- calling codes (`callingCodes`)

#### Additional data
The [data](https://github.com/mledoze/countries/tree/master/data) folder contains additional data such as the countries
Expand Down
500 changes: 250 additions & 250 deletions dist/countries-unescaped.json

Large diffs are not rendered by default.

504 changes: 252 additions & 252 deletions dist/countries.csv

Large diffs are not rendered by default.

500 changes: 250 additions & 250 deletions dist/countries.json

Large diffs are not rendered by default.

500 changes: 250 additions & 250 deletions dist/countries.xml

Large diffs are not rendered by default.

500 changes: 250 additions & 250 deletions dist/countries.yml

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/MLD/Converter/AbstractConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ public function save($outputFile = '')
$country = array_intersect_key($country, array_flip($this->fields));
});
}

// generate calling codes from idd codes
if (array_key_exists('idd', array_flip($this->fields))) {
$this->countries = array_map(static function ($country) {
$country['callingCodes'] = array_map(static function ($suffix) use ($country) {
return $country['idd']['root'] . $suffix;
}, $country['idd']['suffixes']);
return $country;
}, $this->countries);
}

return file_put_contents($this->outputDirectory . $outputFile, $this->convert());
}

Expand Down