Add untildify

Converts a tilde path to an absolute path.
This commit is contained in:
Angelos Chalaris
2018-01-01 17:43:18 +02:00
parent 61120916de
commit 267a3c035c
2 changed files with 14 additions and 0 deletions

13
snippets/untildify.md Normal file
View 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'
```

View File

@ -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