Completed
Push — master ( dce25d...9db7be )
by Dimas
09:29 queued 12s
created

libs/src/observatory/ts/out.ts   A

Complexity

Total Complexity 7
Complexity/F 1.4

Size

Lines of Code 46
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 33
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 7
mnd 2
bc 2
fnc 5
bpm 0.4
cpm 1.4
noi 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