Skip to content

Commit

Permalink
Close #4 PR: strict replace, fix #3.
Browse files Browse the repository at this point in the history
  • Loading branch information
fritx authored and sindresorhus committed Sep 18, 2015
1 parent a12dc61 commit 58a3a2c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.js
@@ -1,7 +1,11 @@
'use strict';
var path = require('path');
var osHomedir = require('os-homedir');
var home = osHomedir();

module.exports = function (str) {
return str.replace(home, '~');
str += path.sep;
str = str.replace(home + path.sep, '~' + path.sep);
str = str.slice(0, -1);
return str;
};
12 changes: 12 additions & 0 deletions test.js
Expand Up @@ -5,10 +5,22 @@ var path = require('path');
var osHomedir = require('os-homedir');
var home = osHomedir();

test(function (t) {
var fixture = home;
t.assert(tildify(fixture) === '~');
t.end();
});

test(function (t) {
var fixture = path.resolve(home, 'tildify');
t.assert(tildify(fixture)[0] === '~');
t.assert(/tildify$/.test(tildify(fixture)));
t.assert(tildify(fixture) !== fixture);
t.end();
});

test(function (t) {
var fixture = path.resolve(home + 'foo', 'tildify');
t.assert(tildify(fixture) === fixture);
t.end();
});

0 comments on commit 58a3a2c

Please sign in to comment.