GithubHelp home page GithubHelp logo

boukeversteegh / iso-3166-country-codes-angular Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rsertelon/iso-3166-country-codes-angular

0.0 2.0 0.0 526 KB

Javascript lib for ISO 3166 Country codes

License: The Unlicense

iso-3166-country-codes-angular's Introduction

ISO 3166 for Angular JS

This project is an ISO 3166 (Country codes) module for AngularJS. It provides:

  • A service (factory) that gives access to all country codes
  • A filter to print country codes as their standard name (FR -> FRANCE)
  • A validation directive to validate country codes

Get it

This library is available with the bower package manager, you can either:

  • Execute the following command: bower install iso-3166-country-codes-angular --save
  • Add this line in your dependencies: "iso-3166-country-codes-angular": "1.0.2"

Features

Factory

You can have access to country codes information and two utilitary methods.

// Declare the factory as dependency
angular.module('myApp')
  .controller('MyCtrl', function (ISO3166) {
    // Test if a value is a country code
    console.log(ISO3166.isCountryCode('FR')); // true
    console.log(ISO3166.isCountryCode('FRA')); // false

    // Get country name
    console.log(ISO3166.getCountryName('FR'));
    // FRANCE

    // Get several country names at once (ignores invalid codes)
    console.log(ISO3166.getCountryNames(['DE', 'FR', 'invalid']);
    // {
    //   'DE': 'GERMANY',
    //   'FR': 'FRANCE'
    // }

    // Direct access to the data
    console.log(ISO3166.codeToCountry);
    // {
    //   'FR': 'FRANCE',
    //   ...
    // }

  });

Filter

If you get country codes from your REST server, you can print its standard name with the provided filter:

<!-- if countryCode is 'FR', will print 'FRANCE' -->
<p>{{countryCode | isoCountry }}</p>

Validation directive

If you want users to enter country codes, you can validate it like so (it fits in Angular validation process):

<form name="form" novalidate>
  <input type="text" name="countryField" country-code />
  <span ng-show="form.countryField.$error.countrycode">This must be a country code!</span>
</form>

Issues, Feature request

You can use Github's issues to submit feature requests and bug reports.

Contributions

This project gladly accepts contributions. However, you must agree to give your work explicitely to public domain. To do so, just put this statement in the pull request definition:

I dedicate any and all copyright interest in this software to the
public domain. I make this dedication for the benefit of the public at
large and to the detriment of my heirs and successors. I intend this
dedication to be an overt act of relinquishment in perpetuity of all
present and future rights to this software under copyright law.

License

This software is given to the public domain. For more information, see the UNLICENSE file.

iso-3166-country-codes-angular's People

Contributors

rsertelon avatar

Watchers

James Cloos avatar  avatar

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.