All files / libs/fs ospath.js

100% Statements 14/14
100% Branches 10/10
100% Functions 4/4
100% Lines 13/13
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 44 45 46 47 48 49 50 51 52 53 54                    9x 9x     4x 1x 1x 2x             3x         18x                 3x 1x 2x       9x               9x  
/**
 *
 * @module      libs/fs/ospath
 * @createdAt   2017-07-14
 *
 * @copyright   Copyright (c) 2017 Zhonglei Qiu
 * @license     Licensed under the MIT license.
 * @see         https://github.com/jprichardson/ospath/blob/1.2.2/index.js
 */
 
var path = require('path')
var os = require('os')
 
function data() {
  switch (this.__platform || /* istanbul ignore next */ process.platform) {
    case 'win32': return path.resolve(process.env.APPDATA)
    case 'darwin': return path.resolve(path.join(home.call(this), 'Library/Application Support/'))
    default: return process.env.XDG_CONFIG_HOME
      ? path.resolve(process.env.XDG_CONFIG_HOME)
      : path.resolve(path.join(home.call(this), '.config/'))
  }
}
 
function desktop() {
  return path.join(home.call(this), 'Desktop')
}
 
function home() {
  /* istanbul ignore else */
  if ('homedir' in os) return os.homedir() // io.js >= 2.3
  /* istanbul ignore next */
  switch (this.__platform || process.platform) {
    case 'win32': return path.resolve(process.env.USERPROFILE)
    default: return path.resolve(process.env.HOME)
  }
}
 
function tmp() {
  switch (this.__platform || /* istanbul ignore next */ process.platform) {
    case 'win32': return path.resolve(process.env.TEMP)
    default: return path.resolve('/tmp')
  }
}
 
var ospath = {
  __platform: process.platform,
  data: data,
  desktop: desktop,
  home: home,
  tmp: tmp
}
 
module.exports = ospath