pax_global_header00006660000000000000000000000064141122437370014516gustar00rootroot0000000000000052 comment=f1729272888f45f6584e74dc4d0af3aecba9e7e8 sindresorhus-env-paths-e710a2d/000077500000000000000000000000001411224373700165565ustar00rootroot00000000000000sindresorhus-env-paths-e710a2d/.editorconfig000066400000000000000000000002571411224373700212370ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 sindresorhus-env-paths-e710a2d/.gitattributes000066400000000000000000000000231411224373700214440ustar00rootroot00000000000000* text=auto eol=lf sindresorhus-env-paths-e710a2d/.github/000077500000000000000000000000001411224373700201165ustar00rootroot00000000000000sindresorhus-env-paths-e710a2d/.github/funding.yml000066400000000000000000000001631411224373700222730ustar00rootroot00000000000000github: sindresorhus open_collective: sindresorhus custom: https://sindresorhus.com/donate tidelift: npm/env-paths sindresorhus-env-paths-e710a2d/.github/security.md000066400000000000000000000002631411224373700223100ustar00rootroot00000000000000# Security Policy To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. sindresorhus-env-paths-e710a2d/.github/workflows/000077500000000000000000000000001411224373700221535ustar00rootroot00000000000000sindresorhus-env-paths-e710a2d/.github/workflows/main.yml000066400000000000000000000006261411224373700236260ustar00rootroot00000000000000name: CI on: - push - pull_request jobs: test: name: Node.js ${{ matrix.node-version }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: node-version: - 16 steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} - run: npm install - run: npm test sindresorhus-env-paths-e710a2d/.gitignore000066400000000000000000000000271411224373700205450ustar00rootroot00000000000000node_modules yarn.lock sindresorhus-env-paths-e710a2d/.npmrc000066400000000000000000000000231411224373700176710ustar00rootroot00000000000000package-lock=false sindresorhus-env-paths-e710a2d/index.d.ts000066400000000000000000000052341411224373700204630ustar00rootroot00000000000000export interface Options { /** __Don't use this option unless you really have to!__ Suffix appended to the project name to avoid name conflicts with native apps. Pass an empty string to disable it. @default 'nodejs' */ readonly suffix?: string; } export interface Paths { /** Directory for data files. Example locations (with the default `nodejs` suffix): - macOS: `~/Library/Application Support/MyApp-nodejs` - Windows: `%LOCALAPPDATA%\MyApp-nodejs\Data` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Data`) - Linux: `~/.local/share/MyApp-nodejs` (or `$XDG_DATA_HOME/MyApp-nodejs`) */ readonly data: string; /** Directory for data files. Example locations (with the default `nodejs` suffix): - macOS: `~/Library/Preferences/MyApp-nodejs` - Windows: `%APPDATA%\MyApp-nodejs\Config` (for example, `C:\Users\USERNAME\AppData\Roaming\MyApp-nodejs\Config`) - Linux: `~/.config/MyApp-nodejs` (or `$XDG_CONFIG_HOME/MyApp-nodejs`) */ readonly config: string; /** Directory for non-essential data files. Example locations (with the default `nodejs` suffix): - macOS: `~/Library/Caches/MyApp-nodejs` - Windows: `%LOCALAPPDATA%\MyApp-nodejs\Cache` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Cache`) - Linux: `~/.cache/MyApp-nodejs` (or `$XDG_CACHE_HOME/MyApp-nodejs`) */ readonly cache: string; /** Directory for log files. Example locations (with the default `nodejs` suffix): - macOS: `~/Library/Logs/MyApp-nodejs` - Windows: `%LOCALAPPDATA%\MyApp-nodejs\Log` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Log`) - Linux: `~/.local/state/MyApp-nodejs` (or `$XDG_STATE_HOME/MyApp-nodejs`) */ readonly log: string; /** Directory for temporary files. Example locations (with the default `nodejs` suffix): - macOS: `/var/folders/jf/f2twvvvs5jl_m49tf034ffpw0000gn/T/MyApp-nodejs` - Windows: `%LOCALAPPDATA%\Temp\MyApp-nodejs` (for example, `C:\Users\USERNAME\AppData\Local\Temp\MyApp-nodejs`) - Linux: `/tmp/USERNAME/MyApp-nodejs` */ readonly temp: string; } /** Get paths for storing things like data, config, cache, etc. Note: It only generates the path strings. It doesn't create the directories for you. You could use [`make-dir`](https://github.com/sindresorhus/make-dir) to create the directories. @param name - The name of your project. Used to generate the paths. @returns The paths to use for your project on current OS. @example ``` import envPaths from 'env-paths'; const paths = envPaths('MyApp'); paths.data; //=> '/home/sindresorhus/.local/share/MyApp-nodejs' paths.config //=> '/home/sindresorhus/.config/MyApp-nodejs' ``` */ export default function envPaths(name: string, options?: Options): Paths; sindresorhus-env-paths-e710a2d/index.js000066400000000000000000000037531411224373700202330ustar00rootroot00000000000000import path from 'node:path'; import os from 'node:os'; import process from 'node:process'; const homedir = os.homedir(); const tmpdir = os.tmpdir(); const {env} = process; const macos = name => { const library = path.join(homedir, 'Library'); return { data: path.join(library, 'Application Support', name), config: path.join(library, 'Preferences', name), cache: path.join(library, 'Caches', name), log: path.join(library, 'Logs', name), temp: path.join(tmpdir, name), }; }; const windows = name => { const appData = env.APPDATA || path.join(homedir, 'AppData', 'Roaming'); const localAppData = env.LOCALAPPDATA || path.join(homedir, 'AppData', 'Local'); return { // Data/config/cache/log are invented by me as Windows isn't opinionated about this data: path.join(localAppData, name, 'Data'), config: path.join(appData, name, 'Config'), cache: path.join(localAppData, name, 'Cache'), log: path.join(localAppData, name, 'Log'), temp: path.join(tmpdir, name), }; }; // https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html const linux = name => { const username = path.basename(homedir); return { data: path.join(env.XDG_DATA_HOME || path.join(homedir, '.local', 'share'), name), config: path.join(env.XDG_CONFIG_HOME || path.join(homedir, '.config'), name), cache: path.join(env.XDG_CACHE_HOME || path.join(homedir, '.cache'), name), // https://wiki.debian.org/XDGBaseDirectorySpecification#state log: path.join(env.XDG_STATE_HOME || path.join(homedir, '.local', 'state'), name), temp: path.join(tmpdir, username, name), }; }; export default function envPaths(name, {suffix = 'nodejs'} = {}) { if (typeof name !== 'string') { throw new TypeError(`Expected a string, got ${typeof name}`); } if (suffix) { // Add suffix to prevent possible conflict with native apps name += `-${suffix}`; } if (process.platform === 'darwin') { return macos(name); } if (process.platform === 'win32') { return windows(name); } return linux(name); } sindresorhus-env-paths-e710a2d/index.test-d.ts000066400000000000000000000005601411224373700214350ustar00rootroot00000000000000import {expectType} from 'tsd'; import envPaths, {Paths} from './index.js'; expectType(envPaths('MyApp')); expectType(envPaths('MyApp', {suffix: 'test'})); const paths = envPaths('MyApp'); expectType(paths.cache); expectType(paths.config); expectType(paths.data); expectType(paths.log); expectType(paths.temp); sindresorhus-env-paths-e710a2d/license000066400000000000000000000021351411224373700201240ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (https://sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. sindresorhus-env-paths-e710a2d/package.json000066400000000000000000000015061411224373700210460ustar00rootroot00000000000000{ "name": "env-paths", "version": "3.0.0", "description": "Get paths for storing things like data, config, cache, etc", "license": "MIT", "repository": "sindresorhus/env-paths", "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, "type": "module", "exports": "./index.js", "engines": { "node": "^12.20.0 || ^14.13.1 || >=16.0.0" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "common", "user", "paths", "env", "environment", "directory", "dir", "appdir", "path", "data", "config", "cache", "logs", "temp", "linux", "unix" ], "devDependencies": { "ava": "^3.15.0", "tsd": "^0.17.0", "xo": "^0.44.0" } } sindresorhus-env-paths-e710a2d/readme.md000066400000000000000000000060551411224373700203430ustar00rootroot00000000000000# env-paths > Get paths for storing things like data, config, cache, etc Uses the correct OS-specific paths. Most developers get this wrong. ## Install ``` $ npm install env-paths ``` ## Usage ```js import envPaths from 'env-paths'; const paths = envPaths('MyApp'); paths.data; //=> '/home/sindresorhus/.local/share/MyApp-nodejs' paths.config //=> '/home/sindresorhus/.config/MyApp-nodejs' ``` ## API ### paths = envPaths(name, options?) Note: It only generates the path strings. It doesn't create the directories for you. You could use [`make-dir`](https://github.com/sindresorhus/make-dir) to create the directories. #### name Type: `string` The name of your project. Used to generate the paths. #### options Type: `object` ##### suffix Type: `string`\ Default: `'nodejs'` **Don't use this option unless you really have to!** Suffix appended to the project name to avoid name conflicts with native apps. Pass an empty string to disable it. ### paths.data Directory for data files. Example locations (with the default `nodejs` [suffix](#suffix)): - macOS: `~/Library/Application Support/MyApp-nodejs` - Windows: `%LOCALAPPDATA%\MyApp-nodejs\Data` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Data`) - Linux: `~/.local/share/MyApp-nodejs` (or `$XDG_DATA_HOME/MyApp-nodejs`) ### paths.config Directory for config files. Example locations (with the default `nodejs` [suffix](#suffix)): - macOS: `~/Library/Preferences/MyApp-nodejs` - Windows: `%APPDATA%\MyApp-nodejs\Config` (for example, `C:\Users\USERNAME\AppData\Roaming\MyApp-nodejs\Config`) - Linux: `~/.config/MyApp-nodejs` (or `$XDG_CONFIG_HOME/MyApp-nodejs`) ### paths.cache Directory for non-essential data files. Example locations (with the default `nodejs` [suffix](#suffix)): - macOS: `~/Library/Caches/MyApp-nodejs` - Windows: `%LOCALAPPDATA%\MyApp-nodejs\Cache` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Cache`) - Linux: `~/.cache/MyApp-nodejs` (or `$XDG_CACHE_HOME/MyApp-nodejs`) ### paths.log Directory for log files. Example locations (with the default `nodejs` [suffix](#suffix)): - macOS: `~/Library/Logs/MyApp-nodejs` - Windows: `%LOCALAPPDATA%\MyApp-nodejs\Log` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Log`) - Linux: `~/.local/state/MyApp-nodejs` (or `$XDG_STATE_HOME/MyApp-nodejs`) ### paths.temp Directory for temporary files. Example locations (with the default `nodejs` [suffix](#suffix)): - macOS: `/var/folders/jf/f2twvvvs5jl_m49tf034ffpw0000gn/T/MyApp-nodejs` - Windows: `%LOCALAPPDATA%\Temp\MyApp-nodejs` (for example, `C:\Users\USERNAME\AppData\Local\Temp\MyApp-nodejs`) - Linux: `/tmp/USERNAME/MyApp-nodejs` ---
Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
sindresorhus-env-paths-e710a2d/test.js000066400000000000000000000023261411224373700200760ustar00rootroot00000000000000import process from 'node:process'; import test from 'ava'; import envPaths from './index.js'; test('default', t => { const name = 'unicorn'; const paths = envPaths(name); for (const [key, value] of Object.entries(paths)) { console.log(` ${key}: ${value}`); t.true(value.endsWith(`${name}-nodejs`)); } }); test('custom suffix', t => { const name = 'unicorn'; const options = {suffix: 'horn'}; const paths = envPaths(name, options); t.true(paths.data.endsWith(`${name}-${options.suffix}`)); }); test('no suffix', t => { const name = 'unicorn'; const paths = envPaths(name, {suffix: false}); t.true(paths.data.endsWith(name)); }); // Linux-specific tests if (process.platform === 'linux') { test('correct paths with XDG_*_HOME set', t => { const envVars = { data: 'XDG_DATA_HOME', config: 'XDG_CONFIG_HOME', cache: 'XDG_CACHE_HOME', log: 'XDG_STATE_HOME', }; for (const env of Object.values(envVars)) { process.env[env] = `/tmp/${env}`; } const name = 'unicorn'; const paths = envPaths(name); for (const env of Object.keys(envVars)) { const expectedPath = process.env[envVars[env]]; t.true(paths[env].startsWith(expectedPath) && paths[env].endsWith(`${name}-nodejs`)); } }); }