Giter VIP home page Giter VIP logo

country-coder's People

Contributors

1ec5 avatar bdon avatar bhousel avatar bonkles avatar dependabot[bot] avatar quincylvania avatar ukchris-osm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

country-coder's Issues

A few more sub-country pseudo codes

This is not a high priority issue, but maybe a nice-to-have.

CountryCoder and LocationConflation are integrated into Name Suggestion Index now which is pretty cool..
Check out the entries on https://nsi.guide to see what I mean:

Screenshot 2020-07-17 10 59 51

Screenshot 2020-07-17 11 00 03

A thing I am running into is:
Some countries like US, GB, FR include a bunch of sub territories. Technically the US includes Marshall Islands and GB includes Bermuda. FR is nice because we can use the code FX to mean "Metropolitan France". But for some situations, it would be really nice to have dedicated code strings for:

I'm not familiar with what all countries contain territories, and not sure to what extent Country Coder already includes some of these.. just brainstorming that it would be nice to say 'conus' or 'scotland' to return just those parts.

Regions

I'd like to be able to also get regions, which would sit at a level higher than countries.
Each country could belong to a single region, and there could be a lookup table or something.

There are many ways to slice up the world, but I'm thinking these 12 (+ Antarctica) would give us a bunch of flexibility:

  • North America
  • Central America
  • South America
  • Western Europe
  • Eastern Europe
  • Middle East
  • North Africa
  • Sub-Saharan Africa
  • Central and South Asia
  • Southeast Asia
  • East Asia
  • Oceania
  • Antarctica

Get rid of prettier

Just wanted to paste a screenshot of the thing that is making me give up on prettier for good.

Screenshot 2023-07-11 at 4 50 33 PM

Sub-regions, repeated data and .geojson hosting

To be honest, I'm not sure where would be best to ask about this, either here, location-conflation or the Name Suggestion Index, so apologies if this isn't relevant here.

Basically, over on the Name Suggestion Index, there is a /features/ folder that I've expanded recently, and it contains .geojson files for mapping certain areas that a brand should be limited to, and this is powered by location-conflation and seems to work well.

However, I've noticed that the osm-community-index has the same concept, with a /features/ folder linking areas where an OSM community group is based.

Within both projects are similar region files, and I can see both projects expanding with similar data. One example being the West Midlands in England (NSI vs OCI) which is basically the same region.

I imagine other projects exist (or will exist) with the same goal of having sub-regions where the .geojson files are similar.

I gather that this project (country-coder) doesn't intend to expand into sub-regions, so as to prevent it becoming too large, and I can understand that.

However, is there any scope for hosting sub-region .geojson files within the repository (or location-conflation) so there is a central place for users to reference the region files, without having to recreate them for their own project?

ISO 639 Language Codes

Heya,

Would you be open to accepting a PR to add 'Official Languages' per-region?

I hunted around for an official source & didn't find many decent ISO 3166 <> 639 mapping files.

This file from geonames contains a bunch of extra fields we could adopt, including the languages (which are correct from my spot checking):
http://download.geonames.org/export/dump/countryInfo.txt

Another option would be to use a locale dataset from a linux distro, I feel like they would be fairly complete and well maintained.

Please let me know if that's something you'd accept.

Accept numeric codes as numbers

For consistency, we store the numeric codes as string types. However, users should be able to pass in number types and get the same results.

Types not added in package.json exports

Package.json exports does not specify types, so declaration are not found when exports supported (moduleResolution: bundler in tsconfig)
It should be specified in package.json as:

  "type": "module",
  "source": "./src/country-coder.ts",
  "types": "./dist/country-coder.d.ts",
  "main": "./dist/country-coder.cjs",
  "module": "./dist/country-coder.mjs",
  "exports": {
+    "types": "./dist/country-coder.d.ts",
    "import": "./dist/country-coder.mjs",
    "require": "./dist/country-coder.cjs"
  },

Error

