UNPKG

621 BJavaScriptView Raw
1'use strict';
2const invertKv = require('invert-kv');
3const all = require('./lcid.json');
4
5const inverted = invertKv(all);
6
7exports.from = lcidCode => {
8 if (typeof lcidCode !== 'number') {
9 throw new TypeError('Expected a number');
10 }
11
12 return all[lcidCode];
13};
14
15exports.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
26exports.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);