1 | 'use strict';
|
2 | const invertKv = require('invert-kv');
|
3 | const all = require('./lcid.json');
|
4 |
|
5 | const inverted = invertKv(all);
|
6 |
|
7 | exports.from = lcidCode => {
|
8 | if (typeof lcidCode !== 'number') {
|
9 | throw new TypeError('Expected a number');
|
10 | }
|
11 |
|
12 | return all[lcidCode];
|
13 | };
|
14 |
|
15 | exports.to = localeId => {
|
16 | if (typeof localeId !== 'string') {
|
17 | throw new TypeError('Expected a string');
|
18 | }
|
19 |
|
20 | const lcidCode = inverted[localeId];
|
21 | if (lcidCode) {
|
22 | return Number(inverted[localeId]);
|
23 | }
|
24 | };
|
25 |
|
26 | exports.all = new Proxy(
|
27 | inverted,
|
28 | {
|
29 | get(target, name) {
|
30 | const lcid = target[name];
|
31 | if (lcid) {
|
32 | return Number(lcid);
|
33 | }
|
34 | }
|
35 | }
|
36 | );
|