Completed
Push — master ( 9ab122...bd9e46 )
by greg
02:35
created

file.js ➔ getContent   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 5
c 2
b 1
f 0
nc 3
dl 0
loc 9
rs 8.8571
nop 1
1
import fse from 'fs-extra'
2
import path from 'path'
3
4
import {
5
  config
6
} from '../../'
7
8
export function exist(pathFile) {
9
  try{
10
    fse.statSync(pathFile)
11
    return true
12
  }catch(e){
13
    return false
14
  }
15
16
  return false
0 ignored issues
show
introduced by
This code is unreachable and can thus be removed without consequences.
Loading history...
17
}
18
19
export function changePath(pathEnv, change) {
20
  pathEnv = pathEnv.replace(config.root, '').replace(/^\//, '').split('/')
21
  pathEnv[0] = change
22
23
  return path.join(config.root, pathEnv.join('/'))
24
}
25
26
/**
27
 * This method checks that the path leads to a file and return the content as UTF-8 content
28
 * @param  {string} path The path
0 ignored issues
show
Documentation introduced by
The parameter path does not exist. Did you maybe forget to remove this comment?
Loading history...
29
 * @return {string}      The content of the UTF-8 file
30
 */
31
export function getContent(pathFile) {
32
  var res = null
33
  if(typeof pathFile !== 'undefined' && pathFile !== null && pathFile !== '') {
34
    if (exist(pathFile)) {
35
      res = fse.readFileSync(pathFile, 'utf8')
36
    }
37
  }
38
  return res
39
}