untildify
Convert a tilde path to an absolute path:
~/dev
โ/Users/sindresorhus/dev
Install
npm install untildify
Usage
import untildify from 'untildify';
untildify('~/dev');
//=> '/Users/sindresorhus/dev'
Related
See tildify for the inverse.
Convert a tilde path to an absolute path: ~/dev => /Users/sindresorhus/dev
License: MIT License
Convert a tilde path to an absolute path:
~/dev
โ/Users/sindresorhus/dev
npm install untildify
import untildify from 'untildify';
untildify('~/dev');
//=> '/Users/sindresorhus/dev'
See tildify for the inverse.
If the path contains $1
anywhere, the replacement is going to break.
const os = require('os');
To get this package to work with Typescript, the following must be set to true in the tsconfig.json
{
"compilerOptions": {
"esModuleInterop": true
}
}
Without this, in the latest Typescript (5.1.0), it fails compilation with the message:
error TS2497: This module can only be referenced with ECMAScript imports/exports by turning on the 'esModuleInterop' flag and referencing its default export.
For libraries like https://github.com/aws/jsii they require that esModuleInterop
be disabled so this library is unusable in that context.
For example, the following does not work:
import * as untildify from "untildify";
Neither does:
import untildify from "untildify";
If you use untildify in a Node process started as a root, it expands to /root/
. Is there a way to expand to a user's home instead?
One way I can think of is to use process.env.SUDO_USER
~+
should expand to the output of process.cwd()
~-
and ~n
need access to the directory stack. Probably possible through undocumented API.Docs:
https://www.gnu.org/software/bash/manual/html_node/Tilde-Expansion.html
http://zsh.sourceforge.net/Doc/Release/Expansion.html#Filename-Expansion
I think this module (and probably the inverse version as well) should supper the ~user
syntax whereby ~username/my/path
is expanded to /home/username/my/path
. It's important to note, though, that the home directory can vary and has to be looked up in the passwd
database.
There is a $40.00 open bounty on this issue. Add more on Issuehunt.
- Checkout the Issuehunt explorer to discover more funded issues.
- Need some help from other developers? Add your repositories on Issuehunt to raise funds.
Right now, only ~/
gets resolved. In my shell, I can do echo ~
and it expands my home folder correctly.
Would you agree to changing this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.