value-lookup
The "value-lookup" utility is a compilation of ISO lookups in order to make it easy to lookup countries, currencies, languages and much more based on character codes.
Built-in support for:
- ISO_639-1
- ISO_3166-1_A2
- ISO_3166-1_A3
- ISO_4127
- UN_M.49
- DMA
- IAB
Getting Started
Install value-lookup
using npm
Installation:
$ npm install value-lookup
--
Basic usage in Javascript:
Server-side (local):
var valueLookup = ;var builtInLookups = valueLookupgenerator;var lookupObj = ;console;// -> "Afghanistan"
Server-side (specify lookup location):
var valueLookup = ;var lookupsFromLocation = valueLookupgenerator;var lookupObj = 'ISO_3166_1_A2';console;// -> "Afghanistan"
Client-side:
var valueLookup = ;var localToWebsite = valueLookupgeneratorvar lookupObj = 'ISO_3166_1_A2';console;// -> "Afghanistan"
If you choose to use a lookup
which doesn't exist in the built-in
lookups, just pass in 'custom'
as the lookup
and either supply
the JSON and use the generator.custom(JSON
), or write your own.
Pass in your own function for retrieving a file:
var valueLookup = ;var customFunc = { return { $; };};var remoteJson = lookupObj = 'custom';console;// -> "Afghanistan"
Pass in raw JSON for the lookup:
var valueLookup = ;var customJson = valueLookupgenerator;var lookupObj = 'custom';console;// -> "Afghanistan"
The keys of any lookup object can be retrieved by calling keys()
.
- Using
lookupObj
from the previous example:
console;// -> ["AF", "AX", "AL", "DZ"]