Gets the home dir or resolves home directories.
A tiny utility to get the home directory, or resolve a path begins with
'~', with cross-platform compatibility.
$ npm install home --save
var home = ;; // Mac && Linux: '/Users/kael', Windows: '\\Users\\kael'home; // '/Users/kael'var some_path = '~/workspace';home; // '/Users/kael/workspace'home; // '/Users/kael/workspace/abc'
path the home directory specified by operating system.
to to an absolute path, if
to begins with
'~', it will be cooked before
home; // 'Users/kael/file'
The usage of
home.resolve is very similar to
Another way to think of it is as a sequence of cd commands in a shell.
home;// -> current directoryhome;// -> '/Users/kael/subfile'
Is equivalent to:
Is similar to:
cd foo/barcd ~/file/cd ..cd a/../subfilepwd
home doesn't support those, which I thought is unnecessary to make this module too complicated.
home.resolve() the directories, before
var dir = '~/dir';dir = home;path;
May be freely distributed under the MIT license.
Copyright (c) Kael Zhang and other contributors.