TS7016: Could not find a declaration file for module '@rapideditor/country-coder'. 'my-project/node_modules/@rapideditor/country-coder/dist/country-coder.mjs' implicitly has an 'any' type. Β Β There are types at 'my-project/node_modules/@rapideditor/country-coder/dist/country-coder.d.ts', but this result could not be resolved when respecting package.json "exports". The '@rapideditor/country-coder' library may need to update its package.json or typings.

Brexit

European Union membership for the UK seems to be disappearing soon...

Add United Nations feature

We already have the European Union. It'd be nice to add the United Nations too. Almost all territories comprise UN member states with some exceptions:

  • Cook Islands
  • Kosovo
  • Niue
  • State of Palestine
  • Taiwan
  • Vatican City
  • Western Sahara
  • others???

Fully ESM compatible ?

First of all thanks a lot for this awesome lib. I was using codegrid but it's not maintained anymore and yours offers so much more features.

I'm using it in a Vue + Vite project, iso1A2Code() works like a charm and returns the country code, but everytime i'm passing {level: 'territory'} i'm getting this error, same for iso1A2Codes(), features() and more.
image

I guess it's probably be some esm issues,
I changed the vite config to optimizeDeps: { exclude: [ '@ideditor/country-coder' ] }
but now i'm getting this: Uncaught SyntaxError: The requested module '/node_modules/which-polygon/index.js?v=3baa6ba3' does not provide an export named 'default'.
To me it seems to come from which-polygon, i took a look at the source code and they seem to use commonJS. I've read vite may have similar issues because of librairies not fully ESM compatibles.
You can close this issue it's probably me and my lack of knowledge, but if anyone has a solution to this let me know !

Thanks

Reduce package/bundle size - dynamically import borders.json

Motivation

Currently when taking dependency on country-coder npm package a bundle will get heavier by ~600kb.
The main reason is due to borders file which takes 595kb and is directly imported in source code.
e.g. running build analysis in iD would tell that iD bundle is 3MB while country-coder takes 600kb (~15%), however it seems that geojson is not the best candidate for web-standard compressions (e.g. br) which is why this piece takes ~35% of the compressed bundle.

Making such bundle overhead impacts fcp (especially with users that have low speed connection) which can be avoided in case when borders.json is not necessary for startup/fcp.

Proposal

Create lazy/dynamic load of the borders file inside the country-coder.
Potential implementation is to have init()/ensureLoaded() method to request+load the heavy file and return the promise which then gets resolved. Unfortunately, that would result in shell pattern (unpopulated object which enables default 'empty' functionalities which become functional after init is done), however in this case it would be worth it.

We might be using "exports" wrong

I'm getting this error downstream in Name-Suggestion-Index after upgrading location-conflation/country-coder:

Screen Shot 2021-06-12 at 10 35 50 AM

The line that triggers the error is:

const iso1A2Code = require('@ideditor/country-coder').iso1A2Code;

I did not expect that by adding "exports" to the package.json that a CJS/require environment would try to use it and pull in a modern ES6 module.

Anyway here is some stuff for me to read later: https://nodejs.org/api/packages.html#packages_package_entry_points

It might be best to avoid the exports field for now and just keep using the main, module, browser fields.
(This might even be fixed already since the switchover to esbuild - I dont know)

Check winding

Looking into this issue: osmlab/osm-community-index#334 (comment)

I'm using location-conflation to process the features with turf. In this case we're unioning all of the gb features together, but many of them get left out. For example, Isle of Man shows up as a hole:

Screenshot 2020-02-10 10 33 41

My guess is that both the GeoJSON spec and Turf are picky about polygon winding, and that some of the features in Country Coder are not wound consistently.

  • A linear ring MUST follow the right-hand rule with respect to the area it bounds, i.e., exterior rings are counterclockwise, and holes are clockwise.

We can probably just run everything through https://github.com/mapbox/geojson-rewind to make sure they are following the right hand rule.

Crimea

