LiviaMedeiros / cwdurl

use Current Working Directory as URL

Home Page:https://www.npmjs.com/package/cwdurl

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

use Current Working Directory as URL

https://www.npmjs.com/package/cwdurl

License:MIT License


Languages

Language:JavaScript 100.0%