pax_global_header00006660000000000000000000000064132123024110014477gustar00rootroot0000000000000052 comment=1a902568488cc2e615dd4eb9df651954979a6ad9 replace-homedir-1.0.0/000077500000000000000000000000001321230241100145355ustar00rootroot00000000000000replace-homedir-1.0.0/.eslintrc000066400000000000000000000000301321230241100163520ustar00rootroot00000000000000{ "extends": "gulp" } replace-homedir-1.0.0/.gitignore000066400000000000000000000011461321230241100165270ustar00rootroot00000000000000# Logs logs *.log # Runtime data pids *.pid *.seed # Directory for instrumented libs generated by jscoverage/JSCover lib-cov # Coverage directory used by tools like istanbul coverage # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt # Compiled binary addons (http://nodejs.org/api/addons.html) build/Release # Dependency directory # Commenting this out is preferred by some people, see # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- node_modules # Users Environment Variables .lock-wscript # Garbage files .DS_Store replace-homedir-1.0.0/.jscsrc000066400000000000000000000000271321230241100160240ustar00rootroot00000000000000{ "preset": "gulp" } replace-homedir-1.0.0/.travis.yml000066400000000000000000000002011321230241100166370ustar00rootroot00000000000000sudo: false language: node_js node_js: - '8' - '6' - '5' - '4' - '0.12' - '0.10' after_script: - npm run coveralls replace-homedir-1.0.0/LICENSE000066400000000000000000000022141321230241100155410ustar00rootroot00000000000000The 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. replace-homedir-1.0.0/README.md000066400000000000000000000034621321230241100160210ustar00rootroot00000000000000

# 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 replace-homedir-1.0.0/appveyor.yml000066400000000000000000000007531321230241100171320ustar00rootroot00000000000000# http://www.appveyor.com/docs/appveyor-yml # http://www.appveyor.com/docs/lang/nodejs-iojs environment: matrix: # node.js - nodejs_version: "0.10" - nodejs_version: "0.12" - nodejs_version: "4" - nodejs_version: "5" - nodejs_version: "6" - nodejs_version: "8" install: - ps: Install-Product node $env:nodejs_version - npm install test_script: - node --version - npm --version - cmd: npm test build: off # build version format version: "{build}" replace-homedir-1.0.0/index.js000066400000000000000000000012741321230241100162060ustar00rootroot00000000000000'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; replace-homedir-1.0.0/package.json000066400000000000000000000022761321230241100170320ustar00rootroot00000000000000{ "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" ] } replace-homedir-1.0.0/test/000077500000000000000000000000001321230241100155145ustar00rootroot00000000000000replace-homedir-1.0.0/test/.eslintrc000066400000000000000000000000351321230241100173360ustar00rootroot00000000000000{ "extends": "gulp/test" } replace-homedir-1.0.0/test/index.js000066400000000000000000000037661321230241100171750ustar00rootroot00000000000000'use strict'; var path = require('path'); var expect = require('expect'); var homedir = require('homedir-polyfill'); var replaceHomedir = require('../'); describe('replace-homedir', function() { var home = homedir(); var relative = 'replace-homedir/test'; var absolute = path.join(home, relative); it('throws if path is not a string', function(done) { function invalidPath() { replaceHomedir(null); } expect(invalidPath).toThrow('Path for replace-homedir must be a string.'); done(); }); it('replaces the homedir with replacement string', function(done) { var result = replaceHomedir(absolute, '~'); var expected = path.join('~', relative); expect(result).toEqual(expected); done(); }); it('replaces the homedir with replacement function', function(done) { var result = replaceHomedir(absolute, function() { return '~'; }); var expected = path.join('~', relative); expect(result).toEqual(expected); done(); }); it('does not replace the homedir if not at beginning of path', function(done) { var filepath = path.join('/fake', absolute); var result = replaceHomedir(filepath, '~'); var expected = path.join('/fake', absolute); expect(result).toEqual(expected); done(); }); it('does not replace homedir when it is a subpath', function(done) { var filepath = path.join(home + '-extended', relative); var result = replaceHomedir(filepath, '~'); var expected = path.join(home + '-extended', relative); expect(result).toEqual(expected); done(); }); it('ignores non-absolute paths', function(done) { var USERPROFILE = process.env.USERPROFILE; var HOME = process.env.HOME; process.env.USERPROFILE = process.env.HOME = home.slice(1); var filepath = absolute.slice(1); var result = replaceHomedir(filepath, '~'); var expected = absolute.slice(1); expect(result).toEqual(expected); done(); process.env.USERPROFILE = USERPROFILE; process.env.HOME = HOME; }); });