that's it that's the issue

FeedBack - Code

hi !

This package is awesome so, i forked it and wanted to put 0 dependencies.

I add typescript on this js package (2) [...].

well... I don't want make pull request because want to make some custom stuff with borders (babylon 5 map)

export interface GeoBorderProps {
    wikidata?: string;
    nameEn?: string;
    aliases?: string[];
    country?: string;
    groups?: string[];
    driveSide?: "right" | "left";
    roadSpeedUnit?: "mph" | "km/h";
    roadHeightUnit?: "ft" | "m";
    callingCodes?: string[];
    iso1A2?: string,
    iso1A3?: string
    level?: GeoLevel,
    m49?: string,
    iso1N3?: string,
    isoStatus?: "usrAssn" | "excRes" | "official",
    ccTLD?: string,

    emojiFlag?: string,
    members?: string[],
    maxLevel?: string | undefined;
    withProp?: string | undefined;
    id?: string,
}
export type GeoBorderKeys= keyof GeoBorderProps

  • This package dont exploit the power of typescript ... rather makes 7*2 functions, you can add a parameter ...
  • the names of function is confusing ... make it more clear (like "filter...", "search...", find....)
  • +surcharge data is a mistake ... In order to be efficient make id with geometry and extra info on a object which have id /props ... geometry is too heavy in my opinion ...
  • When user make search in object you dont have to retrieve the coord of multipolygon/polygon so the props is more usefull than feature ...

I hope it helps

Africa is a donut

Since Bir Tawil isn't part of any country, country-coder doesn't know that it's part of Africa. We should add a region just to fill in this hole.

Screen Shot 2020-07-17 at 1 01 40 PM

Don't use a class structure

The CountryCoder class doesn't actually manage any state except the index caches. Since these never change and could be shared by various callers of the package, it'd be better to move the caches to the module level and remove the need for a class at all.

Regrettably, this is a big breaking change.

United Kingdom

The UK boundary is showing as including the British Overseas Territories and Crown dependencies. I believe this should be excluded. The have their own ISO codes.

https://ideditor.github.io/location-conflation/?locationSet=%7B%20include%3A%20%5B%22GB%22%5D%7D

I think the region that it should show is:
https://ideditor.github.io/location-conflation/?locationSet=%7B%20include%3A%20%5B%22GB-ENG%22%2C%20%22GB-NIR%22%2C%20%22GB-SCT%22%2C%20%22GB-WLS%22%5D%7D

Details on the British Overseas Territories and Crown dependencies can be found here:
https://en.wikipedia.org/wiki/United_Kingdom#Dependencies

Kosovo is missing some attributes

kosovo
The Kosovo is missing both an iso1A3 and iso1N3 attribute which makes it impossible to find e.g. the iso1A2 attribute using the following code:

import { iso1A2Code } from '@ideditor/country-coder';  
iso1A2Code('XKX');

Northen Cyprus' ISO code

Currently, any request with coordinates pointing to Northen Cyprus, returns no country code.

Its entry in borders.json does indeed have no codes specified:

{
   "type":"Feature",
   "properties":{
      "wikidata":"Q23681",
      "nameEn":"Northern Cyprus",
      "groups":[
         "Q644636",
         "145",
         "142"
      ],
      "driveSide":"left",
      "callingCodes":[
         "90 392"
      ]
   },
    ...
},

However, even though the Turkish Republic of Northern Cypr is politically separated from Cyprus (Republic of Cyprus), it should share the same country code CY. Here's why:

  • There is no entry for TRNC in the ISO 3166-1
  • The entry of Cyprus contains a subitem for each of the 6 districts. 2 of these actually form TRNC:
    immagine

France: EU + Europe missing ?

I've started using country-coder in my OpenStreetMap Community Viewer.

I'm trying to "guess" the region/continent a country is from using country-coder groups.
It works pretty well ... except for France (and I guess other countries in a similar "situation") !

