util.home
TypeScript icon, indicating that this package has built-in type declarations

0.0.33 • Public • Published

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'

Readme

Keywords

none

Package Sidebar

Install

npm i util.home

Weekly Downloads

17

Version

0.0.33

License

MIT

Unpacked Size

6.25 kB

Total Files

6

Last publish

Collaborators

  • jmquigley