package/package.json000644 000765 000024 0000002276 13212302411013011 0ustar00000000 000000 { "name": "replace-homedir", "version": "1.0.0", "description": "Replace user home in a string with another string. Useful for tildifying a path.", "author": "Gulp Team (http://gulpjs.com/)", "contributors": [ "Blaine Bublitz " ], "repository": "gulpjs/replace-homedir", "license": "MIT", "engines": { "node": ">= 0.10" }, "main": "index.js", "files": [ "LICENSE", "index.js" ], "scripts": { "lint": "eslint . && jscs index.js test/", "pretest": "npm run lint", "test": "mocha --async-only", "cover": "istanbul cover _mocha --report lcovonly", "coveralls": "npm run cover && istanbul-coveralls" }, "dependencies": { "homedir-polyfill": "^1.0.1", "is-absolute": "^1.0.0", "remove-trailing-separator": "^1.1.0" }, "devDependencies": { "eslint": "^1.7.3", "eslint-config-gulp": "^2.0.0", "expect": "^1.20.2", "istanbul": "^0.4.3", "istanbul-coveralls": "^1.0.3", "jscs": "^2.3.5", "jscs-preset-gulp": "^1.0.0", "mocha": "^2.4.5" }, "keywords": [ "path", "homedir", "tilde", "replace", "subsitute", "user home", "tilde" ] } package/README.md000644 000765 000024 0000003462 13212070715012011 0ustar00000000 000000

# replace-homedir [![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![AppVeyor Build Status][appveyor-image]][appveyor-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Gitter chat][gitter-image]][gitter-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]: http://img.shields.io/npm/dm/replace-homedir.svg [npm-url]: https://www.npmjs.com/package/replace-homedir [npm-image]: http://img.shields.io/npm/v/replace-homedir.svg [travis-url]: https://travis-ci.org/gulpjs/replace-homedir [travis-image]: http://img.shields.io/travis/gulpjs/replace-homedir.svg?label=travis-ci [appveyor-url]: https://ci.appveyor.com/project/gulpjs/replace-homedir [appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/replace-homedir.svg?label=appveyor [coveralls-url]: https://coveralls.io/r/gulpjs/replace-homedir [coveralls-image]: http://img.shields.io/coveralls/gulpjs/replace-homedir/master.svg [gitter-url]: https://gitter.im/gulpjs/gulp [gitter-image]: https://badges.gitter.im/gulpjs/gulp.svg package/LICENSE000644 000765 000024 0000002214 13212061564011533 0ustar00000000 000000 The MIT License (MIT) Copyright (c) 2017 Blaine Bublitz , Eric Schoffstall and other contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. package/index.js000644 000765 000024 0000001274 13212073377012205 0ustar00000000 000000 'use strict'; var path = require('path'); var homedir = require('homedir-polyfill'); var isAbsolute = require('is-absolute'); var removeTrailingSep = require('remove-trailing-separator'); function replaceHomedir(filepath, replacement) { if (typeof filepath !== 'string') { throw new Error('Path for replace-homedir must be a string.'); } if (!isAbsolute(filepath)) { return filepath; } var home = removeTrailingSep(homedir()); var lookupHome = home + path.sep; var lookupPath = removeTrailingSep(filepath) + path.sep; if (lookupPath.indexOf(lookupHome) !== 0) { return filepath; } return filepath.replace(home, replacement); } module.exports = replaceHomedir;