# @yarn-tool/get-paths-by-type

> 根據類型 Symbol 取得對應的路徑陣列（支援全域 npm/yarn 路徑） / Get corresponding path array based on type Symbol (supports global npm/yarn paths)

Latest version **2.0.19** (published 2026-09-06) · ISC license · 0 weekly downloads

## Install

```sh
npm install @yarn-tool/get-paths-by-type
pnpm add @yarn-tool/get-paths-by-type
yarn add @yarn-tool/get-paths-by-type
bun add @yarn-tool/get-paths-by-type
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 2.0.19 |
| Published | 2026-09-06 |
| First published | 2021-10-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 31.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 14 |
| Author | bluelovers |
| Maintainers | bluelovers |
| Keywords | yarn-tool, get-paths, global-dirs, global-paths, symbol, path-resolver, npm-global, yarn-global, yarn, npm, workspaces, monorepo, node-modules, packages, package |

## Links

- npm: https://www.npmjs.com/package/@yarn-tool/get-paths-by-type
- Repository: https://github.com/bluelovers/ws-yarn-workspaces
- Homepage: https://github.com/bluelovers/ws-yarn-workspaces/tree/master/packages/@yarn-tool/get-paths-by-type#readme
- Issues: https://github.com/bluelovers/ws-yarn-workspaces/issues
- npm.io page: https://npm.io/package/@yarn-tool/get-paths-by-type

## Dependencies (3)

- [tslib](https://npm.io/package/tslib.md) >=2.8.1
- [@yarn-tool/fnm-detect](https://npm.io/package/@yarn-tool/fnm-detect.md) ^1.0.8
- [@yarn-tool/get-global-dirs](https://npm.io/package/@yarn-tool/get-global-dirs.md) ^1.0.6

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 2.0.19 (latest) — 2026-09-06
- 2.0.18 — 2026-04-26
- 2.0.17 — 2026-04-26
- 2.0.16 — 2026-03-12
- 2.0.14 — 2026-03-09
- 2.0.11 — 2026-03-02
- 2.0.10 — 2024-05-03
- 2.0.9 — 2022-12-09
- 2.0.8 — 2022-11-14
- 2.0.7 — 2022-10-01
- 2.0.6 — 2022-09-29
- 2.0.5 — 2022-09-27
- 2.0.4 — 2022-09-06
- 2.0.3 — 2022-08-26
- 2.0.2 — 2022-08-13
- … 4 more at https://npm.io/package/@yarn-tool/get-paths-by-type/versions

## README

# @yarn-tool/get-paths-by-type

根據類型 Symbol 取得對應的路徑陣列（支援全域 npm/yarn 路徑、當前目錄、主模組路徑）。
Get corresponding path array based on type Symbol (supports global npm/yarn paths, current directory, and main module path).

## 安裝 (Installation)

```bash
# 使用 yarn / Using yarn
yarn add @yarn-tool/get-paths-by-type

# 使用 yarn-tool / Using yarn-tool
yarn-tool add @yarn-tool/get-paths-by-type
# yt 是 yarn-tool 的別名 / yt is an alias for yarn-tool
yt add @yarn-tool/get-paths-by-type

# 使用 pnpm / Using pnpm
pnpm add @yarn-tool/get-paths-by-type

# 使用 npm / Using npm
npm install @yarn-tool/get-paths-by-type
```

## 使用範例 (Usage Example)

```typescript
import getPathsByType, {
  SymbolCurrentDirectory,
  SymbolGlobal,
  SymbolGlobalNpm,
  SymbolGlobalYarn,
  SymbolModuleMain,
} from '@yarn-tool/get-paths-by-type';

// 取得全域 Yarn 套件目錄 / Get global Yarn package directory
const yarnPaths = getPathsByType(SymbolGlobalYarn);
console.log(yarnPaths); // ['/usr/local/share/.config/yarn/global/node_modules']

// 取得全域 Npm 套件目錄 / Get global Npm package directory
const npmPaths = getPathsByType(SymbolGlobalNpm);
console.log(npmPaths); // ['/usr/local/lib/node_modules']

// 取得所有全域路徑（Yarn + Npm）/ Get all global paths (Yarn + Npm)
const globalPaths = getPathsByType(SymbolGlobal);
console.log(globalPaths); // [yarn packages path, npm packages path]

// 取得當前工作目錄 / Get current working directory
const cwdPaths = getPathsByType(SymbolCurrentDirectory);
console.log(cwdPaths); // [process.cwd()]

// 取得當前目錄（指定路徑）/ Get current directory (specified path)
const customCwdPaths = getPathsByType(SymbolCurrentDirectory, '/custom/path');

// 取得主模組路徑 / Get main module path
const mainModulePaths = getPathsByType(SymbolModuleMain);
```

## API

### `getPathsByType(valueType, cwd?)`

根據類型 Symbol 取得對應的路徑陣列。

**參數 (Parameters):**
- `valueType` - 路徑類型 Symbol / Path type Symbol
- `cwd` - 工作目錄（選填，用於 SymbolCurrentDirectory）/ Working directory (optional, for SymbolCurrentDirectory)

**返回 (Returns):** `string[]` - 路徑陣列 / Path array

### Symbol 類型 (Symbol Types)

| Symbol | 說明 / Description |
|--------|-------------------|
| `SymbolCurrentDirectory` | 當前工作目錄 / Current working directory |
| `SymbolGlobal` | 全域 Yarn + Npm 套件目錄 / Global Yarn + Npm package directories |
| `SymbolGlobalNpm` | 全域 Npm 套件目錄 / Global Npm package directory |
| `SymbolGlobalYarn` | 全域 Yarn 套件目錄 / Global Yarn package directory |
| `SymbolModuleMain` | 主模組的路徑 / Main module path |

## License

ISC

---
_Source: https://npm.io/package/@yarn-tool/get-paths-by-type · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
