os-paths

Generate portable common OS paths (home, temp, ...)

Build status (GHA) Build status (Travis-CI) Build status (AppVeyor) Coverage status License Style Guide  
Repository NPM version NodeJS version Downloads

Installation

npm install os-paths
# or... `npm install github:rivy/js.os-paths`
# or... `npm install "https://cdn.jsdelivr.net/gh/rivy/js.os-paths@latest/dist/os-paths.tgz"`

Requirements

NodeJS >= 6.0[^*]

[^*]: With the conversion to a TypeScript-based project, due to tooling constraints, testing is more difficult and more limited on Node platforms earlier than Node-v10+. However, the generated CommonJS/UMD project code is still fully compatible with Node-v6+.

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 a function object, OSPaths, augmented with attached methods. When this object is called directly (eg, const p = osPaths()), it returns another 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 | undefined

  • Returns the home directory for user (or undefined)

undefined is returned if the home directory is not resolvable.

osPaths.temp(): string

  • Returns the directory for temporary files

Always returns a non-empty path (as sanely as possible).

Discussion

XDG

All XDG-related methods have been relocated to the xdg-portable and xdg-app-paths modules.

Building and Contributing

Repository Build status (GHA) Build status (Travis-CI) Build status (AppVeyor) Coverage status  
Quality status (Codacy) Quality status (CodeClimate) Quality status (CodeFactor) Quality status (Scrutinizer)

Build requirements

  • NodeJS >= 6.0
  • a JavaScript package/project manager (npm or yarn)

optional

Build/test

npm install-test

Project development scripts

> npm run help
...
usage: `npm run TARGET` or `npx run-s TARGET [TARGET..]`

TARGETs:

build               build/compile package
clean               remove build artifacts
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:markdown       check for markdown errors (using `remark`)
lint:spell          check for spelling errors (using `cspell`)
lint:style          check for format imperfections (using `prettier`)
realclean           remove all generated files
rebuild             clean and (re-)build project
retest              clean and (re-)test project
reset:hard          remove *all* generated files and reinstall dependencies
show:deps           show package dependencies
test                test package
test:code           test package code
test:types          test for type declaration errors (using `tsd`)
update              update/prepare for distribution
update:changelog    update CHANGELOG (using `git changelog ...`)
update:dist         update distribution content

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.

License

MIT © Roy Ivy III, Sindre Sorhus