Add untildify
Converts a tilde path to an absolute path.
This commit is contained in:
13
snippets/untildify.md
Normal file
13
snippets/untildify.md
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
### untildify
|
||||||
|
|
||||||
|
Converts a tilde path to an absolute path.
|
||||||
|
|
||||||
|
Use `String.replace()` with a regular expression and `OS.homedir()` to replace the `~` in the start of the path with the home directory.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const untildify = str => str.replace(/^~($|\/|\\)/, `${require('os').homedir()}$1`);
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
untildify('~/node') // '/Users/aUser/node'
|
||||||
|
```
|
||||||
@ -161,6 +161,7 @@ truncateString:string
|
|||||||
truthCheckCollection:object
|
truthCheckCollection:object
|
||||||
unescapeHTML:string
|
unescapeHTML:string
|
||||||
union:array
|
union:array
|
||||||
|
untildify:node
|
||||||
UUIDGeneratorBrowser:browser
|
UUIDGeneratorBrowser:browser
|
||||||
UUIDGeneratorNode:node
|
UUIDGeneratorNode:node
|
||||||
validateNumber:utility
|
validateNumber:utility
|
||||||
|
|||||||
Reference in New Issue
Block a user