Country
Status
Table of Content
Purpose
Country class definition
Installation
Via npm
npm install @scuba-squad/country
API
Country.getByIso2Code(code: string): Country | false
Added in: v1.0.0
Static method to retrieve and build a Country object from the iso2Code
arguments:
code: string
returns: Country | false
const Country = require('@scuba-squad/country');
let country = Country.getByIso2Code('US');
let nonExistant = Country.getByIso2Code('AA');
Country.getByIso3Code(code: string): Country | false
Added in: v1.0.0
Static method to retrieve and build a Country object from the iso3Code
arguments:
code: string
returns: Country | false
const Country = require('@scuba-squad/country');
let country = Country.getByIso3Code('USA');
let nonExistant = Country.getByIso3Code('AAA');
Country.getByIsoNumericCode(code: string): Country | false
Added in: v1.0.0
Static method to retrieve and build a Country object from the isoNumericCode
arguments:
code: string
returns: Country | false
const Country = require('@scuba-squad/country');
let country = Country.getByIsoNumericCode('840');
let nonExistant = Country.getByIsoNumericCode('000');
Country.getByPostalCode(code: ?string): Country[] | false
Added in: v1.0.0
Static method to retrieve and build an array of Country objects who match the given postal code
arguments:
code: string
returns: Country[] | false
const Country = require('@scuba-squad/country');
let country = Country.getByPostalCode('11111');
let nonExistant = Country.getByPostalCode('this is going to return false');
Country.getByCallingCode(code: ?string): Country[] | false
Added in: v1.0.0
Static method to retrieve and build an array of Country objects who match the given calling code
arguments:
code: string
returns: Country[] | false
const Country = require('@scuba-squad/country');
let country = Country.getByCallingCode('1');
let nonExistant = Country.getByCallingCode('99999999999999');
Country(properties: {name: ?string, iso2Code: ?string, iso3Code: ?string, isoNumericCode: ?string postalCodeRegEx: ?regexp, callingCode: ?string | string[]} = {}): Country
Added in: v1.0.0
Country class constructor
arguments:
properties: object = {}
name: string | null | undefined
iso2Code: string | null | undefined
iso3Code: string | null | undefined
isoNumericCode: string | null | undefined
postalCodeRegEx: regexp | null | undefined
callingCode: string | string[] | null | undefined
returns: Country
throws: TypeError
const Country = require('@scuba-squad/country');
let country = new Country();
alternatively
- you can create an instance without the new keyword
const Country = require('@scuba-squad/country');
let country = Country();
Country.VERSION: string
Added in: v1.0.0
Semantic version number of class definition
returns: string
const Country = require('@scuba-squad/country');
let country = new Country();
country.VERSION;
Country.name: string | undefined
Added in: v1.0.0
Property containing the name of the country
returns: string | undefined
throws: TypeError
const Country = require('@scuba-squad/country');
let country = new Country();
country.name = 'Petoria';
country.name;
Country.getName(): string | undefined
Added in: v1.0.0
Getter method for name property
returns: string | undefined
const Country = require('@scuba-squad/country');
let country = new Country();
country.name = 'Petoria';
country.getName();
Country.setName(name: ?string): Country
Added in: v1.0.0
Setter method for name property
arguments:
name: string | undefined | null
returns: Country
throws: TypeError
const Country = require('@scuba-squad/country');
let country = new Country();
country.setName('Petoria');
country.name;
Country.iso2Code: string | undefined
Added in: v1.0.0
Property containing the ISO 3166-1 alpha-2 code of the country
returns: string | undefined
throws: TypeError
const Country = require('@scuba-squad/country');
let country = new Country();
country.iso2Code = 'FG';
country.iso2Code;
Country.getIso2Code(): string | undefined
Added in: v1.0.0
Getter method for iso2Code property
returns: string | undefined
const Country = require('@scuba-squad/country');
let country = new Country();
country.iso2Code = 'FG';
country.getIso2Code();
Country.setIso2Code(code: ?string): Country
Added in: v1.0.
Setter method for iso2Code property
arguments:
code: string | undefined | null
returns: Country
throws: TypeError
const Country = require('@scuba-squad/country');
let country = new Country();
country.setIso2Code('FG');
country.iso2Code;
Country.iso3Code: string | undefined
Added in: v1.0.0
Property containing the ISO 3166-1 alpha-3 code of the country
returns: string | undefined
throws: TypeError
const Country = require('@scuba-squad/country');
let country = new Country();
country.iso3Code = 'GUY';
country.iso3Code;
Country.getIso3Code(): string | undefined
Added in: v1.0.0
Getter method for iso3Code property
returns: string | undefined
const Country = require('@scuba-squad/country');
let country = new Country();
country.iso3Code = 'GUY';
country.getIso3Code();
Country.setIso3Code(code: ?string): Country
Added in: v1.0.0
Setter method for iso3Code property
arguments:
code: string | undefined | null
returns: Country
throws: TypeError
const Country = require('@scuba-squad/country');
let country = new Country();
country.setIso3Code('GUY');
country.iso3Code;
Country.isoNumericCode: string | undefined
Added in: v1.0.0
Property containing the ISO 3166-1 numeric code of the country
returns: string | undefined
throws: TypeError
const Country = require('@scuba-squad/country');
let country = new Country();
country.isoNumericCode = '999';
country.isoNumericCode;
Country.getIsoNumericCode(): string | undefined
Added in: v1.0.0
Getter method for isoNumericCode property
returns: string | undefined
const Country = require('@scuba-squad/country');
let country = new Country();
country.isoNumericCode = '999';
country.getIsoNumericCode();
Country.setIsoNumericCode(code: ?string): Country
Added in: v1.0.0
Setter method for isoNumericCode property
arguments:
code: string | undefined | null
returns: Country
throws: TypeError
const Country = require('@scuba-squad/country');
let country = new Country();
country.setIsoNumericCode('999');
country.isoNumericCode;
Country.postalCodeRegEx: regexp | undefined | null
Added in: v1.0.0
Property containing the postal code validation regular expression for the country
returns: regexp | undefined | null
throws: TypeError
const Country = require('@scuba-squad/country');
let country = new Country();
country.postalCodeRegEx = /^\d{5}$/;
country.postalCodeRegEx;
Country.getPostalCodeRegEx(): regexp | undefined | null
Added in: v1.0.0
Getter method for postalCodeRegEx property
returns: regexp | undefined | null
const Country = require('@scuba-squad/country');
let country = new Country();
country.postalCodeRegEx = /^\d{5}$/;
country.getPostalCodeRegEx();
Country.setPostalCodeRegEx(regex: ?regexp): Country
Added in: v1.0.0
Setter method for postalCodeRegEx property
arguments:
code: regexp | undefined | null
returns: Country
throws: TypeError
const Country = require('@scuba-squad/country');
let country = new Country();
country.setPostalCodeRegEx(/^\d{5}$/);
country.postalCodeRegEx;
Country.callingCode: string | string[] | undefined | null
Added in: v1.0.0
Property containing the calling code of the country
returns: string | string[] | undefined | null
throws: TypeError
const Country = require('@scuba-squad/country');
let country = new Country();
country.callingCode;
country.callingCode = [1, 5];
country.callingCode;
country.callingCode = null;
country.callingCode;
Country.getCallingCode(): string[] | undefined | null
Added in: v1.0.0
Getter method for callingCode property
returns: string[] | undefined | null
const Country = require('@scuba-squad/country');
let country = new Country();
country.getCallingCode();
country.callingCode = [1, 5];
country.getCallingCode();
country.callingCode = null;
country.getCallingCode();
Country.setCallingCode(code: ?...string | string[]): Country
Added in: v1.0.0
Setter method for callingCode property
arguments:
code: ...string | string[] | undefined | null
returns: Country
throws: TypeError
const Country = require('@scuba-squad/country');
let country = new Country();
country
.setCallingCode(1)
.setCallingCode(5, 9)
.setCallingCode([6, 9])
.setCallingCode(5, [6, 9], [1], '4 5');
Country.addCallingCode(code: ?...string | string[]): Country
Added in: v1.0.0
Method to append calling code(s) onto the callingCode property
arguments:
code: ...string | string[] | undefined | null
returns: Country
throws: TypeError
const Country = require('@scuba-squad/country');
let country = new Country();
country
.addCallingCode(1)
.addCallingCode(5, 9)
.addCallingCode([6, 9])
.addCallingCode(5, [6, 9], [1], '4 5');
Country.removeCallingCode(code: ?...string | string[]): Country
Added in: v1.0.0
Method to remove calling code(s) from the callingCode property
arguments:
code: ...string | string[] | undefined | null
returns: Country
throws: TypeError
const Country = require('@scuba-squad/country');
let country = new Country();
country.callingCode = [1, 5, '6 7', 9];
country.removeCallingCode(1, 3);
country.removeCallingCode(1, 5, 9);
country.removeCallingCode(1, 5, '+6 7');
Country.hasCallingCode(code: ?string): boolean
Added in: v1.0.0
Method to check if the given calling code is set for the country
arguments:
code: string | undefined | null
returns: boolean
throws: TypeError
const Country = require('@scuba-squad/country');
let country = new Country();
country.callingCode = [1, 5, '6 7'];
country.hasCallingCode(3);
country.hasCallingCode(1);
country.hasCallingCode('+6 7');
country.hasCallingCode('+1 5');
country.hasCallingCode(5);
Country.hasAllCallingCodes(codes: ?...string | string[]): boolean
Added in: v1.0.0
Method to check if all the given calling codes are set for the country
arguments:
code: ...string | string[] | undefined | null
returns: Country
throws: TypeError
const Country = require('@scuba-squad/country');
let country = new Country();
country.callingCode = [1, 5, '6 7', 9];
country.hasAllCallingCodes(1, 3);
country.hasAllCallingCodes(1, 5, 9);
country.hasAllCallingCodes(1, 5, '+6 7');
country.hasAllCallingCodes(1, 5, 3);
country.hasAllCallingCodes(1, 5, 9, '6 7');
country.hasAllCallingCodes([1, 3]);
country.hasAllCallingCodes([1, 5, 9]);
country.hasAllCallingCodes([1, 5, '+6 7']);
country.hasAllCallingCodes([1, 5, 3]);
country.hasAllCallingCodes([1, 5, 9, '6 7']);
country.hasAllCallingCodes(1, [3]);
country.hasAllCallingCodes([1], 5, 9);
country.hasAllCallingCodes([1, 5], '+6 7');
country.hasAllCallingCodes(1, [5, 3]);
country.hasAllCallingCodes(1, [5, 9], '6 7');
Country.hasAnyCallingCodes(codes: ?...string | string[]): boolean
Added in: v1.0.0
Method to check if any of the given calling codes are set for the country
arguments:
code: ...string | string[] | undefined | null
returns: Country
throws: TypeError
const Country = require('@scuba-squad/country');
let country = new Country();
country.callingCode = [1, 5, '6 7', 9];
country.hasAnyCallingCodes(2, 3);
country.hasAnyCallingCodes(2, 3, 1);
country.hasAnyCallingCodes(2, 3, '+1');
country.hasAnyCallingCodes(2, 3, 67);
country.hasAnyCallingCodes(2, 3, '6 7');
country.hasAnyCallingCodes([2, 3]);
country.hasAnyCallingCodes([2, 3, 1]);
country.hasAnyCallingCodes([2, 3, '+1']);
country.hasAnyCallingCodes([2, 3, 67]);
country.hasAnyCallingCodes([2, 3, '6 7']);
country.hasAnyCallingCodes(2, [3]);
country.hasAnyCallingCodes(2, 3, [1]);
country.hasAnyCallingCodes(2, [3, '+1']);
country.hasAnyCallingCodes(2, [3, 67]);
country.hasAnyCallingCodes([2, 3], '6 7');
Country.get(properties: ?...string | string[]): object
Added in: v1.0.0
Method to create an object literal containing the set properties
arguments:
code: ...string | string[] | undefined | null
returns: object
throws: TypeError
const Country = require('@scuba-squad/country');
let country = Country.getByIso2Code('US');
country.get('iso3Code', 'callingCode');
country.get(['iso3Code', 'callingCode']);
country.get('iso2Code', ['iso3Code', 'callingCode'], 'isoNumericCode');
Country.set(properties: {name: ?string, iso2Code: ?string, iso3Code: ?string, isoNumericCode: ?string postalCodeRegEx: ?regexp, callingCode: ?string | string[]} = {}): Country
Added in: v1.0.0
Method to bulk set properties on the country
arguments:
properties: object = {}
name: string | null | undefined
iso2Code: string | null | undefined
iso3Code: string | null | undefined
isoNumericCode: string | null | undefined
postalCodeRegEx: regexp | null | undefined
callingCode: string | string[] | null | undefined
returns: Country
throws: TypeError
const Country = require('@scuba-squad/country');
let country = new Country();
country.set({name: 'Petoria', iso2Code: 'FG', iso3Code: 'GUY'});
Country.isValidPostalCode(postalCode: ?string): boolean
Added in: v1.0.0
Method to check if the given postal code is valid for the country
arguments:
code: string | undefined | null
returns: boolean
throws: TypeError
const Country = require('@scuba-squad/country');
let country = new Country();
country.isValidPostalCode();
country.isValidPostalCode(null);
country.isValidPostalCode(NaN);
country.isValidPostalCode(0);
country.isValidPostalCode('');
country.isValidPostalCode([]);
country.isValidPostalCode({});
country.postalCodeRegEx = /^\d{5}$/;
country.isValidPostalCode('12345');
country.isValidPostalCode('1234');
country.isValidPostalCode('123456');
country.isValidPostalCode('123e5');
Country[Symbol.toStringTag]: string
Added in: v1.1.0
returns: string
const Country = require('@scuba-squad/country');
let country = new Country();
country[Symbol.toStringTag];
Object.prototype.toString.call(country);
Test
tests
npm install
npm test
License
MIT