-
Notifications
You must be signed in to change notification settings - Fork 0
/
iso.ts
42 lines (33 loc) · 1.47 KB
/
iso.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { iso6391X, type LanguageCode, type LanguageOption } from '../src/index.js';
// => en
console.log(iso6391X.getCode('english') as string);
// => ['aa', 'ab', ... 199 more items]
console.log(iso6391X.getAllCodes() as LanguageCode[]);
// => English
console.log(iso6391X.getName('en') as string);
// => ['Afar', 'Abkhaz', ... 199 more items]
console.log(iso6391X.getAllNames() as string[]);
// => 中文
console.log(iso6391X.getNativeName('zh') as string);
// => ['Afaraf', 'аҧсуа бызшәа', ... 199 more items]
console.log(iso6391X.getAllNativeNames() as string[]);
// => [
// { code: 'en', name: 'English', nativeName: 'English' },
// { code: 'zh', name: 'Chinese', nativeName: '中文' },
// { code: 'fr', name: 'French', nativeName: 'Français' },
// { code: 'de', name: 'German', nativeName: 'Deutsch' },
// { code: 'it', name: 'Italian', nativeName: 'Italiano' },
// { code: 'ja', name: 'Japanese', nativeName: '日本語' },
// { code: 'es', name: 'Spanish', nativeName: 'Español' },
// { code: 'zh-cn', name: 'Chinese (Simplified)', nativeName: '简体中文' }
// ]
console.log(iso6391X.getAllDetections() as LanguageOption[]);
// => [
// { code: 'en', name: 'English', nativeName: 'English' },
// { code: 'zh', name: 'Chinese', nativeName: '中文' },
// ]
console.log(iso6391X.getLanguages(['en', 'zh']) as LanguageOption[]);
// => true
console.log(iso6391X.validate('en') as boolean);
// => false
console.log(iso6391X.validate('english') as boolean);