Git Product home page Git Product logo

iso3166-1's Introduction

iso3166-1 Build Status

Version License Downloads Deps DevDeps

The smallest, fastest, node module for ISO 3166-1 alpha 2/3 helper lookup/parser. Browserify/Webpack friendly.

Install

npm install --save iso3166-1

Usage

var iso31661 = require('iso3166-1')
iso31661.from('USA').to3()         // USA
iso31661.from('USA').to2()         // US
iso31661.from('US').to3()          // USA
iso31661.from('US').to2()          // US
iso31661.fromLocale('en-US').to3() // USA
iso31661.fromLocale('en-US').to2() // US
var iso31661 = require('iso3166-1')
iso31661.to2('USA') // US
iso31661.to3('US')  // USA
var iso31661 = require('iso3166-1')
var locale2 = require('locale2')
iso31661.fromLocale(locale2).to3() // USA
iso31661.fromLocale(locale2).to2() // US
import iso31661 from 'iso3166-1';
iso31661.is2('US')  // true
iso31661.is3('USA') // true
iso31661.is2('XX')  // false
iso31661.is3('XXX') // false

License

MIT

iso3166-1's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar greenkeeperio-bot avatar moimikey avatar msimerson avatar trescube avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

iso3166-1's Issues

Cannot read property 'alpha2' of undefined

Trying the basic example in my app, it works fine with to3() but fails with to2().

Cannot read property 'alpha2' of undefined

TypeError: Cannot read property 'alpha2' of undefined
    at Object.b [as to2] (/Users/vadorequest/dev/loan-advisor/node_modules/iso3166-1/dist/iso3166-1.js:3:11181)
    at Object../hoc/withData.js (/Users/vadorequest/dev/loan-advisor/hoc/withData.js:16:5)
    at __webpack_require__ (/Users/vadorequest/dev/loan-advisor/.next/dist/bundles/pages/webpack/bootstrap b368674930c3372dd65a:21:1)
    at Object../pages/school/index.js (/Users/vadorequest/dev/loan-advisor/pages/school/index.js:18:1)
    at __webpack_require__ (/Users/vadorequest/dev/loan-advisor/.next/dist/bundles/pages/webpack/bootstrap b368674930c3372dd65a:21:1)
    at Object.2 (/Users/vadorequest/dev/loan-advisor/.next/dist/bundles/pages/school.js:3556:18)
    at __webpack_require__ (/Users/vadorequest/dev/loan-advisor/.next/dist/bundles/pages/webpack/bootstrap b368674930c3372dd65a:21:1)
    at module.exports../components/Bloc.js.Object.defineProperty.value (/Users/vadorequest/dev/loan-advisor/.next/dist/bundles/pages/webpack/bootstrap b368674930c3372dd65a:68:1)
    at Object.<anonymous> (/Users/vadorequest/dev/loan-advisor/.next/dist/bundles/pages/school.js:73:10)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)

With the following source code:

import locale2 from 'locale2';
import iso3166 from 'iso3166-1';

console.log(locale2)
console.log(iso3166.fromLocale(locale2))
console.log(iso3166.fromLocale(locale2).to2())

Here is what I get with to3()
image

Tested on both Chrome latest and Firefox, same result

fix broken `minified` builds

noticed uglifyjs verbose output:

util.error: Use console.error instead
WARN: Dropping unused function argument exports [-:1629,33]
util.error: Use console.error instead
WARN: Dropping unused function argument index [-:1785,53]
util.error: Use console.error instead
WARN: Dropping unused function argument name [-:1973,28]
util.error: Use console.error instead
WARN: Dropping unused function argument dir [-:1979,26]
...

https://github.com/moimikey/iso3166-1/blob/master/build/iso3166-1.global.min.js
https://github.com/moimikey/iso3166-1/blob/master/build/iso3166-1.min.js

ability to chain methods

There's a potential use case for converting .to2() or .to3() and chained with .is2() and .is3() respectively. not an imperative addition, but has potential as an enhancement.

TODO

goals

  1. this project is meant to be an isolated node module that is only meant to do one thing and do it well: parse ISO 3166-1 alpha 2 (US) or alpha 3 (USA) country codes.
  2. in order to allow Browserify and/or Webpack, or any client side module loader for that matter, there will be no filesystem calls to necessitate virtual fs or transforms.
  3. it's meant to have a very tiny footprint, thus, only one small goal. country code data can get quite big, the data sets will be compressed rather than raw.
  4. the module should be able to easily integrate with something, for example, that detects the end-users locale (API is subject to change):
var locale = require('locale2');
var iso31661 = require('iso3166-1');
var alpha2 = iso31661.lookup(locale).alpha3;
var alpha3 = iso31661.lookup(locale).alpha2;
  1. a lot of country code libraries do some things well and some things bad. i've encountered outdated or incomplete databases. It generally becomes the project owners discretion to update it. this module will be accompanied by a global binary that will fetch and cache to ensure that the databases are always up to date and complete. in the event something is outdated or incomplete, tests will fail and the binary will issue a warning. this will allow for immediate information as to whether or not the module will be adequate at that period in time and can be addressed in a timely fashion.

progress

  • [ ]

Missing package dependency 'zlib-browserify'

> var iso3166 = require('iso3166-1')
Error: Cannot find module 'zlib-browserify'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Users/james/Code/BlueMix/stack-overflow/node_modules/iso3166-1/src/index.js:2:14)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)

Build version differs from sources.

Hey,

First of all, thanks for your great library. I've seen that the browserified build (iso3166-1.global.js) differs from the version in src/.

The file »src/iso3166-1/index.j2« includes the following function, which i miss inside the build.

var is3 = function is3(alpha3) {
    return ISOCodes.some(function(row) {
      return row.alpha3 === alpha3
    })
  }

Is it possible to rebuild the project and commit the build files?
That would be great!

I could also create a PR for that!?

Thanks!
René

buffer breaks in IE11

@moimikey

Hola! I'm not sure if this is something that can be fixed in this module, but IE11 seems to have some some issues with fromString method of `buffer. Trying to look for a fix and I'll open a PR if I find one but maybe you have some ideas as well?

screen shot 2016-04-18 at 3 56 41 pm

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.