import * as path from 'path' ; import { IPathUtils } from '../types' ; import { NON_WINDOWS_PATH_VARIABLE_NAME , WINDOWS_PATH_VARIABLE_NAME } from './constants' ; import { homedir } from 'os' ; export class PathUtils implements IPathUtils { public readonly home : string ; constructor ( private isWindows ) { this . home = homedir ( ) ; } public get delimiter ( ) : string { return path . delimiter ; } public get separator ( ) : string { return path . sep ; } public getPathVariableName ( ) { return this . isWindows ? WINDOWS_PATH_VARIABLE_NAME : NON_WINDOWS_PATH_VARIABLE_NAME ; } public basename ( pathValue , ext ? ) { return path . basename ( pathValue , ext ) ; } public getDisplayName ( pathValue , cwd ? ) { if ( cwd && pathValue . startsWith ( cwd ) ) { return `.${ path . sep }${ path . relative ( cwd , pathValue ) }` ; } else if ( pathValue . startsWith ( this . home ) ) { return `~${ path . sep }${ path . relative ( this . home , pathValue ) }` ; } else { return pathValue ; } } }