https://github.com/gulpjs/replace-homedir
Replace user home in a string with another string. Useful for tildifying a path.
https://github.com/gulpjs/replace-homedir
Last synced: 8 months ago
JSON representation
Replace user home in a string with another string. Useful for tildifying a path.
- Host: GitHub
- URL: https://github.com/gulpjs/replace-homedir
- Owner: gulpjs
- License: mit
- Created: 2017-12-06T22:34:07.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-01-31T00:10:17.000Z (over 4 years ago)
- Last Synced: 2024-10-29T15:14:42.130Z (over 1 year ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 4
- Watchers: 5
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# replace-homedir
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][ci-image]][ci-url] [![Coveralls Status][coveralls-image]][coveralls-url]
Replace user home in a string with another string. Useful for tildifying a path.
## Usage
```js
var replaceHomedir = require('replace-homedir');
var shortPath = replaceHomedir('/Users/phated/myProject', '~');
// shortPath === '~/myProject'
```
## API
### `replaceHomedir(path, replacement)`
Takes a string `path` as the first argument and a string or function `replacement` as the second argument. If the `path` is absolute and begins with the User's homedir, the homedir portion of the path is replaced with `replacement` using String#replace.
If `path` is not a string, the function will throw.
## License
MIT
[downloads-image]: https://img.shields.io/npm/dm/replace-homedir.svg?style=flat-square
[npm-url]: https://www.npmjs.com/package/replace-homedir
[npm-image]: https://img.shields.io/npm/v/replace-homedir.svg?style=flat-square
[ci-url]: https://github.com/gulpjs/replace-homedir/actions?query=workflow:dev
[ci-image]: https://img.shields.io/github/workflow/status/gulpjs/replace-homedir/dev?style=flat-square
[coveralls-url]: https://coveralls.io/r/gulpjs/replace-homedir
[coveralls-image]: https://img.shields.io/coveralls/gulpjs/replace-homedir/master.svgstyle=flat-square