Groups for France are ["UN", "001"] (see https://ideditor.codes/?code=Q142).
There is definitely EU missing !
But I would also expect 150 (Europe) ; I guess this happens because France has territories outside Europe (same happens to Spain).

Thanks for this awesome library :)

More data

Let's brainstorm here on what other data we want to include for each country. Would be great to remove some of these datasets from iD.

  • Drive Left/Right
  • Units Imperial/Metric
  • Telephone Code
  • Address Format (maybe too hard)

Add basic English names

Names are convenient for debugging and for convenience. For instance it's easy to read and write isIn([23, 78.2], 'Asia') instead of looking up a region code.

ISO 3166 of countries with Sovereign states

Some countries, which have a ISO 3166-1 entry return the Sovereign state's country code.

Example:

"lng": -65.0481,
"lat": 32.177

is a location in Bermuda, which has a country code: https://www.iso.org/obp/ui/#iso:code:3166:BM . However, GB gets returned (I suppose because in its entry there is a "country":"GB" property).

List of countries that have this same problem:

  • AS
  • AI
  • AW
  • BM
  • BV
  • IO
  • VG
  • KY
  • CX
  • CC
  • PF
  • TF
  • GI
  • GL
  • MO
  • CW
  • SX
  • NC
  • PM
  • TK
  • WF
  • EH
  • BQ

ESM export broken in react-native 0.64.2 (non-expo)

react-native version: 0.64.2

import * as countryCoder from '@ideditor/country-coder'; // ES6 import all
import { iso1A2Code } from '@ideditor/country-coder';

Neither works, it will just show as undefined function.

[TypeError: undefined is not a function]

Other exports don't work as well, I suspect something to do with your exports configuration?
import { feature, iso1A2Code, emojiFlag } from '@ideditor/country-coder';

I reverted back my upgrade, the latest version of ideditor/country-coder that works in a react-native (non-expo) environment is v4.1.0

Support bbox query?

which-polygon has a bbox query, which would be amazing if you could support. The use case is: I'm looking at a map and I want to find out all countries that are on the screen given a min/max lat,lng pairs.

Happy to attempt to add this myself, I just thought I'd make the suggestion as it will probably takes the maintainers much less time to implement.

File extension pattern matching in React Native 0.62.4 for mjs cjs main and module files

@bhousel Thank you very much for the help. Just one small thing left before package is fully ready for RN again.

Yes browser export was causing issues, and I get the actual root issue now aside from browser export.

It's the file extension pattern matching.

This is v4.1.0 package.json, it conforms to pattern

"main": "./dist/country-coder.js",
"module": "./dist/country-coder.module.js",

it conforms to this pattern that React-Native wants, notice the .js extension (.native|.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.svg|.native.svg|.svg), without this Xcode will not build.

However in v5.0.3, it becomes

"main": "./dist/country-coder.cjs",
"module": "./dist/country-coder.mjs",

If I just added a .js to both of these files (RN uses module but both pattern matching was needed)

"main": "./dist/country-coder.cjs.js",
"module": "./dist/country-coder.mjs.js",

This works perfectly. All features are now back online. It's silly, but the pattern matching is strict.

Accept lowercase codes

The coder currently expects all codes to be uppercase (e.g. CN). We should accept lowercase or mixed-case codes too (e.g. cn, Cn).

TW polygon missing Lienchiang County and parts of Kinmen County (Wuqiu)

Of the "TPKM" areas the TW polygon currently includes Taiwan, Penghu and the main island of Kinmen County, but there are a few islands missing. In keeping with the objectives of this library the motivation here is to power consistent locale information for mapping, so this doesn't include some unpopulated islands; the civilian population is 10,000+ of these in total and there is significant detail in OSM:

Wuqiu relation on OSM
Lienchiang (Matsu) relation on OSM

Screenshot of proposed polygon change with OSM Carto as a reference, using a minimal number of vertices:

Screenshot 2023-07-11 at 15 53 16

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.