@ferranblanche/standards

1.0.0 • Public • Published

Standards

This library provides ISO codes for:

Installation

It can be installed in whichever way you prefer, but I recommend NPM:

npm install @ferranblanche/standards

Countries

Import de Countries module:

import { Countries } from "@ferranblanche/standards";
const countries = new Countries();

Validate Country code

Validate a String is a valid ISO 3166-1 code:

countries.contains("us");
// true

countries.contains("es");
// true

countries.contains("Japan");
// false

countries.contains("xx");
// false

Get Country by code

Get a Country by a valid ISO 3166-1 code:

countries.get("es");
/*
{
  "name": "Spain",
  "local": "España",
  "code": "es",
  "region": "Europe",
  "currency": "eur",
  "language": "es",
  "flag": "🇪🇸"
}
*/

countries.get("us");
/*
{
  "name": "United States of America",
  "local": "United States of America",
  "code": "us",
  "region": "North America",
  "currency": "usd",
  "language": "en",
  "flag": "🇺🇸"
}
*/

countries.get("xx");
// undefined

countries.get("Spain");
// undefined

Access the Country information:

let name = countries.get("nl").name;
// "Netherlands"

or

const poland = countries.get("pl");
let localName = poland.local;
// "Polska"

Search Country by text

Search Country by text:

countries.search("de");
/*
{
  "name": "Germany",
  "local": "Deutschland",
  "code": "de",
  "region": "Europe",
  "currency": "eur",
  "language": "de",
  "flag": "🇩🇪"
}
*/

countries.search("Espa");
/*
{
  "name": "Spain",
  "local": "España",
  "code": "es",
  "region": "Europe",
  "currency": "eur",
  "language": "es",
  "flag": "🇪🇸"
}
*/

countries.search("中");
/*
{
  "name": "China",
  "local": "中国",
  "code": "cn",
  "region": "Asia & Pacific",
  "currency": "cny",
  "language": "zh-hans",
  "flag": "🇨🇳"
}
*/

countries.search("S語");
// undefined

Currencies

Import de Currencies module:

import { Currencies } from "@ferranblanche/standards";
const currencies = new Currencies();

Validate Currency code

Validate a String is a valid ISO 4217 code:

currencies.contains("usd");
// true

currencies.contains("eur");
// true

currencies.contains("US Dollar");
// false

currencies.contains("xxx");
// false

Get Currency by code

Get a Currency by a valid ISO 4217 code:

currencies.get("eur");
/*
{
  "code": "eur",
  "name": "Euro",
  "decimals": 2,
  "symbol": "€"
}
*/

currencies.get("usd");
/*
{
  "code": "usd",
  "name": "US Dollar",
  "decimals": 2,
  "symbol": "$"
}
*/

currencies.get("xxx");
// undefined

currencies.get("Euro");
// undefined

Access the Currency information:

let name = currencies.get("eur").name;
// "Euro"

or

const euro = currencies.get("eur");
let symbol = euro.local;
// "€"

Search Currency by text

Search Currency by text:

currencies.search("Dirham");
/*
{ 
  "code": "mad", 
  "name": 
  "Moroccan Dirham", 
  "decimals": 2, 
  "symbol": "" 
}
*/

currencies.search("¥");
/*
{ 
  "code": "cny", 
  "name": "Yuan Renminbi", 
  "decimals": 2, 
  "symbol": "¥" 
}
*/

currencies.search("hello¥€");
// undefined

Languages

Import de Languages module:

import { Languages } from "@ferranblanche/standards";
const languages = new Languages();

Validate Language code

Validate a String is a valid ISO 639-1 code:

languages.contains("en");
// true

languages.contains("es");
// true

languages.contains("spanish");
// false

languages.contains("xx");
// false

Get Language by code

Get a Language by a valid ISO 639-1 code:

languages.get("es");
// { code: "es", name: "Spanish", local: "Español" }

languages.get("en");
// { code: "en", name: "English", local: "English" }

languages.get("xx");
// undefined

languages.get("Spanish");
// undefined

Access the Language information:

let name = languages.get("en").name;
// "English"

or

const spanish = languages.get("es");
let localName = spanish.local;
// "Español"

Search Language by text

Search Language by text:

languages.search("nl");
// { code: "nl", name: "Dutch", local: "Nederlands" }

languages.search("Span");
// { code: "es", name: "Spanish", local: "Español" }

languages.search("語");
// { "code": "ja", "name": "Japanese", "local": "日本語" }

languages.search("Span本語");
// undefined

Package Sidebar

Install

npm i @ferranblanche/standards

Weekly Downloads

9

Version

1.0.0

License

MIT

Unpacked Size

191 kB

Total Files

33

Last publish

Collaborators

  • ferranblanche