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 = require'home';home; // Mac && Linux: '/Users/kael', Windows: '\\Users\\kael'homeresolve'~'; // '/Users/kael'var some_path = '~/workspace';homeresolvesome_path; // '/Users/kael/workspace'homeresolvesome_path 'abc'; // '/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
homeresolve'~/file'; // '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.
homeresolve;// -> current directoryhomeresolve'foo/bar' '~/file/' '..' 'a/../subfile';// -> '/Users/kael/subfile'
Is equivalent to:
homeresolve'foo/bar' '/Users/kael/file/' '..' 'a/../subfile';
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 = homeresolvedir;pathjoindir './abc';
May be freely distributed under the MIT license.
Copyright (c) Kael Zhang and other contributors.