Total Complexity | 7 |
Complexity/F | 1.4 |
Lines of Code | 46 |
Function Count | 5 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | "use strict"; |
||
2 | |||
3 | import chalk from "chalk"; |
||
4 | import OS from "os"; |
||
5 | import settings from "./settings"; |
||
6 | import stripAnsi from "strip-ansi"; |
||
7 | |||
8 | /** |
||
9 | * figure out how many lines a string of text will use |
||
10 | * @param text |
||
11 | * @returns {number} |
||
12 | */ |
||
13 | function height(text: any): number { |
||
14 | // todo: text might include \n |
||
15 | return Math.ceil(ln(text) / process.stdout.columns); |
||
16 | } |
||
17 | |||
18 | function writeln(currentLine: number, text: string) { |
||
19 | currentLine += height(text); |
||
20 | write(text + OS.EOL); |
||
21 | return currentLine; |
||
22 | } |
||
23 | |||
24 | function write(text: string) { |
||
25 | if (settings.write) { |
||
26 | settings.write(text); |
||
27 | } |
||
28 | } |
||
29 | |||
30 | function ln(text: any) { |
||
31 | //return chalk.stripColor(text || '').length; |
||
32 | return stripAnsi(text || "").length; |
||
33 | } |
||
34 | |||
35 | function padding(n: number) { |
||
36 | return n > 0 ? new Array(n).join(" ") : ""; |
||
37 | } |
||
38 | |||
39 | export = { |
||
40 | height: height, |
||
41 | writeln: writeln, |
||
42 | write: write, |
||
43 | ln: ln, |
||
44 | padding: padding, |
||
45 | }; |
||
46 |