All files DependencyPath.js

0% Statements 0/14
0% Branches 0/4
0% Functions 0/7
0% Lines 0/14
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                                                                                     
// @flow
 
const FILE_PATH_RE = /^file:(.+)/
const GIT_PATH_RE = /^git(.+)/
 
export default class DependencyPath {
  path: string
 
  constructor (path: string) {
    this.path = path
  }
 
  static fromString (strPath: string) {
    return new DependencyPath(strPath)
  }
 
  static fromFileSystemPath (fsPath: string) {
    return new DependencyPath(`file:${fsPath}`)
  }
 
  get isAFileSystemPath () : boolean {
    return FILE_PATH_RE.test(this.path)
  }
 
  get isAGitPath () : boolean {
    return GIT_PATH_RE.test(this.path)
  }
 
  get unprefixedPath () : string {
    let result = this.path
    if (this.isAFileSystemPath) {
      result = FILE_PATH_RE.exec(this.path)[1]
    } else if (this.isAGitPath) {
      result = GIT_PATH_RE.exec(this.path)[1]
    }
    return result
  }
 
  toString () : string {
    return this.path
  }
}