From 6f207fdf4f8ff30db6ae985b511a62ef4f307410 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Fri, 18 Sep 2015 14:13:36 +0700 Subject: [PATCH] cleanup #4 --- index.js | 6 ++---- test.js | 6 +++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 9c8c24f..68871c2 100644 --- a/index.js +++ b/index.js @@ -4,8 +4,6 @@ var osHomedir = require('os-homedir'); var home = osHomedir(); module.exports = function (str) { - str += path.sep; - str = str.replace(home + path.sep, '~' + path.sep); - str = str.slice(0, -1); - return str; + str = path.resolve(str) + path.sep; + return str.replace(home + path.sep, '~' + path.sep).slice(0, -1); }; diff --git a/test.js b/test.js index 42d783f..682d46f 100644 --- a/test.js +++ b/test.js @@ -5,13 +5,13 @@ var path = require('path'); var osHomedir = require('os-homedir'); var home = osHomedir(); -test(function (t) { +test('tildify home', function (t) { var fixture = home; t.assert(tildify(fixture) === '~'); t.end(); }); -test(function (t) { +test('tildify path', function (t) { var fixture = path.resolve(home, 'tildify'); t.assert(tildify(fixture)[0] === '~'); t.assert(/tildify$/.test(tildify(fixture))); @@ -19,7 +19,7 @@ test(function (t) { t.end(); }); -test(function (t) { +test('ensure only a fully matching path is replaced', function (t) { var fixture = path.resolve(home + 'foo', 'tildify'); t.assert(tildify(fixture) === fixture); t.end();