Comparing version 1.0.1 to 2.0.0
67
index.js
@@ -1,60 +0,23 @@ | ||
'use strict'; | ||
module.exports = home; | ||
const {resolve} = require('path') | ||
var USER_HOME = require('os-homedir')(); | ||
const USER_HOME = require('os').homedir() | ||
function home () { | ||
return USER_HOME; | ||
return USER_HOME | ||
} | ||
var node_path = require('path'); | ||
const resolveHome = path => | ||
path === '~' | ||
? USER_HOME | ||
// I thought, nobody will use `'~\\path\\to'`, but only `'~/path/to'` | ||
: !~ path.indexOf('~/') | ||
// '~file' | ||
? path | ||
// '~/file' -> '/Users/xxx/file' | ||
: USER_HOME + path.slice(1) | ||
var resolve = node_path.resolve; | ||
// The enhanced `path.resolve` | ||
home.resolve = function (/* [from,] */ to) { | ||
switch(arguments.length){ | ||
case 0: | ||
return resolve(); | ||
case 1: | ||
return resolve(resolve_home(to)); | ||
case 2: | ||
return resolve(resolve_home(to), resolve_home(arguments[1])); | ||
default: | ||
// Actually, `node_path.resolve` has no `this` pointer, | ||
// however, we apply it to `node_path` | ||
return resolve.apply(node_path, map_resolve(arguments)); | ||
} | ||
}; | ||
home.resolve = (...args) => resolve(...args.map(resolveHome)) | ||
function resolve_home (path) { | ||
if (!path) { | ||
// Actually, it will lead to an TypeError of `path.resolve` | ||
return path; | ||
} | ||
if (path === '~') { | ||
return USER_HOME; | ||
} | ||
// I thought, nobody will use `'~\\path\\to'`, but only `'~/path/to'` | ||
if (!~path.indexOf('~/')) { | ||
// '~file' | ||
return path; | ||
} | ||
// '~/file' -> '/Users/xxx/file' | ||
return USER_HOME + path.slice(1); | ||
} | ||
function map_resolve (args) { | ||
var paths = []; | ||
var length = args.length; | ||
while(length --){ | ||
paths[length] = resolve_home(args[length]); | ||
} | ||
return paths; | ||
} | ||
module.exports = home |
{ | ||
"name": "home", | ||
"version": "1.0.1", | ||
"version": "2.0.0", | ||
"description": "Gets the home dir or resolves home directories.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "./node_modules/.bin/mocha --reporter spec ./test/*.js" | ||
"test": "nyc mocha --reporter spec ./test/*.js", | ||
"lint": "eslint .", | ||
"fix": "eslint . --fix", | ||
"posttest": "npm run report", | ||
"report": "nyc report --reporter=text-lcov > coverage.lcov && codecov" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"repository": { | ||
@@ -23,3 +30,3 @@ "type": "git", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=5.12.0" | ||
}, | ||
@@ -32,8 +39,10 @@ "author": "kaelzhang", | ||
"devDependencies": { | ||
"@ostai/eslint-config": "^3.0.0", | ||
"chai": "*", | ||
"codecov": "^3.3.0", | ||
"eslint": "^5.16.0", | ||
"eslint-plugin-import": "^2.17.2", | ||
"mocha": "*", | ||
"chai": "*" | ||
}, | ||
"dependencies": { | ||
"os-homedir": "^1.0.1" | ||
"nyc": "^14.1.0" | ||
} | ||
} |
@@ -0,1 +1,4 @@ | ||
[![Build Status](https://travis-ci.org/kaelzhang/node-home.svg?branch=master)](https://travis-ci.org/kaelzhang/node-home) | ||
[![Coverage](https://codecov.io/gh/kaelzhang/node-home/branch/master/graph/badge.svg)](https://codecov.io/gh/kaelzhang/node-home) | ||
# home | ||
@@ -5,5 +8,3 @@ | ||
[![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) | ||
Since `2.0.0`, `home only supports node >= 5.12.0` | ||
@@ -13,3 +14,3 @@ ## Install | ||
```sh | ||
$ npm install home --save | ||
$ npm i home | ||
``` | ||
@@ -20,10 +21,10 @@ | ||
```js | ||
var home = require('home'); | ||
const home = require('home') | ||
home(); // Mac && Linux: '/Users/kael', Windows: '\\Users\\kael' | ||
home.resolve('~'); // '/Users/kael' | ||
home() // Mac && Linux: '/Users/kael', Windows: '\\Users\\kael' | ||
home.resolve('~') // '/Users/kael' | ||
var some_path = '~/workspace'; | ||
home.resolve(some_path); // '/Users/kael/workspace' | ||
home.resolve(some_path, 'abc'); // '/Users/kael/workspace/abc' | ||
const some_path = '~/workspace' | ||
home.resolve(some_path) // '/Users/kael/workspace' | ||
home.resolve(some_path, 'abc') // '/Users/kael/workspace/abc' | ||
``` | ||
@@ -40,3 +41,3 @@ | ||
```js | ||
home.resolve('~/file'); // 'Users/kael/file' | ||
home.resolve('~/file') // 'Users/kael/file' | ||
``` | ||
@@ -49,6 +50,6 @@ | ||
```js | ||
home.resolve(); | ||
home.resolve() | ||
// -> current directory | ||
home.resolve('foo/bar', '~/file/', '..', 'a/../subfile'); | ||
home.resolve('foo/bar', '~/file/', '..', 'a/../subfile') | ||
// -> '/Users/kael/subfile' | ||
@@ -60,3 +61,3 @@ ``` | ||
```js | ||
home.resolve('foo/bar', '/Users/kael/file/', '..', 'a/../subfile'); | ||
home.resolve('foo/bar', '/Users/kael/file/', '..', 'a/../subfile') | ||
``` | ||
@@ -76,3 +77,3 @@ | ||
For now, `home` doesn't support those, which I thought is unnecessary to make this module too complicated. | ||
For now, `home` doesn't support those, which I thought is unnecessary to make this module too complicated. | ||
@@ -82,5 +83,5 @@ I'd rather `home.resolve()` the directories, before `path.join()`. | ||
```js | ||
var dir = '~/dir'; | ||
dir = home.resolve(dir); | ||
path.join(dir, './abc'); | ||
var dir = '~/dir' | ||
dir = home.resolve(dir) | ||
path.join(dir, './abc') | ||
``` | ||
@@ -90,4 +91,4 @@ | ||
May be freely distributed under the [MIT license](https://raw.githubusercontent.com/kaelzhang/node-home/master/LICENSE-MIT). | ||
May be freely distributed under the [MIT license](https://raw.githubusercontent.com/kaelzhang/node-home/master/LICENSE). | ||
Copyright (c) Kael Zhang and [other contributors](https://github.com/kaelzhang/node-home/graphs/contributors). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
0
86
0
4704
7
4
17
1
- Removedos-homedir@^1.0.1
- Removedos-homedir@1.0.2(transitive)