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

rural

v0.2.5

Published

A simple helper module / funtions set for normalizing and returning ISO standard details for country information. and referencing country data in a combined format directly in your app, with out the need for external requests and latency.

Downloads

23

Readme

rural

Build Status codecov Known Vulnerabilities

A country look up module for js apps neededing to normalize or use a standard base to get, ISO codes, currency info, capitals and more to follow.

Why use a module over a lookup service? As these are effectively JSON data sets, the return is fast and with out network latency of look up services external to the project.

Notes on Requirements

The previous dependency of lodash has been removed as of V 0.1.11

Roadmaps

V 0.1+ : Available

Includes a full set of data combined from multiple sources and it useable at present.

Fast Start

Install via NPM npm install rural --save

import the module, for example: import Rural from 'rural'

To use it: Rural('us') or Rural('usa') or Rural('US') => Returns a full object of the countries details.

	{
		"ISO2": "US",
		"ISO3": "USA",
		"name": "United States of America",
		"captialCity": "Washington",
		"dialingCode": "1",
		"currency": "USD",
		"currencyPosition": "pre",
		"currencyMeta": true,
		"currencySymbol": "$",
		"currencyName": "US Dollar",
		"currencyNamePlural": "US dollars",
		"currecnyDecimalDigits": 2,
		"currencyRounding": 0
	}

Note : This may be overkill

Often you need something simpler, the additional functions may suit you needs better!

import Rural, {ruralIso, ruralName} from 'rural' or just what you need import {ruralName} from 'rural'

Api

Default Usage

Rural('CODE', OPTIONS, DEBUG)

CODE : STRING : SUGGESTED

Refers to an ISO2 or ISO3 country code 'US' or 'USA' respectively.

If this is left null: Rural() will return the entire rural data set.

OPTIONS : OBJECT : OPTIONAL

Options is placed in for further extesnion.

DEBUG : BOOLEAN : OPTIONAL

Passing a bool true will log the returned data should you require this.

RETURNS : OBJECT

returns an object of country data.

	{
		"ISO2": "US",
		"ISO3": "USA",
		"name": "United States of America",
		"captialCity": "Washington",
		"dialingCode": "1",
		"currency": "USD",
		"currencyPosition": "pre",
		"currencyMeta": true,
		"currencySymbol": "$",
		"currencyName": "US Dollar",
		"currencyNamePlural": "US dollars",
		"currecnyDecimalDigits": 2,
		"currencyRounding": 0
	}

ALL DATA

Sometimes you may like to do the return once and iterate how you want from the full set. Rural() => calling the default function with no params will return the complete data object. This can be useful to remove overhead to only your app code, for instance having all countries available to pivot data as you see fit.

Example Usage : JSX

Using lodash map function in a JSX to return all the countries info:

	<ul>
		{map(Rural('USa'), (item,key)=>{
			return <li>{key} : {item} </li>
		})}
	</ul>

Note the sanetization for sentence case or other nasties, in data inconsistencies.

Individual Example : JSX

Using what you need specifically.

	<h1>{Rural('us').name}</h1>

In this use case the ruralName submodule would be a better use case ( need to be imported), but uses a smaller more succint data set so is more performant.

	<h1>{ruralName('us')}</h1>

Additional Functions & Helpers

These will run faster with ISO2 country codes as no loop and iterate will be needed, which is faster accross the board. These use optimized for purpose datasets so when paired with an ISO2 code will give the best performance.

ruralIso

Function returns the alternate ISO country code to what you pass it. Useful if your data set is in one either of the Alpha formats and you want to switch it to the other one.

Example:

ruralIso('US') => Returns USA

Vice Versa

ruralIso('USA') => Returns US

Note this will catch case and miss matches in case, 'US' = 'us' = 'Us' = 'uS'

ruralName

Function returns the country name from an ISO Aplha 2 or 3 code. Useful if you just want to work with ISO codes and return a full company name.

ruralName('us') or ruralName('usa') => Returns United States of America

Note this will catch case and miss matches in case, 'US' = 'us' = 'Us' = 'uS'

ruralCurrency

Takes in a currency code such as CAD or GBP or USD and returns an object of relevant currency information:

the function: ruralCurrency('gbp') will fix the code eg gbp === GBP === GbP all are taken to uppercase

will return :

{ currency: 'GBP',
  currencyPosition: 'pre',
  currencyMeta: true,
  currencySymbol: '£',
  currencyName: 'British Pound Sterling',
  currencyNamePlural: 'British pounds sterling',
  currecnyDecimalDigits: 2,
  currencyRounding: 0 }
	```
Especially useful for eccomerce builds, if any information is incorrect please raise an issue or PR a fix into the base data set on github. 

## Testing

Initial testing has been added, these can be run with `npm run test`