util.home

Expands the ~ home directory in a path

Usage no npm install needed!

<script type="module">
  import utilHome from 'https://cdn.skypack.dev/util.home';
</script>

README

util.home

Expands the ~ home directory in a path

build analysis code style: prettier testing NPM

Path strings that use the ~, ~/ or ~\ at the front of the string will be expanded to use the home directory of the user. The home directory is dependent on the architecture. For Linux/OSX the environment variable HOME is used. On the Windows operating system it uses USERPROFILE.

This module uses typescript and has a type definition file supplied with the package. It will also accept a Buffer or string.

This module was inspired by the expand-home-dir package.

Installation

This module uses yarn to manage dependencies and run scripts for development.

To install as an application dependency:

$ yarn add --dev util.home

To build the app and run all tests:

$ yarn run all

Usage

Windows

let expand = require('util.home').expandHomeDirectory;

// With USERPROFILE = 'C:\Users\foo'
let dir = expand('~/Documents');
console.log(dir);  // dir = 'C:\Users\foo\Documents'

Linux/OSX

let expand = require('util.home').expandHomeDirectory;

// With HOME = '/home/foo`'
let dir = expand('~/documents');
console.log(dir);  // dir = '/home/foo/documents'