Add initial 11ty website structure

This commit is contained in:
Marc Froehlich
2026-07-06 01:04:06 +02:00
parent 62b6bbdcbc
commit 80214bf42d
1378 changed files with 204162 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
{
// 基于 airbnb 规则
"extends": "airbnb",
// 使用 babel 解析器,支持一些还没有进入 ES6+ 标准的特性。比如 class property
"parser": "babel-eslint",
// 解析 webpack alias 中的模块名
"settings": {
"import/resolver": "webpack"
},
"env": {
"browser": true
},
"rules": {
"no-plusplus": [
"error",
{
// 允许 for 循环中的 i++
"allowForLoopAfterthoughts": true
}
],
"no-param-reassign": [
"error",
{
// 允许修改参数的属性
"props": false
}
],
// 允许在循环里使用 await
"no-await-in-loop": 0,
// 允许在一个表达式里使用多种操作符,否则与 prettier 冲突
// see https://github.com/prettier/eslint-config-prettier#no-mixed-operators
"no-mixed-operators": 0,
// 允许在 jsx 中使用 bind
"react/jsx-no-bind": 0,
// 允许所有类型的 proptype
"react/forbid-prop-types": 0
}
}
+1
View File
@@ -0,0 +1 @@
14.17
+4
View File
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
+6
View File
@@ -0,0 +1,6 @@
language: node_js
node_js:
- '8.0'
- '6.1'
script:
- npm run test
+5
View File
@@ -0,0 +1,5 @@
{
"eslint.enable": true,
"eslint.packageManager": "yarn",
"prettier.eslintIntegration": true
}
+79
View File
@@ -0,0 +1,79 @@
# iso-639-1 Changelog
## v3.1.5
- ISO6391.validate() type predicate [#87](https://github.com/meikidd/iso-639-1/pull/87)
## v3.1.4
- Fix native language name for Czech and Slovak [#86](https://github.com/meikidd/iso-639-1/issues/86)
## v3.1.3
- Remove unnecessary diacritics [#84](https://github.com/meikidd/iso-639-1/pull/84)
## v3.1.2
- Capitalize Faroese native [#82](https://github.com/meikidd/iso-639-1/pull/82)
## v3.1.1
- Capitalize Danish native [#80](https://github.com/meikidd/iso-639-1/pull/80)
## v3.1.0
- Fix type for getCode [#74](https://github.com/meikidd/iso-639-1/pull/74)
- Improve performance [#72](https://github.com/meikidd/iso-639-1/pull/72)
## v3.0.1
- Fix error TS7016 [#68](https://github.com/meikidd/iso-639-1/issues/68)
## v3.0.0
- Export ESM module [#67](https://github.com/meikidd/iso-639-1/issues/67)
## v2.1.15
- Change parameters type "LanguageCode" to "string"
## v2.1.14
- Bump async from 2.6.0 to 2.6.4 [#53](https://github.com/meikidd/iso-639-1/pull/53)
- Add a type to list the langage codes in the TS definition file [#55](https://github.com/meikidd/iso-639-1/pull/55)
## v2.1.13
- update Arabic native name [#50](https://github.com/meikidd/iso-639-1/pull/50)
## v2.1.12
- remove 'bh' [#51](https://github.com/meikidd/iso-639-1/pull/51)
- fj native name changed to "vosa Vakaviti" [#51](https://github.com/meikidd/iso-639-1/pull/51)
- dv native name changed to "ދިވެހި" [#51](https://github.com/meikidd/iso-639-1/pull/51)
- lo native name changed to "ພາສາລາວ" [#51](https://github.com/meikidd/iso-639-1/pull/51)
- ms native name changed to "Bahasa Melayu" [#51](https://github.com/meikidd/iso-639-1/pull/51)
- lu native name changed to "Kiluba" [#51](https://github.com/meikidd/iso-639-1/pull/51)
- na native name changed to "Dorerin Naoero" [#51](https://github.com/meikidd/iso-639-1/pull/51)
- tk native name changed to "Türkmençe" [#51](https://github.com/meikidd/iso-639-1/pull/51)
## v2.1.11
- Slovenian native name "slovenski jezik" -> "slovenščina" [#49](https://github.com/meikidd/iso-639-1/pull/49)
## v2.1.10
- Polish native name "język polski" -> "Polski" [#48](https://github.com/meikidd/iso-639-1/pull/48)
## v2.1.9
- Change hu native name "Magyar" -> "magyar" [#40](https://github.com/meikidd/iso-639-1/pull/40)
## v2.1.8
- Change hr native name "hrvatski jezik" -> "Hrvatski"
- Change sl English name "Slovene" -> "Slovenian"
## v2.1.0
- Correctly handle prototype property names passed as codes [#20](https://github.com/meikidd/iso-639-1/issues/20)
+21
View File
@@ -0,0 +1,21 @@
This software is licensed under the MIT License.
Copyright(c) by Mei Qingguang
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:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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.
+205
View File
@@ -0,0 +1,205 @@
declare module 'iso-639-1' {
export type LanguageCode =
'aa'
| 'ab'
| 'ae'
| 'af'
| 'ak'
| 'am'
| 'an'
| 'ar'
| 'as'
| 'av'
| 'ay'
| 'az'
| 'ba'
| 'be'
| 'bg'
| 'bi'
| 'bm'
| 'bn'
| 'bo'
| 'br'
| 'bs'
| 'ca'
| 'ce'
| 'ch'
| 'co'
| 'cr'
| 'cs'
| 'cu'
| 'cv'
| 'cy'
| 'da'
| 'de'
| 'dv'
| 'dz'
| 'ee'
| 'el'
| 'en'
| 'eo'
| 'es'
| 'et'
| 'eu'
| 'fa'
| 'ff'
| 'fi'
| 'fj'
| 'fo'
| 'fr'
| 'fy'
| 'ga'
| 'gd'
| 'gl'
| 'gn'
| 'gu'
| 'gv'
| 'ha'
| 'he'
| 'hi'
| 'ho'
| 'hr'
| 'ht'
| 'hu'
| 'hy'
| 'hz'
| 'ia'
| 'id'
| 'ie'
| 'ig'
| 'ii'
| 'ik'
| 'io'
| 'is'
| 'it'
| 'iu'
| 'ja'
| 'jv'
| 'ka'
| 'kg'
| 'ki'
| 'kj'
| 'kk'
| 'kl'
| 'km'
| 'kn'
| 'ko'
| 'kr'
| 'ks'
| 'ku'
| 'kv'
| 'kw'
| 'ky'
| 'la'
| 'lb'
| 'lg'
| 'li'
| 'ln'
| 'lo'
| 'lt'
| 'lu'
| 'lv'
| 'mg'
| 'mh'
| 'mi'
| 'mk'
| 'ml'
| 'mn'
| 'mr'
| 'ms'
| 'mt'
| 'my'
| 'na'
| 'nb'
| 'nd'
| 'ne'
| 'ng'
| 'nl'
| 'nn'
| 'no'
| 'nr'
| 'nv'
| 'ny'
| 'oc'
| 'oj'
| 'om'
| 'or'
| 'os'
| 'pa'
| 'pi'
| 'pl'
| 'ps'
| 'pt'
| 'qu'
| 'rm'
| 'rn'
| 'ro'
| 'ru'
| 'rw'
| 'sa'
| 'sc'
| 'sd'
| 'se'
| 'sg'
| 'si'
| 'sk'
| 'sl'
| 'sm'
| 'sn'
| 'so'
| 'sq'
| 'sr'
| 'ss'
| 'st'
| 'su'
| 'sv'
| 'sw'
| 'ta'
| 'te'
| 'tg'
| 'th'
| 'ti'
| 'tk'
| 'tl'
| 'tn'
| 'to'
| 'tr'
| 'ts'
| 'tt'
| 'tw'
| 'ty'
| 'ug'
| 'uk'
| 'ur'
| 'uz'
| 've'
| 'vi'
| 'vo'
| 'wa'
| 'wo'
| 'xh'
| 'yi'
| 'yo'
| 'za'
| 'zh'
| 'zu'
interface ISO6391 {
getName: (code: string) => string;
getAllNames: () => Array<string>;
getNativeName: (code: string) => string;
getAllNativeNames: () => Array<string>;
getCode: (name: string) => LanguageCode | "";
getAllCodes: () => Array<LanguageCode>;
validate: (code: string) => code is LanguageCode;
getLanguages: (codes: Array<string>) => Array<{
code: LanguageCode;
name: string;
nativeName: string;
}>;
}
let localeCode: ISO6391;
export default localeCode;
}
+41
View File
@@ -0,0 +1,41 @@
{
"name": "iso-639-1",
"version": "3.1.6",
"description": "ISO-639-1 codes",
"main": "./src/index.js",
"type": "commonjs",
"typings": "index.d.ts",
"scripts": {
"build": "webpack",
"test": "mocha"
},
"repository": {
"type": "git",
"url": "git+https://github.com/meikidd/iso-639-1.git"
},
"keywords": [
"iso",
"iso-639",
"iso-639-1",
"language",
"language code",
"locale",
"locale code"
],
"author": "meikidd <meikidd@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/meikidd/iso-639-1/issues"
},
"devDependencies": {
"babel-loader": "^9.1.3",
"clean-webpack-plugin": "^4.0.0",
"mocha": "^4.0.1",
"webpack": "^5.88.2",
"webpack-cli": "^5.1.4"
},
"homepage": "https://github.com/meikidd/iso-639-1#readme",
"engines": {
"node": ">=6.0"
}
}
+121
View File
@@ -0,0 +1,121 @@
# ISO-639-1
[![NPM Version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]
[![Download Count][download-url]][npm-url]
[travis-image]: https://travis-ci.org/meikidd/iso-639-1.svg?branch=master
[travis-url]: https://travis-ci.org/meikidd/iso-639-1
[npm-image]: https://img.shields.io/npm/v/iso-639-1.svg?style=flat-square
[npm-url]: https://npmjs.org/package/iso-639-1
[download-url]: https://img.shields.io/npm/dt/iso-639-1.svg?style=flat-square
Simple interface for [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language codes
## Installation
```
npm install iso-639-1
```
## Usage
### Node.js
```javascript
const ISO6391 = require('iso-639-1');
console.log(ISO6391.getName('en')); // 'English'
```
### ES Module
```javascript
import ISO6391 from 'iso-639-1';
console.log(ISO6391.getName('en')); // 'English'
```
### Browsers
HTML
```html
<script type="text/javascript" src="./node_modules/iso-639-1/build/index.js"></script>
```
Visit global variable ISO6391 in js
```javascript
console.log(ISO6391.getName('en')); // 'English'
```
## Methods
### getName(code)
- @param code {string}
- @return {string}
Lookup language english name by code
### getAllNames()
- @return {array}
Get array of all language english names
### getNativeName(code)
- @param code {string}
- @return {string}
Lookup language native name by code
### getAllNativeNames()
- @return {array}
Get array of all language native names
### getCode(name)
- @param name {string}
- @return {string}
Lookup code by english name or native name
### getAllCodes()
- @return {array}
Get array of all codes
### validate(code)
- @param code {string}
- @return {boolean}
Check whether the given code is in the list of [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)
### getLanguages(codes)
- @param codes {array}
- @return {array}
Get the array of the language objects by the given codes
## Example
```
const ISO6391 = require('iso-639-1')
console.log(ISO6391.getName('zh')) // 'Chinese'
console.log(ISO6391.getNativeName('zh')) // '中文'
console.log(ISO6391.getAllNames()) // ['Afar','Abkhaz', ... ,'Zulu']
console.log(ISO6391.getAllNativeNames()) //['Afaraf','аҧсуа бызшәа', ... ,'isiZulu' ]
console.log(ISO6391.getCode('Chinese')) // 'zh'
console.log(ISO6391.getCode('中文')) // 'zh'
console.log(ISO6391.getAllCodes()) //['aa','ab',...,'zu']
console.log(ISO6391.validate('en')) // true
console.log(ISO6391.validate('xx')) // false
console.log(ISO6391.getLanguages(['en', 'zh']))
// [{code:'en',name:'English',nativeName:'English'},{code:'zh',name:'Chinese',nativeName:'中文'}]
```
+736
View File
@@ -0,0 +1,736 @@
const LANGUAGES_LIST = {
aa: {
name: 'Afar',
nativeName: 'Afaraf',
},
ab: {
name: 'Abkhaz',
nativeName: 'аҧсуа бызшәа',
},
ae: {
name: 'Avestan',
nativeName: 'avesta',
},
af: {
name: 'Afrikaans',
nativeName: 'Afrikaans',
},
ak: {
name: 'Akan',
nativeName: 'Akan',
},
am: {
name: 'Amharic',
nativeName: 'አማርኛ',
},
an: {
name: 'Aragonese',
nativeName: 'aragonés',
},
ar: {
name: 'Arabic',
nativeName: 'العربية',
},
as: {
name: 'Assamese',
nativeName: 'অসমীয়া',
},
av: {
name: 'Avaric',
nativeName: 'авар мацӀ',
},
ay: {
name: 'Aymara',
nativeName: 'aymar aru',
},
az: {
name: 'Azerbaijani',
nativeName: 'azərbaycan dili',
},
ba: {
name: 'Bashkir',
nativeName: 'башҡорт теле',
},
be: {
name: 'Belarusian',
nativeName: 'беларуская мова',
},
bg: {
name: 'Bulgarian',
nativeName: 'български език',
},
bi: {
name: 'Bislama',
nativeName: 'Bislama',
},
bm: {
name: 'Bambara',
nativeName: 'bamanankan',
},
bn: {
name: 'Bengali',
nativeName: 'বাংলা',
},
bo: {
name: 'Tibetan',
nativeName: 'བོད་ཡིག',
},
br: {
name: 'Breton',
nativeName: 'brezhoneg',
},
bs: {
name: 'Bosnian',
nativeName: 'bosanski jezik',
},
ca: {
name: 'Catalan',
nativeName: 'Català',
},
ce: {
name: 'Chechen',
nativeName: 'нохчийн мотт',
},
ch: {
name: 'Chamorro',
nativeName: 'Chamoru',
},
co: {
name: 'Corsican',
nativeName: 'corsu',
},
cr: {
name: 'Cree',
nativeName: 'ᓀᐦᐃᔭᐍᐏᐣ',
},
cs: {
name: 'Czech',
nativeName: 'čeština',
},
cu: {
name: 'Old Church Slavonic',
nativeName: 'ѩзыкъ словѣньскъ',
},
cv: {
name: 'Chuvash',
nativeName: 'чӑваш чӗлхи',
},
cy: {
name: 'Welsh',
nativeName: 'Cymraeg',
},
da: {
name: 'Danish',
nativeName: 'Dansk',
},
de: {
name: 'German',
nativeName: 'Deutsch',
},
dv: {
name: 'Divehi',
nativeName: 'ދިވެހި',
},
dz: {
name: 'Dzongkha',
nativeName: 'རྫོང་ཁ',
},
ee: {
name: 'Ewe',
nativeName: 'Eʋegbe',
},
el: {
name: 'Greek',
nativeName: 'Ελληνικά',
},
en: {
name: 'English',
nativeName: 'English',
},
eo: {
name: 'Esperanto',
nativeName: 'Esperanto',
},
es: {
name: 'Spanish',
nativeName: 'Español',
},
et: {
name: 'Estonian',
nativeName: 'eesti',
},
eu: {
name: 'Basque',
nativeName: 'euskara',
},
fa: {
name: 'Persian',
nativeName: 'فارسی',
},
ff: {
name: 'Fula',
nativeName: 'Fulfulde',
},
fi: {
name: 'Finnish',
nativeName: 'suomi',
},
fj: {
name: 'Fijian',
nativeName: 'vosa Vakaviti',
},
fo: {
name: 'Faroese',
nativeName: 'Føroyskt',
},
fr: {
name: 'French',
nativeName: 'Français',
},
fy: {
name: 'Western Frisian',
nativeName: 'Frysk',
},
ga: {
name: 'Irish',
nativeName: 'Gaeilge',
},
gd: {
name: 'Scottish Gaelic',
nativeName: 'Gàidhlig',
},
gl: {
name: 'Galician',
nativeName: 'galego',
},
gn: {
name: 'Guaraní',
nativeName: "Avañe'ẽ",
},
gu: {
name: 'Gujarati',
nativeName: 'ગુજરાતી',
},
gv: {
name: 'Manx',
nativeName: 'Gaelg',
},
ha: {
name: 'Hausa',
nativeName: 'هَوُسَ',
},
he: {
name: 'Hebrew',
nativeName: 'עברית',
},
hi: {
name: 'Hindi',
nativeName: 'हिन्दी',
},
ho: {
name: 'Hiri Motu',
nativeName: 'Hiri Motu',
},
hr: {
name: 'Croatian',
nativeName: 'Hrvatski',
},
ht: {
name: 'Haitian',
nativeName: 'Kreyòl ayisyen',
},
hu: {
name: 'Hungarian',
nativeName: 'magyar',
},
hy: {
name: 'Armenian',
nativeName: 'Հայերեն',
},
hz: {
name: 'Herero',
nativeName: 'Otjiherero',
},
ia: {
name: 'Interlingua',
nativeName: 'Interlingua',
},
id: {
name: 'Indonesian',
nativeName: 'Bahasa Indonesia',
},
ie: {
name: 'Interlingue',
nativeName: 'Interlingue',
},
ig: {
name: 'Igbo',
nativeName: 'Asụsụ Igbo',
},
ii: {
name: 'Nuosu',
nativeName: 'ꆈꌠ꒿ Nuosuhxop',
},
ik: {
name: 'Inupiaq',
nativeName: 'Iñupiaq',
},
io: {
name: 'Ido',
nativeName: 'Ido',
},
is: {
name: 'Icelandic',
nativeName: 'Íslenska',
},
it: {
name: 'Italian',
nativeName: 'Italiano',
},
iu: {
name: 'Inuktitut',
nativeName: 'ᐃᓄᒃᑎᑐᑦ',
},
ja: {
name: 'Japanese',
nativeName: '日本語',
},
jv: {
name: 'Javanese',
nativeName: 'basa Jawa',
},
ka: {
name: 'Georgian',
nativeName: 'ქართული',
},
kg: {
name: 'Kongo',
nativeName: 'Kikongo',
},
ki: {
name: 'Kikuyu',
nativeName: 'Gĩkũyũ',
},
kj: {
name: 'Kwanyama',
nativeName: 'Kuanyama',
},
kk: {
name: 'Kazakh',
nativeName: 'қазақ тілі',
},
kl: {
name: 'Kalaallisut',
nativeName: 'kalaallisut',
},
km: {
name: 'Khmer',
nativeName: 'ខេមរភាសា',
},
kn: {
name: 'Kannada',
nativeName: 'ಕನ್ನಡ',
},
ko: {
name: 'Korean',
nativeName: '한국어',
},
kr: {
name: 'Kanuri',
nativeName: 'Kanuri',
},
ks: {
name: 'Kashmiri',
nativeName: 'कश्मीरी',
},
ku: {
name: 'Kurdish',
nativeName: 'Kurdî',
},
kv: {
name: 'Komi',
nativeName: 'коми кыв',
},
kw: {
name: 'Cornish',
nativeName: 'Kernewek',
},
ky: {
name: 'Kyrgyz',
nativeName: 'Кыргызча',
},
la: {
name: 'Latin',
nativeName: 'latine',
},
lb: {
name: 'Luxembourgish',
nativeName: 'Lëtzebuergesch',
},
lg: {
name: 'Ganda',
nativeName: 'Luganda',
},
li: {
name: 'Limburgish',
nativeName: 'Limburgs',
},
ln: {
name: 'Lingala',
nativeName: 'Lingála',
},
lo: {
name: 'Lao',
nativeName: 'ພາສາລາວ',
},
lt: {
name: 'Lithuanian',
nativeName: 'lietuvių kalba',
},
lu: {
name: 'Luba-Katanga',
nativeName: 'Kiluba',
},
lv: {
name: 'Latvian',
nativeName: 'latviešu valoda',
},
mg: {
name: 'Malagasy',
nativeName: 'fiteny malagasy',
},
mh: {
name: 'Marshallese',
nativeName: 'Kajin M̧ajeļ',
},
mi: {
name: 'Māori',
nativeName: 'te reo Māori',
},
mk: {
name: 'Macedonian',
nativeName: 'македонски јазик',
},
ml: {
name: 'Malayalam',
nativeName: 'മലയാളം',
},
mn: {
name: 'Mongolian',
nativeName: 'Монгол хэл',
},
mr: {
name: 'Marathi',
nativeName: 'मराठी',
},
ms: {
name: 'Malay',
nativeName: 'Bahasa Melayu',
},
mt: {
name: 'Maltese',
nativeName: 'Malti',
},
my: {
name: 'Burmese',
nativeName: 'ဗမာစာ',
},
na: {
name: 'Nauru',
nativeName: 'Dorerin Naoero',
},
nb: {
name: 'Norwegian Bokmål',
nativeName: 'Norsk bokmål',
},
nd: {
name: 'Northern Ndebele',
nativeName: 'isiNdebele',
},
ne: {
name: 'Nepali',
nativeName: 'नेपाली',
},
ng: {
name: 'Ndonga',
nativeName: 'Owambo',
},
nl: {
name: 'Dutch',
nativeName: 'Nederlands',
},
nn: {
name: 'Norwegian Nynorsk',
nativeName: 'Norsk nynorsk',
},
no: {
name: 'Norwegian',
nativeName: 'Norsk',
},
nr: {
name: 'Southern Ndebele',
nativeName: 'isiNdebele',
},
nv: {
name: 'Navajo',
nativeName: 'Diné bizaad',
},
ny: {
name: 'Chichewa',
nativeName: 'chiCheŵa',
},
oc: {
name: 'Occitan',
nativeName: 'occitan',
},
oj: {
name: 'Ojibwe',
nativeName: 'ᐊᓂᔑᓈᐯᒧᐎᓐ',
},
om: {
name: 'Oromo',
nativeName: 'Afaan Oromoo',
},
or: {
name: 'Oriya',
nativeName: 'ଓଡ଼ିଆ',
},
os: {
name: 'Ossetian',
nativeName: 'ирон æвзаг',
},
pa: {
name: 'Panjabi',
nativeName: 'ਪੰਜਾਬੀ',
},
pi: {
name: 'Pāli',
nativeName: 'पाऴि',
},
pl: {
name: 'Polish',
nativeName: 'Polski',
},
ps: {
name: 'Pashto',
nativeName: 'پښتو',
},
pt: {
name: 'Portuguese',
nativeName: 'Português',
},
qu: {
name: 'Quechua',
nativeName: 'Runa Simi',
},
rm: {
name: 'Romansh',
nativeName: 'rumantsch grischun',
},
rn: {
name: 'Kirundi',
nativeName: 'Ikirundi',
},
ro: {
name: 'Romanian',
nativeName: 'Română',
},
ru: {
name: 'Russian',
nativeName: 'Русский',
},
rw: {
name: 'Kinyarwanda',
nativeName: 'Ikinyarwanda',
},
sa: {
name: 'Sanskrit',
nativeName: 'संस्कृतम्',
},
sc: {
name: 'Sardinian',
nativeName: 'sardu',
},
sd: {
name: 'Sindhi',
nativeName: 'सिन्धी',
},
se: {
name: 'Northern Sami',
nativeName: 'Davvisámegiella',
},
sg: {
name: 'Sango',
nativeName: 'yângâ tî sängö',
},
si: {
name: 'Sinhala',
nativeName: 'සිංහල',
},
sk: {
name: 'Slovak',
nativeName: 'slovenčtina',
},
sl: {
name: 'Slovenian',
nativeName: 'slovenščina',
},
sm: {
name: 'Samoan',
nativeName: "gagana fa'a Samoa",
},
sn: {
name: 'Shona',
nativeName: 'chiShona',
},
so: {
name: 'Somali',
nativeName: 'Soomaaliga',
},
sq: {
name: 'Albanian',
nativeName: 'Shqip',
},
sr: {
name: 'Serbian',
nativeName: 'српски језик',
},
ss: {
name: 'Swati',
nativeName: 'SiSwati',
},
st: {
name: 'Southern Sotho',
nativeName: 'Sesotho',
},
su: {
name: 'Sundanese',
nativeName: 'Basa Sunda',
},
sv: {
name: 'Swedish',
nativeName: 'Svenska',
},
sw: {
name: 'Swahili',
nativeName: 'Kiswahili',
},
ta: {
name: 'Tamil',
nativeName: 'தமிழ்',
},
te: {
name: 'Telugu',
nativeName: 'తెలుగు',
},
tg: {
name: 'Tajik',
nativeName: 'тоҷикӣ',
},
th: {
name: 'Thai',
nativeName: 'ไทย',
},
ti: {
name: 'Tigrinya',
nativeName: 'ትግርኛ',
},
tk: {
name: 'Turkmen',
nativeName: 'Türkmençe',
},
tl: {
name: 'Tagalog',
nativeName: 'Wikang Tagalog',
},
tn: {
name: 'Tswana',
nativeName: 'Setswana',
},
to: {
name: 'Tonga',
nativeName: 'faka Tonga',
},
tr: {
name: 'Turkish',
nativeName: 'Türkçe',
},
ts: {
name: 'Tsonga',
nativeName: 'Xitsonga',
},
tt: {
name: 'Tatar',
nativeName: 'татар теле',
},
tw: {
name: 'Twi',
nativeName: 'Twi',
},
ty: {
name: 'Tahitian',
nativeName: 'Reo Tahiti',
},
ug: {
name: 'Uyghur',
nativeName: 'ئۇيغۇرچە‎',
},
uk: {
name: 'Ukrainian',
nativeName: 'Українська',
},
ur: {
name: 'Urdu',
nativeName: 'اردو',
},
uz: {
name: 'Uzbek',
nativeName: 'Ўзбек',
},
ve: {
name: 'Venda',
nativeName: 'Tshivenḓa',
},
vi: {
name: 'Vietnamese',
nativeName: 'Tiếng Việt',
},
vo: {
name: 'Volapük',
nativeName: 'Volapük',
},
wa: {
name: 'Walloon',
nativeName: 'walon',
},
wo: {
name: 'Wolof',
nativeName: 'Wollof',
},
xh: {
name: 'Xhosa',
nativeName: 'isiXhosa',
},
yi: {
name: 'Yiddish',
nativeName: 'ייִדיש',
},
yo: {
name: 'Yoruba',
nativeName: 'Yorùbá',
},
za: {
name: 'Zhuang',
nativeName: 'Saɯ cueŋƅ',
},
zh: {
name: 'Chinese',
nativeName: '中文',
},
zu: {
name: 'Zulu',
nativeName: 'isiZulu',
},
};
module.exports = LANGUAGES_LIST;
+59
View File
@@ -0,0 +1,59 @@
const LANGUAGES_LIST = require('./data.js');
const LANGUAGES = {};
const LANGUAGES_BY_NAME = {};
const LANGUAGE_CODES = [];
const LANGUAGE_NAMES = [];
const LANGUAGE_NATIVE_NAMES = [];
for (const code in LANGUAGES_LIST) {
const { name, nativeName } = LANGUAGES_LIST[code];
LANGUAGES[code] =
LANGUAGES_BY_NAME[name.toLowerCase()] =
LANGUAGES_BY_NAME[nativeName.toLowerCase()] =
{ code, name, nativeName };
LANGUAGE_CODES.push(code);
LANGUAGE_NAMES.push(name);
LANGUAGE_NATIVE_NAMES.push(nativeName);
}
module.exports = class ISO6391 {
static getLanguages(codes = []) {
return codes.map(code =>
ISO6391.validate(code)
? Object.assign({}, LANGUAGES[code])
: { code, name: '', nativeName: '' }
);
}
static getName(code) {
return ISO6391.validate(code) ? LANGUAGES_LIST[code].name : '';
}
static getAllNames() {
return LANGUAGE_NAMES.slice();
}
static getNativeName(code) {
return ISO6391.validate(code) ? LANGUAGES_LIST[code].nativeName : '';
}
static getAllNativeNames() {
return LANGUAGE_NATIVE_NAMES.slice();
}
static getCode(name) {
name = name.toLowerCase();
return LANGUAGES_BY_NAME.hasOwnProperty(name)
? LANGUAGES_BY_NAME[name].code
: '';
}
static getAllCodes() {
return LANGUAGE_CODES.slice();
}
static validate(code) {
return LANGUAGES_LIST.hasOwnProperty(code);
}
}
+193
View File
@@ -0,0 +1,193 @@
const assert = require('assert');
const ISO6391 = require('../src/index');
describe('getName()', function() {
it('en', function() {
assert.equal(ISO6391.getName('en'), 'English');
});
it('zh', function() {
assert.equal(ISO6391.getName('zh'), 'Chinese');
});
it('xx', function() {
assert.equal(ISO6391.getName('xx'), '');
});
it('toString', function() {
assert.equal(ISO6391.getName('toString'), '');
});
});
describe('getAllNames()', function() {
it('should return an array', function() {
assert.ok(Array.isArray(ISO6391.getAllNames()));
});
it('should return an array of strings', function() {
const names = ISO6391.getAllNames();
assert.ok(names.every(name => typeof name === 'string'));
});
it('should return all language names', function() {
const allNamesFromData = Object.values(require('../src/data')).map(lang => lang.name);
assert.deepEqual(ISO6391.getAllNames().sort(), allNamesFromData.sort());
});
it('should return a copy of the names array', function() {
const names1 = ISO6391.getAllNames();
const names2 = ISO6391.getAllNames();
assert.notStrictEqual(names1, names2);
});
});
describe('getAllNativeNames()', function() {
it('should return an array', function() {
assert.ok(Array.isArray(ISO6391.getAllNativeNames()));
});
it('should return an array of strings', function() {
const nativeNames = ISO6391.getAllNativeNames();
assert.ok(nativeNames.every(nativeName => typeof nativeName === 'string'));
});
it('should return all language native names', function() {
const allNativeNamesFromData = Object.values(require('../src/data')).map(lang => lang.nativeName);
assert.deepEqual(ISO6391.getAllNativeNames().sort(), allNativeNamesFromData.sort());
});
it('should return a copy of the native names array', function() {
const nativeNames1 = ISO6391.getAllNativeNames();
const nativeNames2 = ISO6391.getAllNativeNames();
assert.notStrictEqual(nativeNames1, nativeNames2);
});
});
describe('getAllCodes()', function() {
it('should return an array', function() {
assert.ok(Array.isArray(ISO6391.getAllCodes()));
});
it('should return an array of strings', function() {
const codes = ISO6391.getAllCodes();
assert.ok(codes.every(code => typeof code === 'string'));
});
it('should return all language codes', function() {
const allCodesFromData = Object.keys(require('../src/data'));
assert.deepEqual(ISO6391.getAllCodes().sort(), allCodesFromData.sort());
});
it('should return a copy of the codes array', function() {
const codes1 = ISO6391.getAllCodes();
const codes2 = ISO6391.getAllCodes();
assert.notStrictEqual(codes1, codes2);
});
});
describe('getNativeName()', function() {
it('en', function() {
assert.equal(ISO6391.getNativeName('en'), 'English');
});
it('zh', function() {
assert.equal(ISO6391.getNativeName('zh'), '中文');
});
it('xx', function() {
assert.equal(ISO6391.getNativeName('xx'), '');
});
it('toString', function() {
assert.equal(ISO6391.getNativeName('toString'), '');
});
});
describe('getCode()', function() {
it('English', function() {
assert.equal(ISO6391.getCode('English'), 'en');
});
it('Chinese', function() {
assert.equal(ISO6391.getCode('Chinese'), 'zh');
});
it('中文', function() {
assert.equal(ISO6391.getCode('中文'), 'zh');
});
it('xx', function() {
assert.equal(ISO6391.getCode('xx'), '');
});
it('toString', function() {
assert.equal(ISO6391.getCode('toString'), '');
});
});
describe('validate()', function() {
it('en', function() {
assert.equal(ISO6391.validate('en'), true);
});
it('zh', function() {
assert.equal(ISO6391.validate('zh'), true);
});
it('xx', function() {
assert.equal(ISO6391.validate('xx'), false);
});
it('toString', function() {
assert.equal(ISO6391.validate('toString'), false);
});
});
describe('getLanguages()', function() {
it('[en, zh, xx, toString]', function() {
assert.deepEqual(ISO6391.getLanguages(['en', 'zh', 'xx', 'toString']), [
{
code: 'en',
name: 'English',
nativeName: 'English',
},
{
code: 'zh',
name: 'Chinese',
nativeName: '中文',
},
{
code: 'xx',
name: '',
nativeName: '',
},
{
code: 'toString',
name: '',
nativeName: '',
},
]);
});
it('should return an empty array when given an empty array', function() {
assert.deepEqual(ISO6391.getLanguages([]), []);
});
it('should return an array of all languages when given all valid codes', function() {
const allCodes = Object.keys(require('../src/data'));
const expectedLanguages = allCodes.map(code => ({
code,
name: ISO6391.getName(code),
nativeName: ISO6391.getNativeName(code),
}));
assert.deepEqual(ISO6391.getLanguages(allCodes), expectedLanguages);
});
it('should return an array of empty language objects when given all invalid codes', function() {
const invalidCodes = ['xx', 'yy', 'zz'];
const expectedLanguages = invalidCodes.map(code => ({
code,
name: '',
nativeName: '',
}));
assert.deepEqual(ISO6391.getLanguages(invalidCodes), expectedLanguages);
});
it('should return a new array with new objects', function() {
const codes = ['en', 'zh'];
const languages1 = ISO6391.getLanguages(codes);
const languages2 = ISO6391.getLanguages(codes);
assert.notStrictEqual(languages1, languages2);
languages1.forEach((lang, index) => {
assert.notStrictEqual(lang, languages2[index]);
});
});
});
+20
View File
@@ -0,0 +1,20 @@
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
// webpack configuration
let webpackConfig = {
mode: 'production',
entry: {
index: './src/index.js',
},
output: {
path: path.resolve(__dirname, `./build`),
filename: '[name].js',
library: 'ISO6391',
},
plugins: [
new CleanWebpackPlugin(),
],
};
module.exports = webpackConfig;