expand-tilde
Advanced tools
Comparing version 1.2.0 to 1.2.1
17
index.js
@@ -9,12 +9,15 @@ /*! | ||
var path = require('path'); | ||
var userhome = require('user-home'); | ||
var homedir = require('os-homedir'); | ||
module.exports = function expandTilde(fp) { | ||
if (fp.charCodeAt(0) === 126 /* ~ */) { | ||
if (fp.charCodeAt(1) === 43 /* + */) { | ||
return path.join(process.cwd(), fp.slice(2)); | ||
module.exports = function expandTilde(filepath) { | ||
var home = homedir(); | ||
if (filepath.charCodeAt(0) === 126 /* ~ */) { | ||
if (filepath.charCodeAt(1) === 43 /* + */) { | ||
return path.join(process.cwd(), filepath.slice(2)); | ||
} | ||
return userhome ? path.join(userhome, fp.slice(1)) : fp; | ||
return home ? path.join(home, filepath.slice(1)) : filepath; | ||
} | ||
return fp; | ||
return filepath; | ||
}; |
{ | ||
"name": "expand-tilde", | ||
"description": "Bash-like tilde expansion for node.js. Expands a leading tilde in a file path to the user home directory, or `~+` to the cwd.", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"homepage": "https://github.com/jonschlinkert/expand-tilde", | ||
"author": { | ||
"name": "Jon Schlinkert", | ||
"url": "https://github.com/jonschlinkert" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/jonschlinkert/expand-tilde.git" | ||
}, | ||
"author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"repository": "jonschlinkert/expand-tilde", | ||
"bugs": { | ||
"url": "https://github.com/jonschlinkert/expand-tilde/issues" | ||
}, | ||
"license": { | ||
"type": "MIT", | ||
"url": "https://github.com/jonschlinkert/expand-tilde/blob/master/LICENSE" | ||
}, | ||
"license": "MIT", | ||
"files": [ | ||
"index.js" | ||
], | ||
"main": "index.js", | ||
@@ -26,9 +20,11 @@ "engines": { | ||
"scripts": { | ||
"test": "mocha -R spec" | ||
"test": "mocha" | ||
}, | ||
"dependencies": { | ||
"user-home": "^1.1.1" | ||
"os-homedir": "^1.0.1" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*" | ||
"gulp-format-md": "^0.1.7", | ||
"is-windows": "^0.1.1", | ||
"mocha": "^2.4.5" | ||
}, | ||
@@ -46,3 +42,28 @@ "keywords": [ | ||
"userhome" | ||
] | ||
], | ||
"verb": { | ||
"run": true, | ||
"toc": false, | ||
"layout": "default", | ||
"tasks": [ | ||
"readme" | ||
], | ||
"plugins": [ | ||
"gulp-format-md" | ||
], | ||
"related": { | ||
"list": [ | ||
"micromatch", | ||
"braces", | ||
"expand-brackets", | ||
"is-glob" | ||
] | ||
}, | ||
"reflinks": [ | ||
"verb" | ||
], | ||
"lint": { | ||
"reflinks": true | ||
} | ||
} | ||
} |
@@ -1,15 +0,17 @@ | ||
# expand-tilde [![NPM version](https://badge.fury.io/js/expand-tilde.svg)](http://badge.fury.io/js/expand-tilde) | ||
# expand-tilde [![NPM version](https://img.shields.io/npm/v/expand-tilde.svg?style=flat)](https://www.npmjs.com/package/expand-tilde) [![NPM downloads](https://img.shields.io/npm/dm/expand-tilde.svg?style=flat)](https://npmjs.org/package/expand-tilde) [![Build Status](https://img.shields.io/travis/jonschlinkert/expand-tilde.svg?style=flat)](https://travis-ci.org/jonschlinkert/expand-tilde) | ||
> Bash-like tilde expansion for node.js. Expands a leading tilde in a file path to the user home directory, or `~+` to the cwd. | ||
## Install with [npm](npmjs.org) | ||
## Install | ||
```bash | ||
npm i expand-tilde --save | ||
Install with [npm](https://www.npmjs.com/): | ||
```sh | ||
$ npm install expand-tilde --save | ||
``` | ||
See the [Bash documentation for Tilde Expansion][docs]. | ||
## Usage | ||
See the [Bash documentation for Tilde Expansion](https://www.gnu.org/software/bash/manual/html_node/Tilde-Expansion.html). | ||
```js | ||
@@ -33,25 +35,51 @@ var expandTilde = require('expand-tilde'); | ||
## Related | ||
## Related projects | ||
- [braces](https://github.com/jonschlinkert/braces): Bash-like brace expansion for node.js | ||
- [tildify](https://github.com/sindresorhus/tildify): converts file paths to tildes | ||
You might also be interested in these projects: | ||
* [braces](https://www.npmjs.com/package/braces): Fastest brace expansion for node.js, with the most complete support for the Bash 4.3 braces… [more](https://www.npmjs.com/package/braces) | [homepage](https://github.com/jonschlinkert/braces) | ||
* [expand-brackets](https://www.npmjs.com/package/expand-brackets): Expand POSIX bracket expressions (character classes) in glob patterns. | [homepage](https://github.com/jonschlinkert/expand-brackets) | ||
* [is-glob](https://www.npmjs.com/package/is-glob): Returns `true` if the given string looks like a glob pattern or an extglob pattern.… [more](https://www.npmjs.com/package/is-glob) | [homepage](https://github.com/jonschlinkert/is-glob) | ||
* [micromatch](https://www.npmjs.com/package/micromatch): Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. Just… [more](https://www.npmjs.com/package/micromatch) | [homepage](https://github.com/jonschlinkert/micromatch) | ||
## Contributing | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/expand-tilde/issues) | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/expand-tilde/issues/new). | ||
## Building docs | ||
Generate readme and API documentation with [verb](https://github.com/verbose/verb): | ||
```sh | ||
$ npm install verb && npm run docs | ||
``` | ||
Or, if [verb](https://github.com/verbose/verb) is installed globally: | ||
```sh | ||
$ verb | ||
``` | ||
## Running tests | ||
Install dev dependencies: | ||
```sh | ||
$ npm install -d && npm test | ||
``` | ||
## Author | ||
**Jon Schlinkert** | ||
+ [github/jonschlinkert](https://github.com/jonschlinkert) | ||
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
* [github/jonschlinkert](https://github.com/jonschlinkert) | ||
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
## License | ||
Copyright (c) 2015 Jon Schlinkert | ||
Released under the MIT license | ||
Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert). | ||
Released under the [MIT license](https://github.com/jonschlinkert/expand-tilde/blob/master/LICENSE). | ||
*** | ||
_This file was generated by [verb](https://github.com/assemble/verb) on January 21, 2015._ | ||
[docs]: https://www.gnu.org/software/bash/manual/html_node/Tilde-Expansion.html | ||
_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on April 07, 2016._ |
Sorry, the diff of this file is not supported yet
5885
18
84
3
+ Addedos-homedir@^1.0.1
+ Addedos-homedir@1.0.2(transitive)
- Removeduser-home@^1.1.1
- Removeduser-home@1.1.1(transitive)