
Product
Socket Now Supports pylock.toml Files
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
xdg-basedir
Advanced tools
The xdg-basedir package is a Node.js module that provides access to the XDG Base Directory Specification paths. It allows developers to easily find standard directories like configuration, data, and cache directories according to the XDG standards, which are commonly used in various Linux distributions.
Access to XDG Config Directory
This feature allows developers to retrieve the path to the user's XDG config directory, which is used to store configuration files.
const xdgBasedir = require('xdg-basedir');
console.log(xdgBasedir.config);
Access to XDG Data Directory
This feature provides the path to the XDG data directory, where applications can store data files.
const xdgBasedir = require('xdg-basedir');
console.log(xdgBasedir.data);
Access to XDG Cache Directory
This feature retrieves the path to the XDG cache directory, which is intended for non-essential data files.
const xdgBasedir = require('xdg-basedir');
console.log(xdgBasedir.cache);
Similar to xdg-basedir, env-paths computes paths for storing things like data, config, cache, etc. It works across different platforms (Windows, macOS, Linux), providing a broader scope compared to xdg-basedir which primarily targets XDG standards on Unix-like systems.
appdirs is another package that provides similar functionality to xdg-basedir, offering a simple interface to find appropriate platform-specific dirs (like those for data or config). It is also cross-platform and provides more comprehensive support for different operating systems compared to xdg-basedir.
Get XDG Base Directory paths
This package is meant for Linux. You should not use XDG on macOS or Windows. Instead, you should follow their platform conventions. You can use env-paths
for that.
$ npm install xdg-basedir
import {xdgData, xdgConfig, xdgDataDirectories} from 'xdg-basedir';
console.log(xdgData);
//=> '/home/sindresorhus/.local/share'
console.log(xdgConfig);
//=> '/home/sindresorhus/.config'
console.log(xdgDataDirectories);
//=> ['/home/sindresorhus/.local/share', '/usr/local/share/', '/usr/share/']
The exports xdgData
, xdgConfig
, xdgCache
, xdgRuntime
will return undefined
in the uncommon case that both the XDG environment variable is not set and the users home directory can't be found. You need to handle this case. A common solution is to fall back to a temporary directory.
Directory for user-specific data files.
Directory for user-specific configuration files.
Directory for user-specific state files.
Directory for user-specific non-essential data files.
Directory for user-specific non-essential runtime files and other file objects (such as sockets, named pipes, etc).
Preference-ordered array of base directories to search for data files in addition to xdgData
.
Preference-ordered array of base directories to search for configuration files in addition to xdgConfig
.
FAQs
Get XDG Base Directory paths
The npm package xdg-basedir receives a total of 9,569,630 weekly downloads. As such, xdg-basedir popularity was classified as popular.
We found that xdg-basedir demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
Security News
Research
Socket uncovered two npm packages that register hidden HTTP endpoints to delete all files on command.
Research
Security News
Malicious Ruby gems typosquat Fastlane plugins to steal Telegram bot tokens, messages, and files, exploiting demand after Vietnam’s Telegram ban.