New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

home

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

home - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

12

package.json
{
"name": "home",
"version": "0.1.0",
"description": "home",
"version": "0.1.1",
"description": "Gets the home dir or resolves home directories: `home.resolve('~/path/to')`.",
"main": "index.js",

@@ -14,6 +14,10 @@ "scripts": {

"keywords": [
"home"
"home",
"user-home",
"resolve",
"cross-platform",
"windows"
],
"engines": {
"node": ">=0.11.0"
"node": ">=0.10.0"
},

@@ -20,0 +24,0 @@ "author": "kaelzhang",

# home [![NPM version](https://badge.fury.io/js/home.svg)](http://badge.fury.io/js/home) [![Build Status](https://travis-ci.org/kaelzhang/node-home.svg?branch=master)](https://travis-ci.org/kaelzhang/node-home) [![Dependency Status](https://gemnasium.com/kaelzhang/node-home.svg)](https://gemnasium.com/kaelzhang/node-home)
<!-- description -->
A tiny utility to get the home directory, or resolve a path begins with `'~'`, with cross-platform compatibility.

@@ -15,6 +15,63 @@ ## Install

var home = require('home');
home(); // '/Users/kael'
var some_path = '~/workspace';
home.resolve(some_path); // '/Users/kael/workspace'
home.resolve(some_path, 'abc'); // '/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.
```js
home.resolve('~/file'); // 'Users/kael/file'
```
The usage of `home.resolve` is very similar to [`path.resolve`](http://nodejs.org/api/path.html#path_path_resolve_from_to)
Another way to think of it is as a sequence of cd commands in a shell.
```js
home.resolve('foo/bar', '~/file/', '..', 'a/../subfile');
// -> '/Users/kael/subfile'
```
Is equivalent to:
```js
home.resolve('foo/bar', '/Users/kael/file/', '..', 'a/../subfile');
```
Is similar to:
```sh
cd foo/bar
cd ~/file/
cd ..
cd a/../subfile
pwd
```
## What about `home.relative()`, `home.join()` ?
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
```js
var dir = '~/dir';
dir = home.resolve(dir);
path.join(dir, './abc');
```
## License
MIT
May be freely distributed under the [MIT license](https://raw.githubusercontent.com/kaelzhang/node-home/master/LICENSE-MIT).
Copyright (c) Kael Zhang and [other contributors](https://github.com/kaelzhang/node-home/graphs/contributors).
'use strict';
var expect = require('chai').expect;
var home = require('../');
var home = require('../');
// Node.js test cases from https://github.com/joyent/node/blob/master/test/simple/test-path.js
var isWindows = process.platform === 'win32';
if (isWindows) {
// windows
var resolveTests =
// arguments result
[
[
['c:/blah\\blah', 'd:/games', 'c:../a'], 'c:\\blah\\a'
],
[
['c:/ignore', 'd:\\a/b\\c/d', '\\e.exe'], 'd:\\e.exe'
],
[
['c:/ignore', 'c:/some/file'], 'c:\\some\\file'
],
[
['d:/ignore', 'd:some/dir//'], 'd:\\ignore\\some\\dir'
],
[
['.'], process.cwd()
],
[
['//server/share', '..', 'relative\\'], '\\\\server\\share\\relative'
],
[
['c:/', '//'], 'c:\\'
],
[
['c:/', '//dir'], 'c:\\dir'
],
[
['c:/', '//server/share'], '\\\\server\\share\\'
],
[
['c:/', '//server//share'], '\\\\server\\share\\'
],
[
['c:/', '///some//dir'], 'c:\\some\\dir'
]
];
} else {
// Posix
var resolveTests =
// arguments result
[
[
['/var/lib', '../', 'file/'], '/var/file'
],
[
['/var/lib', '/../', 'file/'], '/file'
],
[
['a/b/c/', '../../..'], process.cwd()
],
[
['.'], process.cwd()
],
[
['/some/dir', '.', '/absolute/'], '/absolute'
]
];
}
// var home = require('path')
var resolve = home.resolve;
describe("home.resolve(), with no '~' path:", function(){
resolveTests.forEach(function (c) {
var args = c[0];
var result = c[1];
it(
'normal: ' + args.map(JSON.stringify).join(', ')
+ ' -> ' + JSON.stringify(result), function(){
expect(resolve.apply(home, args)).to.equal(result);
});
});
});
if (isWindows) {
var HOME = process.env.USERPROFILE;
// windows
var homeResolveTests =
// arguments result
[
[
['~'], HOME
],
[
['c:/blah\\blah', 'd:/games', 'c:../a'], 'c:\\blah\\a'
],
[
['c:/ignore', 'd:\\a/b\\c/d', '\\e.exe'], 'd:\\e.exe'
],
[
['c:/ignore', 'c:/some/file'], 'c:\\some\\file'
],
[
['d:/ignore', 'd:some/dir//'], 'd:\\ignore\\some\\dir'
],
[
['.'], process.cwd()
],
[
['//server/share', '..', 'relative\\'], '\\\\server\\share\\relative'
],
[
['c:/', '//'], 'c:\\'
],
[
['c:/', '//dir'], 'c:\\dir'
],
[
['c:/', '//server/share'], '\\\\server\\share\\'
],
[
['c:/', '//server//share'], '\\\\server\\share\\'
],
[
['c:/', '///some//dir'], 'c:\\some\\dir'
]
];
} else {
var HOME = process.env.HOME;
// Posix
var homeResolveTests =
// arguments result
[
[
['~'], HOME
],
[
['~/var/lib', '../', 'file/'], HOME + '/var/file'
],
[
['~/var/lib', '/../', 'file/'], '/file'
],
[
['~/some/dir', '.', '~/absolute/'], HOME + '/absolute'
],
[
['~/some/dir', '.', '/absolute/'], '/absolute'
]
];
}
describe("home():", function(){
it("home(), should return home dir", function(){
expect(home()).to.equal(HOME);
});
});
describe("home.resolve(), with '~' path:", function(){
homeResolveTests.forEach(function (c, i) { console.log(c, i)
var args = c[0];
var result = c[1];
it(args.map(JSON.stringify).join(', ') + ' -> ' + JSON.stringify(result), function(){
expect(resolve.apply(home, args)).to.equal(result);
});
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc