os-paths
Generate portable common OS paths (home, temp, ...)
Installation
npm install os-paths
Requirements
NodeJS >= 6.0
Usage
const osPaths = require('os-paths');
osPaths.home();
//(*nix) => '/home/rivy'
//(win) => 'C:\Users\rivy'
osPaths.temp();
//(*nix) => '/tmp'
//(win) => 'C:\Windows\temp'
API
Initialization
require('os-paths'): OSPaths()
const osPaths = require('os-paths');
The object returned by the module constructor is an OSPaths
function object, augmented with attached methods. When called directly (eg, const p = osPaths()
), it returns a newly constructed OSPaths
object. Since the OSPaths
object contains no instance state, all constructed objects will be functionally identical.
Methods
All module methods return simple, platform-compatible, path strings which are normalized and have no trailing path separators.
The path strings are not guaranteed to already exist on the file system. So, the user is responsible for directory construction, if/when needed. However, since all of these are standard OS directories, they should all exist without the need for user intervention.
If/when necessary, make-dir
or mkdirp
can be used to create the directories.
osPaths.home(): string
Returns the home directory for user
osPaths.temp(): string
Returns the directory for temporary files
Discussion
XDG
All XDG-related methods have been relocated to the xdg-portable
and xdg-app-paths
modules.
Building and Contributing
Build requirements
optional
git-changelog
... enables changelog automation
Build/test
npm install
npm test
Project development scripts
> npm run help
...
usage: `npm run TARGET [TARGET..]`
TARGETs:
coverage calculate and display (or send) code coverage [alias: 'cov']
fix fix package issues (automated/non-interactive)
fix:lint fix `ESLint` issues
fix:style fix `Prettier` formatting issues
help display help
lint check for package code 'lint'
lint:lint check for code 'lint' (using `ESLint`)
lint:spell check for spelling errors (using `cSpell`)
lint:style check for format imperfections (using `Prettier`)
lint:types check for type declaration errors (using `tsd`)
test test package
test:code test package code
update:changelog update CHANGELOG (using `git changelog ...`)
Contributions
Contributions are welcome.
Any pull requests should be based off of the default branch (master
). And, whenever possible, please include tests for any new code, ensuring that local (via npm test
) and remote CI testing passes.
By contributing to the project, you are agreeing to provide your contributions under the same license as the project itself.
Related
xdg-app-paths
... easy XDG for applicationsxdg-portable
... XDG Base Directory paths (cross-platform)