From 62d1720e7cb5e8a6d358a3517206dfebf9a833bb Mon Sep 17 00:00:00 2001 From: Wermeille Bastien Date: Wed, 16 Mar 2022 07:55:45 +0100 Subject: [PATCH] Refactor No need to compute `homedir` in every case. --- index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/index.js b/index.js index d4e4706..b710c4e 100644 --- a/index.js +++ b/index.js @@ -9,12 +9,11 @@ var homedir = require('homedir-polyfill'); var path = require('path'); module.exports = function expandTilde(filepath) { - var home = homedir(); - if (filepath.charCodeAt(0) === 126 /* ~ */) { if (filepath.charCodeAt(1) === 43 /* + */) { return path.join(process.cwd(), filepath.slice(2)); } + const home = homedir(); return home ? path.join(home, filepath.slice(1)) : filepath; }