1.0.0 • Published 9 months ago

cwdurl v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

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

1.0.0

9 months ago