cwdurl

1.0.0 • Public • Published

MIT License npm npm bundle size

cwdurl

cwdurl allows to work with Current Working Directory as URL

Installation

$ npm i cwdurl

Usage

import * as cwd from 'cwdurl';

// returns CWD with trailing directory separator
const path = cwd.path(); // /path/to/current/working/directory/

// returns CWD as URL instance
const url = cwd.url(); // file:///path/to/current/working/directory/

// returns CWD as urlstring
const href = cwd.href(); // file:///path/to/current/working/directory/

// resolves relative URL against CWD, returns URL instance
const fileInCwd = cwd.resolve('infile.txt'); // file:///path/to/current/working/directory/infile.txt
const fileOutCwd = cwd.resolve('..', 'outfile.txt'); // file:///path/to/current/working/infile.txt
const ignoreCWD = cwd.resolve('file:///home/absfile.txt'); // file:///home/absfile.txt

// changes CWD using URL
cwd.cd('../../other/directory'); // changes to /path/to/current/other/directory/
cwd.cd('file:///tmp'); // changes to /tmp/

Environment variables

If CWDURL_PERSIST is set, CWD values will be cached at import time and become immutable. cwd.url() will return frozen URL instance.

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i cwdurl

Weekly Downloads

3

Version

1.0.0

License

MIT

Unpacked Size

4.23 kB

Total Files

4

Last publish

Collaborators

  • liviamedeiros