blob: d4e47062b2be465f45cc1cf34bb6493afcff4bb5 [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001/*!
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};