Gathering detailed insights and metrics for xdg-portable
Gathering detailed insights and metrics for xdg-portable
Gathering detailed insights and metrics for xdg-portable
Gathering detailed insights and metrics for xdg-portable
Determine XDG Base Directory paths (OS/platform portable)
npm install xdg-portable
97.7
Supply Chain
99.5
Quality
76
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
7 Stars
399 Commits
2 Watching
5 Branches
4 Contributors
Updated on 29 Oct 2024
Minified
Minified + Gzipped
JavaScript (69.8%)
TypeScript (30.2%)
Cumulative downloads
Total Downloads
Last day
1%
123,394
Compared to previous day
Last week
1.9%
648,860
Compared to previous week
Last month
9%
2,780,087
Compared to previous month
Last year
802.3%
25,203,772
Compared to previous year
50
1
Determine XDG Base Directory paths (OS/platform portable)
1npm install xdg-portable 2# or... `npm install "git:github.com/rivy/js.xdg-portable"` 3# or... `npm install "git:github.com/rivy/js.xdg-portable#v10.6.0"` 4# or... `npm install "https://cdn.jsdelivr.net/gh/rivy/js.xdg-portable@v10.6.0/dist/xdg-portable.tgz"` 5# or... `npm install "https://cdn.jsdelivr.net/gh/rivy/js.xdg-portable@COMMIT_SHA/dist/xdg-portable.tgz"`
1const xdg = require('xdg-portable/cjs'); 2 3const configDirs = xdg.configDirs(); 4const stateDir = xdg.state(); 5 6const locatePath = require('locatePath'); 7const mkdirp = require('mkdirp'); 8 9const configDir = locatePath.sync(configDirs) || configDirs[0]; 10mkdirp.sync(configDir, 0o700); 11 12mkdirp.sync(stateDir, 0o700);
1import xdg from 'xdg-portable'; 2const configDirs = xdg.configDirs(); 3//...
1import xdg from 'https://deno.land/x/xdg_portable@v10.6.0/src/mod.deno.ts'; 2//or (via CDN, [ie, JSDelivr with GitHub version/version-range, commit, 'latest' support])... 3//import xdg from 'https://cdn.jsdelivr.net/gh/rivy/js.xdg-portable@v10.6.0/src/mod.deno.ts'; 4//import xdg from 'https://cdn.jsdelivr.net/gh/rivy/js.xdg-portable@COMMIT_SHA/src/mod.deno.ts'; 5const configDirs = xdg.configDirs(); 6//...
XDG()
1const xdg = require('xdg-portable/cjs'); // CJS 2//or... 3//import xdg from 'xdg-portable'; // ESM/TypeScript 4//import xdg from 'https://deno.land/x/xdg/src/mod.deno.ts'; // Deno
When importing this module, the object returned is a function object, XDG
, augmented with attached methods. Additional XDG
objects may be constructed by direct call of the imported XDG
object (eg, const x = xdg()
) or by using new
(eg, const x = new xdg()
). Notably, since the XDG
object contains no user-facing instance state, all XDG
objects will be functionally identical.
XDG
~ primary module function objectTypes named here are exported individually by name (eg, as "XDG").
1import type { XDG } from 'xdg-portable'; // TypeScript 2//or... 3//import type { XDG } from 'https://deno.land/x/xdg/src/mod.deno.ts'; // Deno
All module methods return platform-compatible path strings which are normalized and have no trailing path separators.
The returned path strings are not guaranteed to already exist on the file system. So, the user application is responsible for directory construction, if/when needed. If needed, make-dir
or mkdirp
can be used to create the directories.
xdg.cache(): string
Deletion of the data contained here might cause an application to slow down.
1const cacheDir = xdg.cache(); 2//(mac)=> '/Users/rivy/Library/Caches' 3//(nix)=> '/home/rivy/.cache' 4//(win)=> 'C:\\Users\\rivy\\AppData\\Local\\xdg.cache'
This directory location would be analogous to /var/cache for *nix.
%LocalAppData%\xdg.cache
is the default for the windows platform.
xdg.config(): string
Deletion of the data contained here might require the user to reconfigure an application.
1const configDir = xdg.config(); 2//(mac)=> '/Users/rivy/Library/Preferences' 3//(nix)=> '/home/rivy/.config' 4//(win)=> 'C:\\Users\\rivy\\AppData\\Roaming\\xdg.config'
This directory location would be analogous to /etc for *nix.
%AppData%\xdg.config
is the default for the windows platform.
xdg.data(): string
Deletion of the data contained here might force the user to restore from backups.
1const dataDir = xdg.data(); 2//(mac)=> '/Users/rivy/Library/Application Support' 3//(nix)=> '/home/rivy/.local/share' 4//(win)=> 'C:\\Users\\rivy\\AppData\\Roaming\\xdg.data'
This directory location would be analogous to /usr/share for *nix.
%AppData%\xdg.data
is the default for the windows platform.
xdg.runtime(): string?
undefined
.Deletion of the data contained here might interfere with a currently executing application but should have no effect on future executions.
1const runtimeDir = xdg.runtime();
The XDG specification defines some fairly strict specifications for a "runtime"-data candidate directory. To meet these criteria, the directory must usually be supplied by the OS. The user may override this by using the XDG_RUNTIME_DIR
environment variable.
undefined
is the default for the windows platform.
xdg.state(): string
Deletion of the data contained here should not materially interfere with execution of an application.
1const stateDir = xdg.state(); 2//(mac)=> '/Users/rivy/Library/State' 3//(nix)=> '/home/rivy/.local/state' 4//(win)=> 'C:\\Users\\rivy\\AppData\\Local\\xdg.state'
This directory location might hold data such as backups, input history, logs, recent file lists, visual application state, etc.
%LocalAppData%\xdg.state
is the default for the windows platform.
xdg.configDirs(): readonly string[]
xdg.config()
directory as first entry).1const configDirs = xdg.configDirs(); 2//(mac)=> [ '/Users/rivy/Library/Preferences', ... ] 3//(nix)=> [ '/home/rivy/.config', ... ] 4//(win)=> [ 'C:\\Users\\rivy\\AppData\\Roaming\\xdg.config' , ... ]
xdg.dataDirs(): readonly string[]
xdg.data()
directory as first entry).1const dataDirs = xdg.dataDirs(); 2//(mac)=> [ '/Users/rivy/Library/Application Support', ... ] 3//(nix)=> [ '/home/rivy/.local/share', ... ] 4//(win)=> [ 'C:\\Users\\rivy\\AppData\\Roaming\\xdg.share' , ... ]
Requirements
NodeJS >= 4.01
*.js
and *.cjs
)CJS is the basic supported output (with support for NodeJS versions as early as NodeJS-v4).
1const xdg = require('xdg-portable/cjs'); 2console.log(xdg.config());
Note: for CJS,
require('xdg-portable')
is supported for backward-compatibility and will execute correctly at run-time. However,require('xdg-portable')
links to the default package type declarations which, though correct for Deno/ESM/TypeScript, are incorrect for CJS. This, then, leads to incorrect analysis of CJS files by static analysis tools such as TypeScript and Intellisense.Using
require('xdg-portable/cjs')
is preferred as it associates the proper CJS type declarations and provides correct information to static analysis tools.
*.mjs
)XDG
v8.0
+.XDG
fully supports ESM imports.
1import xdg from 'xdg-portable'; 2console.log(xdg.config());
*.ts
)XDG
v8.0
+.As of v8.0
+, XDG
has been converted to a TypeScript-based module.
As a consequence, TypeScript type definitions are automatically generated, bundled, and exported by the module.
Requirements
Deno >= v1.8.02
Required Permissions
--allow-env
· allow access to the process environment variables
This module/package requires access to various environment variables to determine platform configuration (eg, location of temp and user directories).
XDG
v9.0
+.XDG
also fully supports use by Deno.
1import xdg from 'https://deno.land/x/xdg/src/mod.deno.ts'; 2console.log(xdg.config());
The XDG Base Directory Specification@ defines categories of user information (ie, "cache", "config", "data", ...), defines their standard storage locations, and defines the standard process for user configuration of those locations (using XDG_CACHE_HOME
, etc).
Applications supporting the XDG convention are expected to store user-specific files within these locations, either within the common/shared directory (eg, `${xdg.cache()}/filename`
) or within a more isolated application-defined subdirectory (eg, `${xdg.config()}/DIR/filename`
; DIR
usually being the application name).
Windows has an alternate convention, offering just two standard locations for applications to persist data, either %APPDATA%
(for files which may "roam" with the user between hosts) and %LOCALAPPDATA%
(for local-machine-only files). All application files are expected to be stored within an application-unique subdirectory in one of those two locations, usually under a directory matching the application name. There is no further popular convention used to segregate the file types (ie, into "cache", "config", ...) in any way similar to the XDG specification.
So, to support basic XDG-like behavior (that is, segregating the information types into type-specific directories), this module creates a new convention for Windows hosts, placing the specific types of files into subdirectories under either %APPDATA%
or %LOCALAPPDATA%
, as appropriate for the file type. For example, "cache"-type files will be offered placement into %LOCALAPPDATA%\xdg.cache
, "config"-type files into %APPDATA%\xdg.config
, "data"-type files into %APPDATA%\xdg.data
, etc.
xdg-app-paths
builds on this module and offers application specific paths more in-line with usual platform conventions, but still compatible with the XDG specification.
In the uncommon case that both the XDG environment variable is not set and the users home directory can't be determined, the temporary directory (OS/platform specific; determined by temp()
from os-paths) will be used as a fallback for the missing home directory value.
This module was forked from sindresorhus/xdg-basedir in order to add cross-platform portability and support simpler cross-platform applications.
optional
bmp
(v0.0.6+) ... synchronizes version strings within the projectgit-changelog
(v1.1+) ... enables changelog automation
1npm install-test
1git clone "https://github.com/rivy/js.xdg-portable" 2cd js.xdg-portable 3# * note: for WinOS, replace `cp` with `copy` (or use [uutils](https://github.com/uutils/coreutils)) 4# npm 5cp .deps-lock/package-lock.json . 6npm clean-install 7# yarn 8cp .deps-lock/yarn.lock . 9yarn --immutable --immutable-cache --check-cache
1> npm run help 2... 3usage: `npm run TARGET` or `npx run-s TARGET [TARGET..]` 4 5TARGETs: 6 7build build/compile package 8clean remove build artifacts 9coverage calculate and display (or send) code coverage [alias: 'cov'] 10fix fix package issues (automated/non-interactive) 11fix:lint fix ESLint issues 12fix:style fix Prettier formatting issues 13help display help 14lint check for package code 'lint' 15lint:audit check for `npm audit` violations in project code 16lint:commits check for commit flaws (using `commitlint` and `cspell`) 17lint:editorconfig check for EditorConfig format flaws (using `editorconfig-checker`) 18lint:lint check for code 'lint' (using `eslint`) 19lint:markdown check for markdown errors (using `remark`) 20lint:spell check for spelling errors (using `cspell`) 21lint:style check for format imperfections (using `prettier`) 22prerelease clean, rebuild, and fully test (useful prior to publish/release) 23realclean remove all generated files 24rebuild clean and (re-)build project 25refresh clean and rebuild/regenerate all project artifacts 26refresh:dist clean, rebuild, and regenerate project distribution 27retest clean and (re-)test project 28reset:hard remove *all* generated files and reinstall dependencies 29show:deps show package dependencies 30test test package 31test:code test package code (use `--test-code=...` to pass options to testing harness) 32test:types test for type declaration errors (using `tsd`) 33update update/prepare for distribution [alias: 'dist'] 34update:changelog update CHANGELOG (using `git changelog ...`) 35update:dist update distribution content 36verify fully (and verbosely) test package
1#=== * POSIX 2# update project VERSION strings (package.json,...) 3# * `bmp --[major|minor|patch]`; next VERSION in M.m.r (semver) format 4bmp --minor 5VERSION=$(cat VERSION) 6git-changelog --next-tag "v${VERSION}" > CHANGELOG.mkd 7# create/commit updates and distribution 8git add package.json CHANGELOG.mkd README.md VERSION .bmp.yml 9git commit -m "${VERSION}" 10npm run clean && npm run update:dist && git add dist && git commit --amend --no-edit 11# (optional) update/save dependency locks 12# * note: `yarn import` of 'package-lock.json' (when available) is faster but may not work for later versions of 'package-lock.json' 13rm -f package-lock.json yarn.lock 14npm install --package-lock 15yarn install 16mkdir .deps-lock 2> /dev/null 17cp package-lock.json .deps-lock/ 18cp yarn.lock .deps-lock/ 19git add .deps-lock 20git commit --amend --no-edit 21# tag VERSION commit 22git tag -f "v${VERSION}" 23# (optional) prerelease checkup 24npm run prerelease 25#=== * WinOS 26@rem # update project VERSION strings (package.json,...) 27@rem # * `bmp --[major|minor|patch]`; next VERSION in M.m.r (semver) format 28bmp --minor 29for /f %G in (VERSION) do @set "VERSION=%G" 30git-changelog --next-tag "v%VERSION%" > CHANGELOG.mkd 31@rem # create/commit updates and distribution 32git add package.json CHANGELOG.mkd README.md VERSION .bmp.yml 33git commit -m "%VERSION%" 34npm run clean && npm run update:dist && git add dist && git commit --amend --no-edit 35@rem # (optional) update/save dependency locks 36@rem # * note: `yarn import` of 'package-lock.json' (when available) is faster but may not work for later versions of 'package-lock.json' 37del package-lock.json yarn.lock 2>NUL 38npm install --package-lock 39yarn install 40mkdir .deps-lock 2>NUL 41copy /y package-lock.json .deps-lock >NUL 42copy /y yarn.lock .deps-lock >NUL 43git add .deps-lock 44git commit --amend --no-edit 45@rem # tag VERSION commit 46git tag -f "v%VERSION%" 47@rem # (optional) prerelease checkup 48npm run prerelease
1# publish 2# * optional (will be done in 'prePublishOnly' by `npm publish`) 3npm run clean && npm run test && npm run dist && git-changelog > CHANGELOG.mkd #expect exit code == 0 4git diff-index --quiet HEAD || echo "[lint] ERROR uncommitted changes" # expect no output and exit code == 0 5# * 6npm publish # `npm publish --dry-run` will perform all prepublication actions and stop just before the actual publish push 7# * if published to NPMjs with no ERRORs; push to deno.land with tag push 8git push origin --tags
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.
os-paths
... portable common OS/platform paths (home, temp, ...)xdg-app-paths
... easy XDG for applicationsxdg-basedir
... inspiration for this moduleWith the conversion to a TypeScript-based project, due to tooling constraints, building and testing are more difficult and more limited on Node platforms earlier than NodeJS-v10. However, the generated CommonJS/UMD project code is fully tested (for NodeJS-v10+) and continues to be compatible with NodeJS-v4+. ↩
The Deno.permissions
API (stabilized in Deno v1.8.0) is required to avoid needless panics or prompts by Deno during static imports of this module/package. Note: Deno v1.3.0+ may be used if the run flag --unstable
is also used. ↩
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
12 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More