-
Notifications
You must be signed in to change notification settings - Fork 0
/
framework.js
37 lines (31 loc) · 1.02 KB
/
framework.js
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
const fs = require('fs');
const zlib = require('zlib');
const { join } = require('path');
const { inspect } = require('util');
const { CLDRFramework } = require('@phensley/cldr');
exports.dump = (o) => inspect(o, true, undefined, true);
const framework = new CLDRFramework({
loader: (lang) => {
const path = join(__dirname, `node_modules/@phensley/cldr/packs/${lang}.json.gz`);
const compressed = fs.readFileSync(path);
return zlib.gunzipSync(compressed).toString('utf-8');
}
});
// Use our lib to format numbers for display
const cldr = framework.get('en');
// const MEGABYTE = 1024 * 1024;
// const KILOBYTE = 1024;
// exports.datasize = (n) => {
// if (n >= MEGABYTE) {
// n /= MEGABYTE;
// unit = 'megabyte';
// } else if (n >= KILOBYTE) {
// n /= KILOBYTE;
// unit = 'kilobyte';
// } else {
// unit = 'byte';
// }
// return cldr.Units.formatQuantity(
// { value: n, unit }, { length: 'short', minimumFractionDigits: 2});
// };
exports.decimal = (n) => cldr.Numbers.formatDecimal(n);