项目作者: xan105

项目描述 :
Windows user shell folders
高级语言: JavaScript
项目地址: git://github.com/xan105/node-usershellfolder.git
创建时间: 2021-05-11T16:13:35Z
项目社区:https://github.com/xan105/node-usershellfolder

开源协议:MIT License

下载


About

User shell folders.

Example

  1. import { folders } from "@xan105/usershellfolder";
  2. const path = folders.user.desktop;
  3. console.log(path);
  4. //Win: C:\Users\Xan\Desktop
  5. //Linux: /home/Xan/Desktop

Install

  1. npm install @xan105/usershellfolder

API

⚠️ This module is only available as an ECMAScript module (ESM).

Named export

const folders = object

Windows

On Windows return an object as the following:

  1. {
  2. root: ...,
  3. temp: ...,
  4. user: {
  5. appData: ...,
  6. localAppData: ...,
  7. home: ...,
  8. desktop: ...,
  9. documents: ...,
  10. music: ...,
  11. pictures: ...,
  12. videos: ...,
  13. download: ...,
  14. savegame: ...
  15. },
  16. common: {
  17. appData: ...,
  18. home: ...,
  19. desktop: ...,
  20. documents: ...,
  21. music: ...,
  22. pictures: ...,
  23. videos: ...
  24. }
  25. }

Linux

On Linux return an object as the following:

  1. {
  2. root: ...,
  3. temp: ...,
  4. user: {
  5. data: ...,
  6. config: ...,
  7. cache: ...,
  8. home: ...,
  9. desktop: ...,
  10. documents: ...,
  11. music: ...,
  12. pictures: ...,
  13. videos: ...,
  14. download: ...
  15. }
  16. }

expand(string: string, map?: object = process.env) string

Expand replaces %VAR% in the string based on the mapping object.

If no mapping object is provided then it uses process.env.

Example:

  1. import { expand, folders } from "@xan105/usershellfolder";
  2. expand("%DOCUMENTS%", folders.user); //C:\\Users\\Xan\\Documents
  3. expand("%APPDATA%"); //C:\\Users\\Xan\\AppData
  4. expand("%USER%", { USER: "foo" }) //foo
  5. expand("%USER%", { user: "foo" }) //foo
  6. expand("%USER%", { FOO: "bar" }) //%USER%

Default export

Alias to const folders for backward compatibility