New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ideditor/country-coder

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ideditor/country-coder - npm Package Compare versions

Comparing version 4.0.0 to 4.1.0

dist/country-coder.d.ts

2

LICENSE.md
## ISC License
Copyright (c) iD Contributors
Copyright (c) 2019-present, country-coder contributors

@@ -5,0 +5,0 @@ Permission to use, copy, modify, and/or distribute this software for any

{
"name": "@ideditor/country-coder",
"version": "4.0.0",
"version": "4.1.0",
"description": "Convert longitude-latitude pairs to ISO 3166-1 codes quickly and locally",
"repository": "github:ideditor/country-coder",
"main": "built/cjs/country-coder.js",
"module": "built/es6/country-coder.js",
"license": "ISC",

@@ -17,14 +15,20 @@ "keywords": [

],
"files": [
"dist/",
"src/"
],
"source": "./src/country-coder.ts",
"types": "./dist/country-coder.d.ts",
"exports": "./dist/country-coder.modern.js",
"main": "./dist/country-coder.js",
"module": "./dist/country-coder.module.js",
"unpkg": "./dist/country-coder.umd.js",
"devDependencies": {
"@babel/core": "^7.5.4",
"@babel/preset-env": "^7.5.4",
"@mapbox/geojson-rewind": "^0.5.0",
"@types/node": "^14.0.11",
"babel-jest": "^26.0.1",
"jest": "^26.0.1",
"jest": "^27.0.3",
"jest-extended": "^0.11.2",
"microbundle": "^0.13.1",
"npm-run-all": "^4.0.0",
"prettier": "^2.0.5",
"shx": "^0.3.0",
"typescript": "^4.0.2"
"shx": "^0.3.0"
},

@@ -36,10 +40,30 @@ "dependencies": {

"all": "npm-run-all -s clean build pretty test",
"clean": "shx rm -rf ./built/*",
"clean": "shx rm -rf dist",
"build": "npm-run-all -s format-json build:**",
"build:bundles": "microbundle --no-compress --external none",
"format-json": "node ./scripts/format-json.js",
"build:es6": "tsc --project ./tsconfig.es6.json && cp -R src/data built/es6/",
"build:cjs": "tsc --project ./tsconfig.cjs.json && cp -R src/data built/cjs/",
"test": "jest --config jest.config.js tests/*.js",
"pretty": "prettier --write \"./**/*.{ts,js}\""
"test": "jest tests/*.js",
"pretty": "prettier --write \"./{src,tests}/*.{ts,js}\""
},
"publishConfig": {
"access": "public"
},
"jest": {
"collectCoverage": true,
"collectCoverageFrom": [
"**/dist/*.js",
"!**/node_modules/**"
],
"coverageDirectory": "<rootDir>/.coverage",
"setupFilesAfterEnv": [
"jest-extended"
],
"verbose": true
},
"prettier": {
"arrowParens": "always",
"printWidth": 100,
"singleQuote": true,
"trailingComma": "none"
},
"engines": {

@@ -46,0 +70,0 @@ "node": ">=10",

@@ -0,3 +1,3 @@

[![build](https://github.com/ideditor/country-coder/workflows/build/badge.svg)](https://github.com/ideditor/country-coder/actions?query=workflow%3A%22build%22)
[![npm version](https://badge.fury.io/js/%40ideditor%2Fcountry-coder.svg)](https://badge.fury.io/js/%40ideditor%2Fcountry-coder)
[![Build Status](https://travis-ci.org/ideditor/country-coder.svg?branch=master)](https://travis-ci.org/ideditor/country-coder)

@@ -102,14 +102,16 @@ # country-coder

* [iso1A2Code](#iso1A2Code)(query: Location | string | number, opts?: CodingOptions): string?
* [iso1A2Codes](#iso1A2Codes)(query: Location): [string]
* [iso1A2Codes](#iso1A2Codes)(query: Location | Bbox): [string]
* [iso1A3Code](#iso1A3Code)(query: Location | string | number, opts?: CodingOptions): string?
* [iso1A3Codes](#iso1A3Codes)(query: Location): [string]
* [iso1A3Codes](#iso1A3Codes)(query: Location | Bbox): [string]
* [iso1N3Code](#iso1N3Code)(query: Location | string | number, opts?: CodingOptions): string?
* [iso1N3Codes](#iso1N3Codes)(query: Location): [string]
* [iso1N3Codes](#iso1N3Codes)(query: Location | Bbox): [string]
* [m49Code](#m49Code)(query: Location | string | number, opts?: CodingOptions): string?
* [m49Codes](#m49Codes)(query: Location): [string]
* [m49Codes](#m49Codes)(query: Location | Bbox): [string]
* [wikidataQID](#wikidataQID)(query: Location | string | number, opts?: CodingOptions): string?
* [wikidataQIDs](#wikidataQIDs)(query: Location): [string]
* [wikidataQIDs](#wikidataQIDs)(query: Location | Bbox): [string]
* [emojiFlag](#emojiFlag)(query: Location | string | number, opts?: CodingOptions): string?
* [emojiFlags](#emojiFlags)(query: Location): [string]
* [featuresContaining](#featuresContaining)(query: Location | string | number, strict: boolean): [RegionFeature]
* [emojiFlags](#emojiFlags)(query: Location | Bbox): [string]
* [ccTLD](#ccTLD)(query: Location | string | number, opts?: CodingOptions): string?
* [ccTLDs](#ccTLDs)(query: Location | Bbox): [string]
* [featuresContaining](#featuresContaining)(query: Location | Bbox | string | number, strict: boolean): [RegionFeature]
* [featuresIn](#featuresIn)(id: string | number, strict: boolean): [RegionFeature]

@@ -130,2 +132,3 @@ * [aggregateFeature](#aggregateFeature)(id: string | number): [RegionFeature]

* [Vec2](#Vec2): [number, number]
* [Bbox](#Bbox): [number, number, number, number]
* [PointGeometry](#PointGeometry): a GeoJSON Point geometry object

@@ -156,2 +159,3 @@ * [PointFeature](#PointFeature): a GeoJSON feature object with a Point geometry type

feature('🇬🇧'); // returns {United Kingdom}
feature('.uk'); // returns {United Kingdom}
feature('UK'); // returns {United Kingdom}

@@ -180,2 +184,3 @@ feature('IM'); // returns {Isle of Man}

iso1A2Code('🇬🇧'); // returns 'GB'
iso1A2Code('.uk'); // returns 'GB'
iso1A2Code('UK'); // returns 'GB'

@@ -191,5 +196,5 @@ iso1A2Code('IMN'); // returns 'IM'

<a name="iso1A2Codes" href="#iso1A2Codes">#</a> <b>iso1A2Codes</b>(query: Location): [string]
<a name="iso1A2Codes" href="#iso1A2Codes">#</a> <b>iso1A2Codes</b>(query: Location | Bbox): [string]
Returns all the ISO 3166-1 alpha-2 codes for the given location, if any.
Returns all the ISO 3166-1 alpha-2 codes for the given location or bounding box, if any.

@@ -219,2 +224,3 @@ ```js

iso1A3Code('🇬🇧'); // returns 'GBR'
iso1A3Code('.uk'); // returns 'GBR'
iso1A3Code('UK'); // returns 'GBR'

@@ -230,5 +236,5 @@ iso1A3Code('IM'); // returns 'IMN'

<a name="iso1A3Codes" href="#iso1A3Codes">#</a> <b>iso1A3Codes</b>(query: Location): [string]
<a name="iso1A3Codes" href="#iso1A3Codes">#</a> <b>iso1A3Codes</b>(query: Location | Bbox): [string]
Returns all the ISO 3166-1 alpha-3 codes for the given location, if any.
Returns all the ISO 3166-1 alpha-3 codes for the given location of bounding box, if any.

@@ -257,2 +263,3 @@ ```js

iso1N3Code('🇬🇧'); // returns '826'
iso1N3Code('.uk'); // returns '826'
iso1N3Code('UK'); // returns '826'

@@ -269,5 +276,5 @@ iso1N3Code('IM'); // returns '833'

<a name="iso1N3Codes" href="#iso1N3Codes">#</a> <b>iso1N3Codes</b>(query: Location): [string]
<a name="iso1N3Codes" href="#iso1N3Codes">#</a> <b>iso1N3Codes</b>(query: Location | Bbox): [string]
Returns all the ISO 3166-1 numeric-3 codes for the given location, if any.
Returns all the ISO 3166-1 numeric-3 codes for the given location or bounding box, if any.

@@ -296,2 +303,3 @@ ```js

m49Code('🇬🇧'); // returns '826'
m49Code('.uk'); // returns '826'
m49Code('UK'); // returns '826'

@@ -308,5 +316,5 @@ m49Code('IM'); // returns '833'

<a name="m49Codes" href="#m49Codes">#</a> <b>m49Codes</b>(query: Location): [string]
<a name="m49Codes" href="#m49Codes">#</a> <b>m49Codes</b>(query: Location | Bbox): [string]
Returns all the United Nations M49 codes for the given location, if any.
Returns all the United Nations M49 codes for the given location or bounding box, if any.

@@ -336,2 +344,3 @@ ```js

wikidataQID('🇬🇧'); // returns 'Q145'
wikidataQID('.uk'); // returns 'Q145'
wikidataQID('UK'); // returns 'Q145'

@@ -347,5 +356,5 @@ wikidataQID('IM'); // returns 'Q9676'

<a name="wikidataQIDs" href="#wikidataQIDs">#</a> <b>wikidataQIDs</b>(query: Location): [string]
<a name="wikidataQIDs" href="#wikidataQIDs">#</a> <b>wikidataQIDs</b>(query: Location | Bbox): [string]
Returns all the Wikidata QIDs for the given location, if any.
Returns all the Wikidata QIDs for the given location or bounding box, if any.

@@ -385,5 +394,5 @@ ```js

<a name="emojiFlags" href="#emojiFlags">#</a> <b>emojiFlags</b>(query: Location): [string]
<a name="emojiFlags" href="#emojiFlags">#</a> <b>emojiFlags</b>(query: Location | Bbox): [string]
Returns all the emoji flag sequences for the given location, if any.
Returns all the emoji flag sequences for the given location or bounding box, if any.

@@ -400,7 +409,44 @@ ```js

<a name="featuresContaining" href="#featuresContaining">#</a> <b>featuresContaining</b>(query: Location | string | number, strict: boolean): [RegionFeature]
<a name="ccTLD" href="#ccTLD">#</a> <b>ccTLD</b>(query: Location | string | number, opts?: CodingOptions): string?
Returns all the the features of any type that contain or match the given location or identifier, if any. If `strict` is `true` then only features that are strictly containing are returned.
Returns the country code top-level internet domain for the given location or identifier and options, if found.
```js
ccTLD([-4.5, 54.2]); // returns '.uk'
ccTLD([-4.5, 54.2], { level: 'territory' }); // returns '.im'
ccTLD([0, 90]); // returns null
ccTLD('GB'); // returns '.uk'
ccTLD('GBR'); // returns '.uk'
ccTLD('826'); // returns '.uk'
ccTLD(826); // returns '.uk'
ccTLD('Q145'); // returns '.uk'
ccTLD('UK'); // returns '.uk'
ccTLD('IM'); // returns '.im'
ccTLD('United Kingdom'); // returns '.uk'
let pointGeoJSON = { type: 'Feature', geometry: { type: 'Point', coordinates: [-4.5, 54.2] } };
ccTLD(pointGeoJSON); // returns '.uk'
ccTLD(pointGeoJSON.geometry); // returns '.uk'
```
<a name="ccTLDs" href="#ccTLDs">#</a> <b>ccTLDs</b>(query: Location | Bbox): [string]
Returns all the country code top-level internet domains for the given location or bounding box, if any.
```js
ccTLDs([-4.5, 54.2]); // returns ['.im', '.uk']
ccTLDs([0, 90]); // returns []
let pointGeoJSON = { type: 'Feature', geometry: { type: 'Point', coordinates: [-4.5, 54.2] } };
ccTLDs(pointGeoJSON); // returns ['.im', '.uk']
ccTLDs(pointGeoJSON.geometry); // returns ['.im', '.uk']
```
<a name="featuresContaining" href="#featuresContaining">#</a> <b>featuresContaining</b>(query: Location | Bbox | string | number, strict: boolean): [RegionFeature]
Returns all the the features of any type that contain or match the given location, bounding box, or identifier, if any. If `strict` is `true` and `query` is an identifier, then only features that are strictly containing are returned.
```js
featuresContaining([-4.5, 54.2]); // returns [{Isle of Man}, {Crown Dependencies}, {United Kingdom}, {Northern Europe}, {Europe}, {United Nations}, {World}]

@@ -416,2 +462,3 @@ featuresContaining([0, 51.5]); // returns [{England}, {Countries of the United Kingdom}, {United Kingdom}, {Great Britain}, {Northern Europe}, {Europe}, {United Nations}, {World}]

featuresContaining('🇬🇧'); // returns [{United Kingdom}, {United Nations}, {World}]
featuresContaining('.uk'); // returns [{United Kingdom}, {United Nations}, {World}]
featuresContaining('UK'); // returns [{United Kingdom}, {United Nations}, {World}]

@@ -439,2 +486,3 @@ featuresContaining('154'); // returns [{Northern Europe}, {Europe}, {World}]

featuresIn('🇨🇳'); // returns [{China}, {Mainland China}, {Hong Kong}, {Macau}]
featuresIn('.cn'); // returns [{China}, {Mainland China}, {Hong Kong}, {Macau}]
featuresIn('China'); // returns [{China}, {Mainland China}, {Hong Kong}, {Macau}]

@@ -456,2 +504,3 @@ featuresIn('CN', true); // returns [{Mainland China}, {Hong Kong}, {Macau}]

aggregateFeature('🇨🇳'); // returns Mainland China, Hong Kong, and Macau as one feature
aggregateFeature('.cn'); // returns Mainland China, Hong Kong, and Macau as one feature
aggregateFeature('China'); // returns Mainland China, Hong Kong, and Macau as one feature

@@ -477,2 +526,3 @@ ```

isIn('🇮🇲', '🇬🇧'); // returns true
isIn('.im', '.uk'); // returns true
isIn('United Kingdom', 'Europe'); // returns true

@@ -504,5 +554,7 @@ isIn('United Kingdom', 'Africa'); // returns false

isInEuropeanUnion('🇩🇪'); // returns true
isInEuropeanUnion('.de'); // returns true
isInEuropeanUnion('Germany'); // returns true
isInEuropeanUnion('GB'); // returns false
isInEuropeanUnion('IM'); // returns false
isInEuropeanUnion('.im'); // returns false
isInEuropeanUnion('CH'); // returns false

@@ -534,5 +586,7 @@

isInUnitedNations('🇩🇪'); // returns true
isInUnitedNations('.de'); // returns true
isInUnitedNations('Germany'); // returns true
isInUnitedNations('GB'); // returns true
isInUnitedNations('IM'); // returns true
isInUnitedNations('.im'); // returns true
isInUnitedNations('CH'); // returns true

@@ -564,2 +618,3 @@ isInUnitedNations('XK'); // returns false (Kosovo)

driveSide('🇬🇧'); // returns 'left'
driveSide('.uk'); // returns 'left'
driveSide('UK'); // returns 'left'

@@ -590,2 +645,3 @@ driveSide('United Kingdom'); // returns 'left'

roadSpeedUnit('🇬🇧'); // returns 'mph'
roadSpeedUnit('.uk'); // returns 'mph'
roadSpeedUnit('UK'); // returns 'mph'

@@ -616,2 +672,3 @@ roadSpeedUnit('United Kingdom'); // returns 'mph'

roadHeightUnit('🇬🇧'); // returns 'ft'
roadHeightUnit('.uk'); // returns 'ft'
roadHeightUnit('UK'); // returns 'ft'

@@ -641,2 +698,3 @@ roadHeightUnit('United Kingdom'); // returns 'ft'

callingCodes('🇬🇧'); // returns ['44']
callingCodes('.uk'); // returns ['44']
callingCodes('UK'); // returns ['44']

@@ -668,3 +726,9 @@ callingCodes('United Kingdom'); // returns ['44']

<a name="Bbox" href="#Bbox">#</a> <b>Bbox</b>
A bounding box represented as an array of four numbers `[minLongitude, minLatitude, maxLongitude, maxLatitude]` referenced to the WGS 84 datum.
`[number, number, number, number]`
<a name="PointGeometry" href="#PointGeometry">#</a> <b>PointGeometry</b>

@@ -711,2 +775,3 @@

- `emojiFlag`: `string`, the emoji flag sequence derived from this feature's ISO 3166-1 alpha-2 code
- `ccTLD`: `string`, the ccTLD (country code top-level internet domain)
- `nameEn`: `string`, common name in English

@@ -713,0 +778,0 @@ - `aliases`: `[string]`, additional identifiers which can be used to look up this feature

@@ -26,2 +26,5 @@ import whichPolygon from 'which-polygon';

// The ccTLD (country code top-level domain)
ccTLD: string | undefined;
// The common English name

@@ -92,2 +95,3 @@ nameEn: string;

type Vec2 = [number, number]; // [lon, lat]
type Bbox = [number, number, number, number]; // [minLon, minLat, maxLon, maxLat]
type PointGeometry = { type: string; coordinates: Vec2 };

@@ -118,4 +122,10 @@ type PointFeature = { type: string; geometry: PointGeometry; properties: any };

function canonicalID(id: string): string {
return id.replace(idFilterRegex, '').toUpperCase();
function canonicalID(id: string | null): string {
let s = id || '';
if (s.charAt(0) === '.') {
// skip replace if it leads with a '.' (e.g. a ccTLD like '.de', '.la')
return s.toUpperCase();
} else {
return s.replace(idFilterRegex, '').toUpperCase();
}
}

@@ -142,4 +152,5 @@

function loadDerivedDataAndCaches(borders) {
let identifierProps = ['iso1A2', 'iso1A3', 'm49', 'wikidata', 'emojiFlag', 'nameEn'];
let identifierProps = ['iso1A2', 'iso1A3', 'm49', 'wikidata', 'emojiFlag', 'ccTLD', 'nameEn'];
let geometryFeatures: Array<RegionFeature> = [];
for (let i in borders.features) {

@@ -153,2 +164,3 @@ let feature = borders.features[i];

loadM49(feature);
loadTLD(feature);
loadIsoStatus(feature);

@@ -243,2 +255,11 @@ loadLevel(feature);

function loadTLD(feature: RegionFeature) {
let props = feature.properties;
if (props.level === 'unitedNations') return; // `.un` is not a ccTLD
if (!props.ccTLD && props.iso1A2) {
// ccTLD is nearly the same as iso1A2, so we only need to explicitly code any exceptions
props.ccTLD = '.' + props.iso1A2.toLowerCase();
}
}
function loadIsoStatus(feature: RegionFeature) {

@@ -496,2 +517,3 @@ let props = feature.properties;

let stringID: string;
if (typeof id === 'number') {

@@ -510,2 +532,8 @@ stringID = id.toString();

function smallestFeaturesForBbox(bbox: Bbox): [RegionFeature] {
return whichPolygonGetter.bbox(bbox).map(function (props) {
return featuresByCode[props.id];
});
}
function smallestOrMatchingFeature(query: Location | string | number): RegionFeature | null {

@@ -595,3 +623,14 @@ if (typeof query === 'object') {

function propertiesForQuery(query: Location, property: string): Array<string> {
// Returns the ccTLD (country code top-level domain) for the feature matching the arguments, if any
export function ccTLD(
query: Location | string | number,
opts: CodingOptions = defaultOpts
): string | null {
opts.withProp = 'ccTLD';
let match = feature(query, opts);
if (!match) return null;
return match.properties.ccTLD || null;
}
function propertiesForQuery(query: Location | Bbox, property: string): Array<string> {
let features = featuresContaining(query, false);

@@ -606,3 +645,3 @@ return features

// Returns all the ISO 3166-1 alpha-2 codes of features at the location
export function iso1A2Codes(query: Location): Array<string> {
export function iso1A2Codes(query: Location | Bbox): Array<string> {
return propertiesForQuery(query, 'iso1A2');

@@ -612,3 +651,3 @@ }

// Returns all the ISO 3166-1 alpha-3 codes of features at the location
export function iso1A3Codes(query: Location): Array<string> {
export function iso1A3Codes(query: Location | Bbox): Array<string> {
return propertiesForQuery(query, 'iso1A3');

@@ -618,3 +657,3 @@ }

// Returns all the ISO 3166-1 numeric-3 codes of features at the location
export function iso1N3Codes(query: Location): Array<string> {
export function iso1N3Codes(query: Location | Bbox): Array<string> {
return propertiesForQuery(query, 'iso1N3');

@@ -624,3 +663,3 @@ }

// Returns all the UN M49 codes of features at the location
export function m49Codes(query: Location): Array<string> {
export function m49Codes(query: Location | Bbox): Array<string> {
return propertiesForQuery(query, 'm49');

@@ -630,3 +669,3 @@ }

// Returns all the Wikidata QIDs of features at the location
export function wikidataQIDs(query: Location): Array<string> {
export function wikidataQIDs(query: Location | Bbox): Array<string> {
return propertiesForQuery(query, 'wikidata');

@@ -636,27 +675,48 @@ }

// Returns all the emoji flag sequences of features at the location
export function emojiFlags(query: Location): Array<string> {
export function emojiFlags(query: Location | Bbox): Array<string> {
return propertiesForQuery(query, 'emojiFlag');
}
// Returns all the ccTLD (country code top-level domain) sequences of features at the location
export function ccTLDs(query: Location | Bbox): Array<string> {
return propertiesForQuery(query, 'ccTLD');
}
// Returns the feature matching `query` and all features containing it, if any.
// If passing `true` for `strict`, an exact match will not be included
export function featuresContaining(
query: Location | string | number,
query: Location | Bbox | string | number,
strict?: boolean
): Array<RegionFeature> {
let feature = smallestOrMatchingFeature(query);
if (!feature) return [];
let matchingFeatures: Array<RegionFeature>;
let features: Array<RegionFeature> = [];
if (Array.isArray(query) && query.length === 4) {
// check if bounding box
matchingFeatures = smallestFeaturesForBbox(<Bbox>query);
} else {
let smallestOrMatching = smallestOrMatchingFeature(<Location | string | number>query);
matchingFeatures = smallestOrMatching ? [smallestOrMatching] : [];
}
if (!matchingFeatures.length) return [];
let returnFeatures: Array<RegionFeature>;
if (!strict || typeof query === 'object') {
features.push(feature);
returnFeatures = matchingFeatures.slice();
} else {
returnFeatures = [];
}
let properties = feature.properties;
for (let i in properties.groups) {
let groupID = properties.groups[i];
features.push(featuresByCode[groupID]);
for (let j in matchingFeatures) {
let properties = matchingFeatures[j].properties;
for (let i in properties.groups) {
let groupID = properties.groups[i];
let groupFeature = featuresByCode[groupID];
if (returnFeatures.indexOf(groupFeature) === -1) {
returnFeatures.push(groupFeature);
}
}
}
return features;
return returnFeatures;
}

@@ -663,0 +723,0 @@

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