npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ferranblanche/standards

v1.0.0

Published

Library to consult and validate standard codes for languages and countries

Downloads

68

Readme

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