From 267a3c035cb4bca9f8983cc72fc7b5a7d4142523 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Mon, 1 Jan 2018 17:43:18 +0200 Subject: [PATCH] Add untildify Converts a tilde path to an absolute path. --- snippets/untildify.md | 13 +++++++++++++ tag_database | 1 + 2 files changed, 14 insertions(+) create mode 100644 snippets/untildify.md diff --git a/snippets/untildify.md b/snippets/untildify.md new file mode 100644 index 000000000..67e51efe8 --- /dev/null +++ b/snippets/untildify.md @@ -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' +``` diff --git a/tag_database b/tag_database index 64503984d..e66052213 100644 --- a/tag_database +++ b/tag_database @@ -161,6 +161,7 @@ truncateString:string truthCheckCollection:object unescapeHTML:string union:array +untildify:node UUIDGeneratorBrowser:browser UUIDGeneratorNode:node validateNumber:utility