locale-codes
Advanced tools
Comparing version 1.1.0 to 1.2.0
51
index.js
@@ -5,3 +5,3 @@ const lcid = require('windows-locale') | ||
let all = [] | ||
const all = [] | ||
@@ -14,15 +14,15 @@ let lcidLanguage | ||
lcidKeys.map((id) => { | ||
lcidKeys.map(id => { | ||
lcidLanguage = id | ||
let locale = { | ||
['name'] : lcid[lcidLanguage]['language'], | ||
['local'] : null, | ||
['location'] : lcid[lcidLanguage]['location'], | ||
['tag'] : lcid[lcidLanguage]['tag'], | ||
['lcid'] : lcid[lcidLanguage]['id'], | ||
['iso639-2'] : null, | ||
['iso639-1'] : null | ||
const locale = { | ||
name: lcid[lcidLanguage].language, | ||
local: null, | ||
location: lcid[lcidLanguage].location, | ||
tag: lcid[lcidLanguage].tag, | ||
lcid: lcid[lcidLanguage].id, | ||
'iso639-2': null, | ||
'iso639-1': null | ||
} | ||
isoLanguage = isoKeys.find(name => name.toLowerCase() == lcid[lcidLanguage].language.toLowerCase()) | ||
isoLanguage = isoKeys.find(name => name.toLowerCase() === lcid[lcidLanguage].language.toLowerCase()) | ||
if (isoLanguage) { | ||
@@ -34,4 +34,5 @@ locale['iso639-2'] = iso[isoLanguage]['iso639-2'] | ||
if (element['2T']) { | ||
return element['2T'].toLowerCase() == locale['iso639-2'] | ||
return element['2T'].toLowerCase() === locale['iso639-2'] | ||
} | ||
return false | ||
@@ -41,8 +42,6 @@ }) | ||
if (nameLocal) { | ||
locale['local'] = nameLocal.local | ||
locale.local = nameLocal.local | ||
} | ||
} | ||
all.push(locale) | ||
@@ -52,21 +51,22 @@ }) | ||
const where = (key = 'name', text = '') => { | ||
if (key == 'lcid') { | ||
return all.find(e => e[key] == text) | ||
if (key === 'lcid') { | ||
return all.find(element => element[key] === text) | ||
} | ||
return all.find(e => e[key].toLowerCase() == text.toLowerCase()) | ||
return all.find(element => element[key].toLowerCase() === text.toLowerCase()) | ||
} | ||
const getByName = (text) => where('name', text) | ||
const getByName = text => where('name', text) | ||
const getByNameLocal = (text) => where('local', text) | ||
const getByNameLocal = text => where('local', text) | ||
const getByLocation = (text) => where('location', text) | ||
const getByLocation = text => where('location', text) | ||
const getByTag = (text) => where('tag', text) | ||
const getByTag = text => where('tag', text) | ||
const getByLCID = (id) => where('lcid', Number(id)) | ||
const getByLCID = id => where('lcid', Number(id)) | ||
const getByISO6392 = (text) => where('iso639-2', text) | ||
const getByISO6392 = text => where('iso639-2', text) | ||
const getByISO6391 = (text) => where('iso639-1', text) | ||
const getByISO6391 = text => where('iso639-1', text) | ||
@@ -77,2 +77,3 @@ module.exports = { | ||
getByName, | ||
getByNameLocal, | ||
getByLocation, | ||
@@ -79,0 +80,0 @@ getByTag, |
@@ -5,3 +5,3 @@ { | ||
"preferGlobal": false, | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": " Language codes & country codes", | ||
@@ -38,3 +38,3 @@ "author": { | ||
"start": "node index.js", | ||
"test": "node test.js" | ||
"test": "xo && tsd && node test.js" | ||
}, | ||
@@ -60,3 +60,4 @@ "engines": { | ||
"README.md", | ||
"index.js" | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
@@ -68,3 +69,12 @@ "dependencies": { | ||
}, | ||
"devDependencies": {} | ||
"devDependencies": { | ||
"tsd": "^0.11.0", | ||
"xo": "^0.30.0" | ||
}, | ||
"xo": { | ||
"semicolon": false, | ||
"rules": { | ||
"array-callback-return": "off" | ||
} | ||
} | ||
} |
# Locale Codes | ||
[![Travis](https://img.shields.io/travis/TiagoDanin/Locale-Codes.svg?branch=master&style=flat-square)](https://travis-ci.org/TiagoDanin/Locale-Codes) [![Downloads](https://img.shields.io/npm/dt/locale-codes.svg?style=flat-square)](https://npmjs.org/package/locale-codes) [![Node](https://img.shields.io/node/v/locale-codes.svg?style=flat-square)](https://npmjs.org/package/locale-codes) [![Version](https://img.shields.io/npm/v/locale-codes.svg?style=flat-square)](https://npmjs.org/package/locale-codes) | ||
[![Travis](https://img.shields.io/travis/TiagoDanin/Locale-Codes.svg?branch=master&style=flat-square)](https://travis-ci.org/TiagoDanin/Locale-Codes) [![Downloads](https://img.shields.io/npm/dt/locale-codes.svg?style=flat-square)](https://npmjs.org/package/locale-codes) [![Node](https://img.shields.io/node/v/locale-codes.svg?style=flat-square)](https://npmjs.org/package/locale-codes) [![Version](https://img.shields.io/npm/v/locale-codes.svg?style=flat-square)](https://npmjs.org/package/locale-codes) [![XO code style](https://img.shields.io/badge/code%20style-XO-red.svg?style=flat-square)](https://github.com/xojs/xo) | ||
@@ -9,20 +9,38 @@ Language codes & country codes | ||
Module available through the [npm registry](https://www.npmjs.com/). It can be installed using the [`npm`](https://docs.npmjs.com/getting-started/installing-npm-packages-locally) or [`yarn`](https://yarnpkg.com/en/) command line tools. | ||
Module available through the [npm registry](https://www.npmjs.com/). It can be installed using the [`npm`](https://docs.npmjs.com/getting-started/installing-npm-packages-locally) or [`yarn`](https://yarnpkg.com/en/) command line tool. | ||
```sh | ||
# NPM | ||
# Yarn (Recomend) | ||
yarn add locale-codes | ||
# NPM | ||
npm install locale-codes --save | ||
# Or Using Yarn | ||
yarn add locale-codes | ||
``` | ||
## Example | ||
## Examples | ||
### JavaScript | ||
```js | ||
/* eslint-disable no-unused-expressions */ | ||
const locale = require('locale-codes') | ||
locale.all // [language: '...] | ||
locale.all // [language: '...'] | ||
locale.getByTag('pt-br').name // 'Portuguese' | ||
locale.where('tag', 'pt-br').name // 'Portuguese' | ||
``` | ||
### TypeScript | ||
```ts | ||
/* eslint-disable @typescript-eslint/no-unused-expressions, @typescript-eslint/no-unused-vars */ | ||
import * as locale from 'locale-codes' | ||
import {ILocale} from '.' | ||
locale.all // [language: '...'] | ||
const localeSelect: ILocale = locale.all[0] | ||
locale.getByTag('pt-br').name // 'Portuguese' | ||
locale.where('tag', 'pt-br').name // 'Portuguese' | ||
``` | ||
## Documentation | ||
@@ -884,5 +902,3 @@ | ||
```sh | ||
# NPM | ||
npm test | ||
# Or Using Yarn | ||
# Using Yarn | ||
yarn test | ||
@@ -900,2 +916,8 @@ ``` | ||
<details> | ||
<summary><a href="https://ghub.io/langs">langs</a>: ISO 639-1/2/3 Language codes with English and local names</summary> | ||
<b>Author</b>: adlawson</br> | ||
<b>License</b>: MIT</br> | ||
<b>Version</b>: ^2.0.0 | ||
</details> | ||
<details> | ||
<summary><a href="https://ghub.io/windows-locale">windows-locale</a>: Windows Language Code Identifier (LCID) for JavaScript</summary> | ||
@@ -906,8 +928,17 @@ <b>Author</b>: Tiago Danin</br> | ||
</details> | ||
## Dev Dependencies | ||
<details> | ||
<summary><a href="https://ghub.io/langs">langs</a>: ISO 639-1/2/3 Language codes with English and local names</summary> | ||
<b>Author</b>: adlawson</br> | ||
<summary><a href="https://ghub.io/tsd">tsd</a>: Check TypeScript type definitions</summary> | ||
<b>Author</b>: Sam Verschueren</br> | ||
<b>License</b>: MIT</br> | ||
<b>Version</b>: ^2.0.0 | ||
<b>Version</b>: ^0.11.0 | ||
</details> | ||
<details> | ||
<summary><a href="https://ghub.io/xo">xo</a>: JavaScript/TypeScript linter with great defaults</summary> | ||
<b>Author</b>: Sindre Sorhus</br> | ||
<b>License</b>: MIT</br> | ||
<b>Version</b>: ^0.30.0 | ||
</details> | ||
@@ -914,0 +945,0 @@ ## Contributors |
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
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
58884
5
147
947
2