ember-countries

2.0.2 • Public • Published

Ember-countries

npm version Ember Observer Score

A simple Addon that contains the 6 following lists:

  • all the countries in ISO2 (US), ISO3 (USA), ISO-Numeric (840) and English name (United States) formats.
  • the countries without ZIP Code.
  • the countries with states.
  • the US states & military states
  • the US states that require customs declaration
  • the Canadian states

Here are a list of the main helpers:

  • Country ISO2, ISO3 or ISO-Numeric to Country object.
  • Is country with state.
  • Is country without ZIP Code.
  • State ISO2 to State object

You can find more information about ISO codes here:

Installation

  • ember install ember-countries

Upgrading from 1.x.x to 2.0.0

Here are all the information that you need to migrate from version 1.x.x to 2.0.0: Migrating from 1.x.x to 2.0.0

Usage

All imports

import { COUNTRIES_LIST, COUNTRIES_WITHOUT_ZIP_LIST, COUNTRIES_WITH_STATES_LIST } from 'ember-countries';
import { US_STATES_LIST, US_MILITARY_STATES_LIST, US_REQUIRING_CUSTOM_DECLARATION_STATES_LIST, CA_STATES_LIST, STATES_BY_COUNTRIES } from 'ember-countries';
import { getCountry, isCountryWithState, isCountryWithoutZip } from 'ember-countries';
import { getStatesForCountry, isCustomsDeclarationRequiredInUS, countryContainsState, getState } from 'ember-countries';
import defaultEmberCountries from 'ember-countries';

Example 1: countries lists

import Em from 'ember';
import { COUNTRIES_LIST } from 'ember-countries';
 
export default Em.Controller.extend({
 
  COUNTRIES_LIST: COUNTRIES_LIST,
  ...
});

Example 2: countries properties

import Em from 'ember';
import { getCountry, isCountryWithState, isCountryWithoutZip } from 'ember-countries';
 
export default Em.Controller.extend({
 
  countryHelper() {
    let expect   = {name: "United States", iso2: "US", iso3: "USA", isoNumeric: "840"}
    let country1 = getCountry('US');
    let country2 = getCountry('USA');
    let country3 = getCountry('840');
    
    country1 === expect  // true
    country2 === expect  // true
    country3 === expect  // true
    
    isCountryWithState('US')  // true
    isCountryWithoutZip('US')  // false
  },
  ...
});

Example 3: states lists

import Em from 'ember';
import emberCountries from 'ember-countries';
 
export default Em.Controller.extend({
 
  US_STATES: emberCountries.US_STATES_LIST,
  ...
});

Example 4: states properties

import Em from 'ember';
import { getState, countryContainsState } from 'ember-countries';
 
export default Em.Controller.extend({
 
  countryHelper() {
    let expect = {name: "California", iso2: "CA"}
    let state1 = getState('US', 'CA');
    let state2 = getState('USA', 'CA');
    let state3 = getState('840', 'CA');
    
    state1 === expect  // true
    state2 === expect  // true
    state3 === expect  // true
    
    countryContainsState('US', 'CA')  // true
  },
  ...
});

Running Tests

  • npm test (Runs ember try:each to test your addon against multiple Ember versions)
  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit http://ember-cli.com/.

Contributing

PRs welcome!

Package Sidebar

Install

npm i ember-countries

Weekly Downloads

75

Version

2.0.2

License

MIT

Last publish

Collaborators

  • mnowik