-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmillify
More file actions
executable file
·64 lines (62 loc) · 1.73 KB
/
millify
File metadata and controls
executable file
·64 lines (62 loc) · 1.73 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env node
const { millify } = require("../dist/millify");
require("yargs").command(
"$0 <number> [options]",
"Convert long numbers to pretty, human-readable strings",
(yargs) => {
return yargs
.positional("number", {
describe: "Value to convert",
type: "number",
})
.option("precision", {
describe: "Number of decimal places",
alias: "p",
type: "number",
default: 1,
})
.option("decimal", {
describe: "Decimal separator (mark)",
alias: "d",
type: "string",
default: ".",
})
.option("lowercase", {
describe: "Lowercase attributes",
alias: "l",
type: "boolean",
default: false,
})
.option("space", {
describe: "Space after value",
alias: "s",
type: "boolean",
default: false,
})
.option("unsafeInteger", {
describe: "Use unsafe integer",
alias: "U",
type: "boolean",
default: false,
})
.option("units", {
describe: "Unit abbreviatons",
alias: "u",
type: "string",
})
.example("$0 1000", "Run with default options")
.example("$0 15025 --precision 2", "Set precision value")
.example("$0 1000 --lowercase --space", "Lowercase and space set to true")
.example('$0 1000 --decimal=","', "Commas as decimal separator")
.example("$0 1000 -u B -u KB -u MB -u GB", "Specify units");
},
(argv) => {
const options = { ...argv, decimalSeparator: argv.d };
try {
// eslint-disable-next-line no-console
console.log(millify(argv.number, options));
} catch (e) {
console.error("ERR!", e.message);
}
}
).argv;