Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shinnn/app-cache-dir
Get a path of the standard cache directory for a given application
https://github.com/shinnn/app-cache-dir
cache cross-platform directory environment javascript nodejs xdg
Last synced: 26 days ago
JSON representation
Get a path of the standard cache directory for a given application
- Host: GitHub
- URL: https://github.com/shinnn/app-cache-dir
- Owner: shinnn
- License: isc
- Created: 2017-06-26T10:57:40.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-10T09:11:21.000Z (over 5 years ago)
- Last Synced: 2024-10-18T19:57:41.114Z (3 months ago)
- Topics: cache, cross-platform, directory, environment, javascript, nodejs, xdg
- Language: JavaScript
- Homepage: https://github.com/atom/atom/issues/8281#issue-99784635
- Size: 82 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# app-cache-dir
[![npm version](https://img.shields.io/npm/v/app-cache-dir.svg)](https://www.npmjs.com/package/app-cache-dir)
[![Build Status](https://travis-ci.com/shinnn/app-cache-dir.svg?branch=master)](https://travis-ci.com/shinnn/app-cache-dir)
[![codecov](https://codecov.io/gh/shinnn/app-cache-dir/branch/master/graph/badge.svg)](https://codecov.io/gh/shinnn/app-cache-dir)Get a path of the standard cache directory for a given application
```javascript
const appCacheDir = require('app-cache-dir');// On most Linuxes
appCacheDir('my-app'); //=> '/root/shinnn/.cache/my-app'// On macOS
appCacheDir('my-app'); //=> '/Users/shinnn/.cache/my-app'// On Windows
appCacheDir('my-app'); //=> 'C:\\Users\\shinnn\\AppData\\Local\\my-app\\cache'
```## Installation
[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/about-npm/).
```
npm install app-cache-dir
```## API
```javascript
const appCacheDir = require('app-cache-dir');
```### appCacheDir(*appName*)
*appName*: `string` (application name)
Return: `string` (absolute directory path)It resolves an application name into its [standard cache directory presented in the Atom issue tracker](https://github.com/atom/atom/issues/8281#issue-99784635), with following the environment variables [`XDG_CACHE_HOME`](https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html) (POSIX) and `LOCALAPPDATA` (Windows).
Basically it results:
* `~/.cache/${appName}` on POSIX
* `C:\\Users\\${username}\\AppData\Local\${appName}\cache` on Windows```javascript
// On macOSappCacheDir('hi'); //=> '/Users/shinnn/.cache/hi'
process.env.XDG_CACHE_HOME = '/foo/bar/';
appCacheDir('hi'); //=> '/foo/bar/hi'
```When it cannot resolve the cache path, for exmaple both `HOME` and `XDG_CACHE_HOME` are empty, it returns `${os.tmpdir()}/${appName}/cache` as a last resort.
### appCacheDir.posix(*appName*)
*appName*: `string`
Return: `string`Follow POSIX way regardless of the current OS.
### appCacheDir.win32(*appName*)
*appName*: `string`
Return: `string`Follow Windows way regardless of the current OS.
## License
[ISC License](./LICENSE) © 2017 - 2019 Shinnosuke Watanabe