home
A tiny utility to get the home directory, or resolve a path begins with '~'
, with cross-platform compatibility.
Since 2.0.0
, home only supports node >= 5.12.0
Install
$ npm i home
Usage
const home = // Mac && Linux: '/Users/kael', Windows: '\\Users\\kael'home // '/Users/kael' const some_path = '~/workspace'home // '/Users/kael/workspace'home // '/Users/kael/workspace/abc'
home()
Returns path
the home directory specified by operating system.
home.resolve([from...], to)
Resolves to
to an absolute path, if to
begins with '~'
, it will be cooked before path.resolve()
d.
home // 'Users/kael/file'
The usage of home.resolve
is very similar to path.resolve
Another way to think of it is as a sequence of cd commands in a shell.
home// -> current directory home// -> '/Users/kael/subfile'
Is equivalent to:
home
Is similar to:
cd foo/barcd ~/file/cd ..cd a/../subfilepwd
home.relative()
, home.join()
?
What about For now, home
doesn't support those, which I thought is unnecessary to make this module too complicated.
I'd rather home.resolve()
the directories, before path.join()
.
var dir = '~/dir'dir = homepath
License
May be freely distributed under the MIT license.
Copyright (c) Kael Zhang and other contributors.