1
|
/*!
|
2
|
* expand-tilde <https://github.com/jonschlinkert/expand-tilde>
|
3
|
*
|
4
|
* Copyright (c) 2015 Jon Schlinkert.
|
5
|
* Licensed under the MIT license.
|
6
|
*/
|
7
|
|
8
|
var homedir = require('homedir-polyfill');
|
9
|
var path = require('path');
|
10
|
|
11
|
module.exports = function expandTilde(filepath) {
|
12
|
var home = homedir();
|
13
|
|
14
|
if (filepath.charCodeAt(0) === 126 /* ~ */) {
|
15
|
if (filepath.charCodeAt(1) === 43 /* + */) {
|
16
|
return path.join(process.cwd(), filepath.slice(2));
|
17
|
}
|
18
|
return home ? path.join(home, filepath.slice(1)) : filepath;
|
19
|
}
|
20
|
|
21
|
return filepath;
|
22
|
};
|