UNPKG

549 BJavaScriptView Raw
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
8var homedir = require('homedir-polyfill');
9var path = require('path');
10
11module.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};