Countries is basically a data package (with some helpers) for easy access to country, locale, language, currency and time zone data.
yarn add @doubco/countries
⚠️ GraphQL versions' has matching objectkey
and list_id
with type definations.
{
...,
"TR": {
"name": "Turkey",
"flag": "🇹🇷",
"code": "+90",
"currency": "TRY",
"capital": "Ankara",
"languages": ["tr"],
"nativeName": "Türkiye"
},
...
}
[
...
{
"_id": "TR",
"label": "Turkey (Türkiye)"
},
...
]
import { countries, countryList } from "@doubco/countries";
// or
import countries from "@doubco/countries";
// default
// countries.data
// countries.list
// graphql alt.
// countries.graphql.data
// countries.graphql.list
{
...,
"en_GB": "English - Great Britain",
...
}
[
...
{
"_id": "en_GB",
"label": "English - Great Britain"
},
...
]
import { locales, localeList } from "@doubco/countries/locales";
// or
import locales from "@doubco/countries/locales";
// default
// locales.data
// locales.list
// graphql alt.
// locales.graphql.data
// locales.graphql.list
{
...,
"tr": {
"name": "Turkish",
"nativeName": "Türkçe"
},
...
}
[
...
{
"_id": "tr",
"label": "Turkish (Türkçe)"
},
...
]
import { languages, languageList } from "@doubco/countries/languages";
// or
import languages from "@doubco/countries/languages";
// default
// languages.data
// languages.list
// graphql alt.
// languages.graphql.data
// languages.graphql.list
{
...,
"TRY": {
"symbol": "TRY",
"nativeSymbol": "\u20BA",
"decimalDigits": 2,
"name": "Turkish Lira",
"nativeName": "Türk Lirası",
"namePlural": "Turkish Lira"
},
...
}
⚠️ nativeName is only available on some currencies.
[
...
{
"_id": "TRY",
"label": "Turkish Lira (₺)",
},
...
]
[
...
{
"_id": "TRY",
"label": "TRY",
},
...
]
import {
currencies,
currencyList,
currencyListSimple,
currenciesLite,
currencyListLite,
currencyListLiteSimple,
} from "@doubco/countries/currencies";
import currencies from "@doubco/countries/currencies";
// default
// currencies.data;
// currencies.list;
// currencies.simpleList;
// lite
// currencies.lite.data;
// currencies.lite.list;
// currencies.lite.simpleList;
// graphql alt.
// currencies.graphql.data;
// currencies.graphql.list;
// currencies.graphql.simpleList;
// currencies.graphql.lite.data;
// currencies.graphql.lite.list;
// currencies.graphql.lite.simpleList;
Simple list versions' uses
key
aslabel
.
Lite versions' includes only currencies supported by most currency convertion APIs.
{
...,
"TRY": {
"symbol": "TRY",
"nativeSymbol": "\u20BA",
"decimalDigits": 2,
"name": "Turkish Lira",
"nativeName": "Türk Lirası",
"namePlural": "Turkish Lira"
},
...
}
[
...
{
"_id": "TRY",
"label": "Turkish Lira (₺)",
},
...
]
import { timezones, timezoneList } from "@doubco/countries/timezones";
// or
import timezones from "@doubco/countries/timezones";
// default
// timezones.data
// timezones.list
// lite
// timezones.lite.data
// timezones.lite.list
// graphql alt.
// timezones.graphql.data
// timezones.graphql.list
// timezones.graphql.lite.data
// timezones.graphql.lite.list
Lite versions only includes one time zone once.
This library also exposes GraphQL resolvers and type definations.
import { countries, locales } from "@doubco/countries/graphql";
export default {
typeDefs: [
countries.typeDefs, // this is it.
locales.typeDefs, // this is it.
User.typeDefs,
Log.typeDefs,
...
],
resolvers: merge(
countries.resolvers, // this is it.
locales.resolvers, // this is it.
Auth.resolvers,
User.resolvers,
...
),
};
const { countries, locales } = require("@doubco/countries/graphql");
module.exports = {
typeDefs: [
countries.typeDefs, // this is it.
locales.typeDefs, // this is it.
Auth.typeDefs,
User.typeDefs,
Log.typeDefs,
...
],
resolvers: merge(
countries.resolvers, // this is it.
locales.resolvers, // this is it.
Auth.resolvers,
User.resolvers,
...
),
};
This usage is for Apollo Server, you can use similar approach on other frameworks.
Pull requests are welcome and please submit bugs 🐛.
- Follow @doubco on Twitter
- Follow @doubco on Instagram
- Email mailto:[email protected]
Region data is from https://github.com/country-regions/country-region-data