All files / lib/utils format.ts

52.63% Statements 10/19
0% Branches 0/5
0% Functions 0/3
55.56% Lines 10/18
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  1x 1x 1x 1x 1x 1x 1x 1x                       1x       1x        
import * as os from 'os';
import * as path from 'path';
 
import * as chalk from 'chalk';
 
export const ICON_SUCCESS = '✔';
export const ICON_FAILURE = '✖';
export const STRIP_ANSI_REGEX = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
 
export const ICON_SUCCESS_GREEN = chalk.green(ICON_SUCCESS);
export const ICON_FAILURE_RED = chalk.red(ICON_FAILURE);

export function prettyPath(p: string): string {
  const d = path.dirname(p);
  const h = os.homedir();

  if (process.cwd() === d) {
    return './' + path.basename(p);
  } else if (p.indexOf(h) === 0) {
    return '~/' + p.substring(h.length + 1);
  }

  return p;
}
 
export function indent(n: number = 4): string {
  return new Array(n).fill(' ').reduce((a, b) => a + b);
}