@ladjs/country-language
Advanced tools
Comparing version 0.2.1 to 1.0.0
202
index.js
@@ -1,14 +0,12 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
var _ = require('underscore') | ||
, _d = require('underscore.deep') | ||
, utils = require('./utils') | ||
, data = require('./data.json'); | ||
const data = require('./data.json'); | ||
_.mixin(_d); | ||
var noop = function(err, value) { | ||
function noop(err, value) { | ||
if (err) return err; | ||
return value; | ||
}; | ||
} | ||
function isFunction(obj) { | ||
return typeof obj === 'function'; | ||
} | ||
exports.getCountries = function () { | ||
@@ -27,18 +25,20 @@ return data.countries; | ||
exports.getLanguageCodes = function (codeType, cb) { | ||
var languages = data.languages | ||
, cType | ||
, cTypeNames = [ 'iso639_1', 'iso639_2en', 'iso639_3'] | ||
, codes = []; | ||
const { languages } = data; | ||
const cTypeNames = ['iso639_1', 'iso639_2en', 'iso639_3']; | ||
const codes = []; | ||
cb = cb || (utils.isFunction(codeType) ? codeType : noop); | ||
cb = cb || (isFunction(codeType) ? codeType : noop); | ||
codeType = (codeType && !utils.isFunction(codeType)) ? codeType : 1; | ||
codeType = codeType && !isFunction(codeType) ? codeType : 1; | ||
codeType = Math.floor(Number(codeType)); | ||
if (isNaN(codeType) || codeType < 1 || codeType > cTypeNames.length) { | ||
return cb('Wrong language code type provided. Valid values: 1, 2, 3 for iso639-1, iso639-2, iso639-3 respectively'); | ||
if (Number.isNaN(codeType) || codeType < 1 || codeType > cTypeNames.length) { | ||
return cb( | ||
'Wrong language code type provided. Valid values: 1, 2, 3 for iso639-1, iso639-2, iso639-3 respectively' | ||
); | ||
} | ||
cType = cTypeNames[codeType - 1]; | ||
_.each(languages, function (language) { | ||
const cType = cTypeNames[codeType - 1]; | ||
for (const language of languages) { | ||
if (language[cType]) codes.push(language[cType]); | ||
}); | ||
} | ||
@@ -49,18 +49,20 @@ return cb(null, codes); | ||
exports.getCountryCodes = function (codeType, cb) { | ||
var countries = data.countries | ||
, cType | ||
, cTypeNames = [ 'numCode', 'code_2', 'code_3' ] | ||
, codes = []; | ||
const { countries } = data; | ||
const cTypeNames = ['numCode', 'code_2', 'code_3']; | ||
const codes = []; | ||
cb = cb || (utils.isFunction(codeType) ? codeType : noop); | ||
cb = cb || (isFunction(codeType) ? codeType : noop); | ||
codeType = (codeType && !utils.isFunction(codeType)) ? codeType : 2; | ||
codeType = codeType && !isFunction(codeType) ? codeType : 2; | ||
codeType = Math.floor(Number(codeType)); | ||
if (isNaN(codeType) || codeType < 1 || codeType > cTypeNames.length) { | ||
return cb('Wrong country code type provided. Valid values: 1, 2, 3 for numeric code, alpha-2, alpha-3 respectively'); | ||
if (Number.isNaN(codeType) || codeType < 1 || codeType > cTypeNames.length) { | ||
return cb( | ||
'Wrong country code type provided. Valid values: 1, 2, 3 for numeric code, alpha-2, alpha-3 respectively' | ||
); | ||
} | ||
cType = cTypeNames[codeType - 1]; | ||
_.each(countries, function (country) { | ||
const cType = cTypeNames[codeType - 1]; | ||
for (const country of countries) { | ||
if (country[cType]) codes.push(country[cType]); | ||
}); | ||
} | ||
@@ -71,10 +73,10 @@ return cb(null, codes); | ||
exports.languageCodeExists = function (code) { | ||
var codes | ||
, exists; | ||
let codes; | ||
let exists; | ||
if (!code) return false; | ||
code = code.toLowerCase(); | ||
for (var i = 1; i < 4; i++) { | ||
for (let i = 1; i < 4; i++) { | ||
codes = exports.getLanguageCodes(i); | ||
exists = _.indexOf(codes, code) !== -1; | ||
exists = codes.includes(code); | ||
if (exists) break; | ||
@@ -87,10 +89,10 @@ } | ||
exports.countryCodeExists = function (code) { | ||
var codes | ||
, exists; | ||
let codes; | ||
let exists; | ||
if (!code) return false; | ||
code = code.toUpperCase(); | ||
for (var i = 1; i < 4; i++) { | ||
for (let i = 1; i < 4; i++) { | ||
codes = exports.getCountryCodes(i); | ||
exists = _.indexOf(codes, code) !== -1; | ||
exists = codes.includes(code); | ||
if (exists) break; | ||
@@ -102,11 +104,12 @@ } | ||
exports.getCountry = function (code, cb, noLangInfo) { | ||
var countries = data.countries | ||
, country | ||
, codeFld | ||
, langs; | ||
exports.getCountry = function (code, cb, noLangInfo) { | ||
const { countries } = data; | ||
let country; | ||
let codeFld; | ||
let langs; | ||
if ('string' !== typeof code) { | ||
if (typeof code !== 'string') { | ||
return cb('No country code provided'); | ||
} | ||
cb = cb || noop; | ||
@@ -122,3 +125,3 @@ code = code.toUpperCase(); | ||
if (codeFld) { | ||
country = _.find(countries, function (c) { | ||
country = countries.find((c) => { | ||
return c[codeFld] === code; | ||
@@ -129,27 +132,30 @@ }); | ||
} | ||
country = _.deepClone(country); | ||
country = { ...country }; | ||
if (!noLangInfo) { | ||
langs = country.languages; | ||
country.languages = []; | ||
_.each(langs, function (l) { | ||
for (const l of langs) { | ||
country.languages.push(exports.getLanguage(l, null, true)); | ||
}); | ||
} | ||
} | ||
return cb(null, country); | ||
} else { | ||
return cb('Wrong type of country code provided'); | ||
} | ||
return cb('Wrong type of country code provided'); | ||
}; | ||
exports.getLanguage = function (code, cb, noCountryInfo) { | ||
var languages = data.languages | ||
, language | ||
, codeFld = [] | ||
, countrs; | ||
const { languages } = data; | ||
let language; | ||
const codeFld = []; | ||
let countrs; | ||
cb = cb || noop; | ||
if ('string' !== typeof code) { | ||
if (typeof code !== 'string') { | ||
return cb('No language code provided'); | ||
} | ||
code = code.toLowerCase(); | ||
@@ -160,33 +166,36 @@ | ||
} else if (code.length === 3) { | ||
codeFld.push('iso639_2'); | ||
codeFld.push('iso639_2en'); | ||
codeFld.push('iso639_3'); | ||
codeFld.push('iso639_2', 'iso639_2en', 'iso639_3'); | ||
} | ||
if (codeFld) { | ||
for (var i = 0; i < codeFld.length; i++) { | ||
language = _.find(languages, function (l) { | ||
return l[codeFld[i]] === code; | ||
for (const element of codeFld) { | ||
language = languages.find((l) => { | ||
return l[element] === code; | ||
}); | ||
if (language) break; | ||
} | ||
if (!language) { | ||
return cb('There is no language with code "' + code + '"'); | ||
} | ||
language = _.deepClone(language); | ||
language = { ...language }; | ||
if (!noCountryInfo) { | ||
countrs = language.countries; | ||
language.countries = []; | ||
_.each(countrs, function (c) { | ||
language.countries.push(exports.getCountry(c, null, true)); | ||
}); | ||
if (countrs) | ||
for (const c of countrs) { | ||
language.countries.push(exports.getCountry(c, null, true)); | ||
} | ||
} | ||
return cb(null, language); | ||
} else { | ||
return cb('Wrong type of language code provided'); | ||
} | ||
return cb('Wrong type of language code provided'); | ||
}; | ||
exports.getCountryLanguages = function (code, cb) { | ||
var codes = []; | ||
const codes = []; | ||
@@ -197,9 +206,9 @@ cb = cb || noop; | ||
if (err) return cb(err); | ||
_.each(country.languages, function (l) { | ||
for (const l of country.languages) { | ||
codes.push({ | ||
iso639_1: l.iso639_1 | ||
, iso639_2: l.iso639_2en | ||
, iso639_3: l.iso639_3 | ||
iso639_1: l.iso639_1, | ||
iso639_2: l.iso639_2en, | ||
iso639_3: l.iso639_3 | ||
}); | ||
}); | ||
} | ||
}); | ||
@@ -210,3 +219,3 @@ return cb(null, codes); | ||
exports.getLanguageCountries = function (code, cb) { | ||
var codes = []; | ||
const codes = []; | ||
@@ -217,9 +226,9 @@ cb = cb || noop; | ||
if (err) return cb(err); | ||
_.each(language.countries, function (c) { | ||
for (const c of language.countries) { | ||
codes.push({ | ||
code_2: c.code_2 | ||
, code_3: c.code_3 | ||
, numCode: c.numCode | ||
code_2: c.code_2, | ||
code_3: c.code_3, | ||
numCode: c.numCode | ||
}); | ||
}); | ||
} | ||
}); | ||
@@ -230,3 +239,3 @@ return cb(null, codes); | ||
exports.getCountryMsLocales = function (code, cb) { | ||
var codes = []; | ||
let codes = []; | ||
@@ -243,3 +252,3 @@ cb = cb || noop; | ||
exports.getLanguageMsLocales = function (code, cb) { | ||
var codes = []; | ||
let codes = []; | ||
@@ -256,15 +265,14 @@ cb = cb || noop; | ||
exports.getLanguageFamilyMembers = function (family, cb) { | ||
var languages = data.languages | ||
, check | ||
, members | ||
, ret = []; | ||
const { languages } = data; | ||
const ret = []; | ||
cb = cb || noop; | ||
if ('string' !== typeof family) { | ||
if (typeof family !== 'string') { | ||
return cb('No language family provided'); | ||
} | ||
family = family.toLowerCase(); | ||
check = _.find(data.languageFamilies, function (f) { | ||
const check = data.languageFamilies.find((f) => { | ||
return f.toLowerCase() === family; | ||
@@ -276,8 +284,9 @@ }); | ||
members = _.filter(languages, function (l) { | ||
const members = languages.filter((l) => { | ||
return l.family.toLowerCase() === family; | ||
}); | ||
_.each(members, function (l) { | ||
for (const l of members) { | ||
ret.push(exports.getLanguage(l.iso639_3)); | ||
}); | ||
} | ||
return cb(null, ret); | ||
@@ -287,6 +296,6 @@ }; | ||
exports.getLocales = function (mode) { | ||
var locales = data.locales | ||
, ret = [] | ||
, loc2; | ||
locales.forEach(function (loc) { | ||
const { locales } = data; | ||
const ret = []; | ||
let loc2; | ||
for (const loc of locales) { | ||
loc2 = loc[2] ? '-' + loc[2] : ''; | ||
@@ -298,4 +307,5 @@ if (mode) { | ||
} | ||
}); | ||
} | ||
return ret; | ||
}; |
{ | ||
"name": "@ladjs/country-language", | ||
"description": "Query languages spoken to a country or countries where people speak a language.", | ||
"version": "0.2.1", | ||
"description": "Maintained fork of country-language with zero-dependencies. Query languages spoken to a country or countries where people speak a language.", | ||
"version": "1.0.0", | ||
"author": { | ||
@@ -11,15 +11,31 @@ "name": "Tassos Diamantidis", | ||
"url": "https://github.com/ladjs/country-language/issues", | ||
"email": "opensource@bdswiss.com" | ||
"email": "github@titanism.com" | ||
}, | ||
"dependencies": { | ||
"underscore": "~1.13.1", | ||
"underscore.deep": "~0.5.1" | ||
}, | ||
"contributors": [ | ||
"titanism" | ||
], | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"mocha": "^8.4.0", | ||
"typescript": "^4.2.4" | ||
"@commitlint/cli": "^17.0.3", | ||
"@commitlint/config-conventional": "^17.0.3", | ||
"ava": "^4.3.0", | ||
"cross-env": "^7.0.3", | ||
"eslint": "^8.19.0", | ||
"eslint-config-xo-lass": "^2.0.1", | ||
"fixpack": "^4.0.0", | ||
"husky": "^8.0.1", | ||
"lint-staged": "^13.0.3", | ||
"nyc": "^15.1.0", | ||
"remark-cli": "^11.0.0", | ||
"remark-preset-github": "^4.0.4", | ||
"xo": "^0.50.0" | ||
}, | ||
"engines": { | ||
"node": "*" | ||
"node": ">= 14" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"data.json" | ||
], | ||
"homepage": "https://github.com/ladjs/country-language", | ||
"keywords": [ | ||
@@ -38,10 +54,10 @@ "country", | ||
"type": "git", | ||
"url": "git@github.com:ladjs/country-language.git" | ||
"url": "https://github.com/ladjs/country-language" | ||
}, | ||
"scripts": { | ||
"check": "tsc", | ||
"lint": "eslint --fix .", | ||
"test": "make test" | ||
}, | ||
"types": "index.d.ts" | ||
"lint": "xo --fix && remark . -qfo && fixpack", | ||
"prepare": "husky install", | ||
"pretest": "npm run lint", | ||
"test": "cross-env NODE_ENV=test nyc ava" | ||
} | ||
} |
261
README.md
@@ -1,20 +0,51 @@ | ||
country-language | ||
========== | ||
# [**@ladjs/country-language**](https://github.com/ladjs/country-languages) | ||
> Query any country's spoken languages or countries where a language is spoken. | ||
[![build status](https://github.com/ladjs/country-languages/actions/workflows/ci.yml/badge.svg)](https://github.com/ladjs/country-languages/actions/workflows/ci.yml) | ||
[![code coverage](https://img.shields.io/codecov/c/github/ladjs/country-languages.svg)](https://codecov.io/gh/ladjs/country-languages) | ||
[![code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo) | ||
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier) | ||
[![made with lass](https://img.shields.io/badge/made_with-lass-95CC28.svg)](https://lass.js.org) | ||
[![license](https://img.shields.io/github/license/ladjs/country-languages.svg)]() | ||
## Installation | ||
> **Maintained fork of country-language with zero-dependencies.** Query any country's spoken languages or countries where a language is spoken. | ||
### Node.js | ||
`country-language` is available on [npm](https://www.npmjs.org/package/country-language). | ||
## Table of Contents | ||
$ npm install country-language | ||
* [Install](#install) | ||
* [Usage](#usage) | ||
* [.getLanguageCodes (languageCodeType, cb)](#getlanguagecodes-languagecodetype-cb) | ||
* [.getCountryCodes (countryCodeType, cb)](#getcountrycodes-countrycodetype-cb) | ||
* [.languageCodeExists (languageCode)](#languagecodeexists-languagecode) | ||
* [.countryCodeExists (countryCode)](#countrycodeexists-countrycode) | ||
* [.getCountry (code, cb)](#getcountry-code-cb) | ||
* [.getLanguage (code, cb)](#getlanguage-code-cb) | ||
* [.getCountryLanguages (code, cb)](#getcountrylanguages-code-cb) | ||
* [.getLanguageCountries (code, cb)](#getlanguagecountries-code-cb) | ||
* [.getCountryMsLocales (code, cb)](#getcountrymslocales-code-cb) | ||
* [.getLanguageMsLocales (code, cb)](#getlanguagemslocales-code-cb) | ||
* [.getCountries ()](#getcountries-) | ||
* [.getLanguages ()](#getlanguages-) | ||
* [.getLanguageFamilies ()](#getlanguagefamilies-) | ||
* [.getLocales (mode)](#getlocales-mode) | ||
* [.getLanguageFamilyMembers (family, cb)](#getlanguagefamilymembers-family-cb) | ||
* [Contributors](#contributors) | ||
* [License](#license) | ||
## Install | ||
[npm][]: | ||
```sh | ||
npm install @ladjs/country-language | ||
``` | ||
## Usage | ||
Once you require `country-language`, the following API will be available. | ||
Once you require `@ladjs/country-language`, the following API will be available. | ||
```js | ||
var CountryLanguage = require('country-language'); | ||
const CountryLanguage = require('@ladjs/country-language'); | ||
``` | ||
@@ -24,6 +55,6 @@ | ||
* **@param** _{String}_ language code type. Acceptable values: 1, 2 or 3. | ||
* **@param** _{Function}_ callback on complete or error | ||
* **@cb** _{Error|null}_ if error | ||
* **@cb** _{Object}_ array String with language codes | ||
* **@param** *{String}* language code type. Acceptable values: 1, 2 or 3. | ||
* **@param** *{Function}* callback on complete or error | ||
* **@cb** *{Error|null}* if error | ||
* **@cb** *{Object}* array String with language codes | ||
@@ -34,3 +65,3 @@ Acceptable language code type parameter values: 1, 2, 3 for returning ISO-639-1, ISO-639-2, ISO-639-3 codes respectively. | ||
```js | ||
var allLanguageCodes = CountryLanguage.getLanguageCodes(2); | ||
const allLanguageCodes = CountryLanguage.getLanguageCodes(2); | ||
``` | ||
@@ -40,6 +71,6 @@ | ||
* **@param** _{String}_ country code type. Acceptable values: 1, 2 or 3. | ||
* **@param** _{Function}_ callback on complete or error | ||
* **@cb** _{Error|null}_ if error | ||
* **@cb** _{Object}_ array String with country codes | ||
* **@param** *{String}* country code type. Acceptable values: 1, 2 or 3. | ||
* **@param** *{Function}* callback on complete or error | ||
* **@cb** *{Error|null}* if error | ||
* **@cb** *{Object}* array String with country codes | ||
@@ -50,3 +81,3 @@ Acceptable country code type parameter values: 1, 2, 3 for returning numerical code, alpha-2, alpha-3 codes respectively. | ||
```js | ||
var allCountryCodes = CountryLanguage.getCountryCodes(2); | ||
const allCountryCodes = CountryLanguage.getCountryCodes(2); | ||
``` | ||
@@ -56,3 +87,3 @@ | ||
* **@param** _{String}_ language code to check. | ||
* **@param** *{String}* language code to check. | ||
@@ -63,3 +94,3 @@ Returns Boolean indicating language existance. | ||
```js | ||
var languageExists = CountryLanguage.languageCodeExists('en'); | ||
const languageExists = CountryLanguage.languageCodeExists('en'); | ||
``` | ||
@@ -69,3 +100,3 @@ | ||
* **@param** _{String}_ country code to check. | ||
* **@param** *{String}* country code to check. | ||
@@ -76,3 +107,3 @@ Returns Boolean indicating country existance. | ||
```js | ||
var countryExists = CountryLanguage.countryCodeExists('GB'); | ||
const countryExists = CountryLanguage.countryCodeExists('GB'); | ||
``` | ||
@@ -82,6 +113,6 @@ | ||
* **@param** _{String}_ country code | ||
* **@param** _{Function}_ callback on complete or error | ||
* **@cb** _{Error|null}_ if error | ||
* **@cb** _{Object}_ object containing country info | ||
* **@param** *{String}* country code | ||
* **@param** *{Function}* callback on complete or error | ||
* **@cb** *{Error|null}* if error | ||
* **@cb** *{Object}* object containing country info | ||
@@ -91,26 +122,26 @@ Country code can be either an Alpha-2 or Alpha-3 code. | ||
* ```code_2```: Country alpha-2 code (2 letters) | ||
* ```code_3```: Country alpha-3 code (3 letters) | ||
* ```numCode```: Country numeric code | ||
* ```name```: Country name | ||
* ```languages```: Array of language objects for each language spoken in the country | ||
* ```langCultureMs```: Array of language cultures for the country supported by Microsoft© | ||
* `code_2`: Country alpha-2 code (2 letters) | ||
* `code_3`: Country alpha-3 code (3 letters) | ||
* `numCode`: Country numeric code | ||
* `name`: Country name | ||
* `languages`: Array of language objects for each language spoken in the country | ||
* `langCultureMs`: Array of language cultures for the country supported by Microsoft© | ||
Each language object in ```languages``` property includes the following info: | ||
Each language object in `languages` property includes the following info: | ||
* ```iso639_1```: language iso639-1 code (2 letters) | ||
* ```iso639_2```: language iso639-2 code (3 letters) | ||
* ```iso639_2en```: language iso639-2 code with some codes derived from English names rather than native names of languages (3 letters) | ||
* ```iso639_3```: language iso639-3 code (3 letters) | ||
* ```name```: String array with one or more language names (in English) | ||
* ```nativeName```: String array with one or more language names (in native language) | ||
* ```direction```: Language script direction (either 'LTR' or 'RTL') - Left-to-Right, Right-to-Left | ||
* ```family```: language family | ||
* ```countries```: Array of country objects where this language is spoken | ||
* `iso639_1`: language iso639-1 code (2 letters) | ||
* `iso639_2`: language iso639-2 code (3 letters) | ||
* `iso639_2en`: language iso639-2 code with some codes derived from English names rather than native names of languages (3 letters) | ||
* `iso639_3`: language iso639-3 code (3 letters) | ||
* `name`: String array with one or more language names (in English) | ||
* `nativeName`: String array with one or more language names (in native language) | ||
* `direction`: Language script direction (either "LTR" or "RTL") - Left-to-Right, Right-to-Left | ||
* `family`: language family | ||
* `countries`: Array of country objects where this language is spoken | ||
Each Microsoft© language culture object in ```langCultureMs``` property icludes the following info: | ||
Each Microsoft© language culture object in `langCultureMs` property icludes the following info: | ||
* ```langCultureName```: language culture name | ||
* ```displayName```: language culture dispaly name | ||
* ```cultureCode```: language culture code | ||
* `langCultureName`: language culture name | ||
* `displayName`: language culture dispaly name | ||
* `cultureCode`: language culture code | ||
@@ -122,3 +153,3 @@ ```js | ||
} else { | ||
var languagesInGB = country.languages; | ||
const languagesInGB = country.languages; | ||
} | ||
@@ -130,9 +161,9 @@ }); | ||
* **@param** _{String}_ language code | ||
* **@param** _{Function}_ callback on complete or error | ||
* **@cb** _{Error|null}_ if error | ||
* **@cb** _{Object}_ object containing language info | ||
* **@param** *{String}* language code | ||
* **@param** *{Function}* callback on complete or error | ||
* **@cb** *{Error|null}* if error | ||
* **@cb** *{Object}* object containing language info | ||
Language code can be either iso639-1, iso639-2, iso639-2en or iso639-3 code. | ||
Contents of the returned language object are described in **```.getCountry```** method. | ||
Contents of the returned language object are described in **`.getCountry`** method. | ||
@@ -144,3 +175,3 @@ ```js | ||
} else { | ||
var countriesSpeakingEN = language.countries; | ||
const countriesSpeakingEN = language.countries; | ||
} | ||
@@ -152,6 +183,6 @@ }); | ||
* **@param** _{String}_ country code | ||
* **@param** _{Function}_ callback on complete or error | ||
* **@cb** _{Error|null}_ if error | ||
* **@cb** _{Object}_ object array containing country languages info | ||
* **@param** *{String}* country code | ||
* **@param** *{Function}* callback on complete or error | ||
* **@cb** *{Error|null}* if error | ||
* **@cb** *{Object}* object array containing country languages info | ||
@@ -161,5 +192,5 @@ Country code can be either an Alpha-2 or Alpha-3 code. | ||
* ```iso639_1```: language iso639-1 code (2 letters) | ||
* ```iso639_2```: language iso639-2 code with some codes derived from English names rather than native names of languages (3 letters) | ||
* ```iso639_3```: language iso639-3 code (3 letters) | ||
* `iso639_1`: language iso639-1 code (2 letters) | ||
* `iso639_2`: language iso639-2 code with some codes derived from English names rather than native names of languages (3 letters) | ||
* `iso639_3`: language iso639-3 code (3 letters) | ||
@@ -180,6 +211,6 @@ ```js | ||
* **@param** _{String}_ language code | ||
* **@param** _{Function}_ callback on complete or error | ||
* **@cb** _{Error|null}_ if error | ||
* **@cb** _{Object}_ object array containing country info | ||
* **@param** *{String}* language code | ||
* **@param** *{Function}* callback on complete or error | ||
* **@cb** *{Error|null}* if error | ||
* **@cb** *{Object}* object array containing country info | ||
@@ -189,5 +220,5 @@ Language code can be either iso639-1, iso639-2, iso639-2en or iso639-3 code. | ||
* ```code_2```: Country alpha-2 code (2 letters) | ||
* ```code_3```: Country alpha-3 code (3 letters) | ||
* ```numCode```: Country numeric code | ||
* `code_2`: Country alpha-2 code (2 letters) | ||
* `code_3`: Country alpha-3 code (3 letters) | ||
* `numCode`: Country numeric code | ||
@@ -208,9 +239,9 @@ ```js | ||
* **@param** _{String}_ country code | ||
* **@param** _{Function}_ callback on complete or error | ||
* **@cb** _{Error|null}_ if error | ||
* **@cb** _{Object}_ object array containing Language Cultures info for the country | ||
* **@param** *{String}* country code | ||
* **@param** *{Function}* callback on complete or error | ||
* **@cb** *{Error|null}* if error | ||
* **@cb** *{Object}* object array containing Language Cultures info for the country | ||
Country code can be either an Alpha-2 or Alpha-3 code. | ||
Contents of each Language Culture object are described in **```.getCountry```** method. | ||
Contents of each Language Culture object are described in **`.getCountry`** method. | ||
@@ -231,9 +262,9 @@ ```js | ||
* **@param** _{String}_ language code | ||
* **@param** _{Function}_ callback on complete or error | ||
* **@cb** _{Error|null}_ if error | ||
* **@cb** _{Object}_ object array containing Language Cultures info for the language | ||
* **@param** *{String}* language code | ||
* **@param** *{Function}* callback on complete or error | ||
* **@cb** *{Error|null}* if error | ||
* **@cb** *{Object}* object array containing Language Cultures info for the language | ||
Language code can be either iso639-1, iso639-2, iso639-2en or iso639-3 code. | ||
Contents of each Language Culture object are described in **```.getCountry```** method. | ||
Contents of each Language Culture object are described in **`.getCountry`** method. | ||
@@ -255,6 +286,6 @@ ```js | ||
Returns an array object with info for every country in the world having an ISO 3166 code. | ||
Contents of each country object in the array is described in **```.getCountry```** method. | ||
Contents of each country object in the array is described in **`.getCountry`** method. | ||
```js | ||
var allCountries = CountryLanguage.getCountries(); | ||
const allCountries = CountryLanguage.getCountries(); | ||
``` | ||
@@ -265,6 +296,6 @@ | ||
Returns an array object with info for every language in the world having an ISO 639-2 code (and a few more). | ||
Contents of each language object in the array is described in **```.getCountry```** method. | ||
Contents of each language object in the array is described in **`.getCountry`** method. | ||
```js | ||
var allLanguages = CountryLanguage.getLanguages(); | ||
const allLanguages = CountryLanguage.getLanguages(); | ||
``` | ||
@@ -277,3 +308,3 @@ | ||
```js | ||
var allLanguageFamilies = CountryLanguage.getLanguageFamilies(); | ||
const allLanguageFamilies = CountryLanguage.getLanguageFamilies(); | ||
``` | ||
@@ -283,3 +314,3 @@ | ||
* **@param** _{Boolean}_ locale symbols mode | ||
* **@param** *{Boolean}* locale symbols mode | ||
@@ -289,19 +320,23 @@ Returns an array of strings with all locale codes. | ||
```js | ||
const localesSymbols = CountryLanguage.getLocales(); | ||
``` | ||
If mode is set to true, they will be returned like: **az-AZ-Cyrl** | ||
```js | ||
var localesSymbols = CountryLanguage.getLocales(); | ||
var localesSymbols = CountryLanguage.getLocales(true); | ||
const localesSymbols = CountryLanguage.getLocales(true); | ||
``` | ||
### .getLanguageFamilyMembers (family, cb) | ||
Returns an array object with info for every language in the world having an ISO 639-2 code (and a few more). | ||
Contents of each language object in the array is described in **```.getCountry```** method. | ||
Contents of each language object in the array is described in **`.getCountry`** method. | ||
* **@param** _{String}_ language family name ( | ||
* **@param** _{Function}_ callback on complete or error | ||
* **@cb** _{Error|null}_ if error | ||
* **@cb** _{Object}_ object array containing languages info for each language member in the family. | ||
* **@param** *{String}* language family name ( | ||
* **@param** *{Function}* callback on complete or error | ||
* **@cb** *{Error|null}* if error | ||
* **@cb** *{Object}* object array containing languages info for each language member in the family. | ||
Contents of the returned language object are described in **```.getCountry```** method. | ||
Contents of the returned language object are described in **`.getCountry`** method. | ||
@@ -319,2 +354,3 @@ ```js | ||
``` | ||
<br /> | ||
@@ -335,32 +371,23 @@ ## Notes | ||
the ```cb``` parameter is optional. When not provided, each method returns either an Object when there is no error, or a String in case of an error. | ||
<br/> | ||
<br/> | ||
<br/> | ||
the `cb` parameter is optional. When not provided, each method returns either an Object when there is no error, or a String in case of an error. | ||
Any input parameter (country code, language code, language family name) is case insensitive. | ||
<br/> | ||
<br/> | ||
<br/> | ||
```Language#nativeName``` string is not displayed correclty on the console for Right-to-Left (RTL) languages. However, there is no issue on string rendering (either on the browser or any text editor). | ||
# License | ||
`Language#nativeName` string is not displayed correclty on the console for Right-to-Left (RTL) languages. However, there is no issue on string rendering (either on the browser or any text editor). | ||
Copyright (c) 2014 BDSwiss | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
## Contributors | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
| Name | | ||
| ------------ | | ||
| **titanism** | | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
## License | ||
[MIT](LICENSE) © Tassos Diamantidis | ||
## | ||
[npm]: https://www.npmjs.com/ |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
0
0
368
248280
13
5
12685
1
- Removedunderscore@~1.13.1
- Removedunderscore.deep@~0.5.1
- Removedunderscore@1.13.7(transitive)
- Removedunderscore.deep@0.5.3(transitive)