Coder Social home page Coder Social logo

tildify's Introduction

tildify

Convert an absolute path to a tilde path: /Users/sindresorhus/dev โ†’ ~/dev

Install

$ npm install tildify

Usage

import tildify from 'tildify';

tildify('/Users/sindresorhus/dev');
//=> '~/dev'

Related

See untildify for the inverse.

tildify's People

Contributors

bendingbender avatar fritx avatar kevva avatar richienb avatar sindresorhus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

tildify's Issues

Make str.replace strict?

Hey @sindresorhus
How about this? also would work in untildify

module.exports = function (str) {
    return str.replace(home, '~');
};

=>

module.exports = function (str) {
  str += path.sep;
  str = str.replace(home + path.sep, '~' + path.sep);
  str = str.slice(0, -1);
  return str;
};
test(function (t) {
  var fixture = home;
  t.assert(tildify(fixture) === '~');
  t.end();
});

test(function (t) {
  var fixture = path.resolve(home, 'tildify');
  t.assert(tildify(fixture)[0] === '~');
  t.assert(/tildify$/.test(tildify(fixture)));
  t.assert(tildify(fixture) !== fixture);
  t.end();
});

test(function (t) {
  var fixture = path.resolve(home + 'foo', 'tildify');
  t.assert(tildify(fixture) === fixture);
  t.end();
});

image

string match fails when Windows drive letter is lowercase

Paths returned by VS Code APIs may have lowercase drive letters on Windows. As StartsWith is case sensitive the logic fails. It's such short code I just rewrote it in Typescript and fixed my local copy.

	if (normalizedPath[1] === ":") {
		//force first char to uppercase
		normalizedPath = normalizedPath.replace(normalizedPath[0], normalizedPath[0].toUpperCase());
	}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.