Correct: `Array.from()` (it’s a static method) Incorrect: `Array.join()` (doesn’t exist; it’s a prototype method) This patch uses the common `#` syntax to denote `.prototype.`.
14 lines
357 B
Markdown
14 lines
357 B
Markdown
### untildify
|
|
|
|
Converts a tilde path to an absolute path.
|
|
|
|
Use `String.prototype.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'
|
|
```
|