npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@yarn-tool/npa-to-deps

v3.0.7

Published

Convert npm-package-arg results to dependency values / 將 npm-package-arg 結果轉換為依賴值

Readme

@yarn-tool/npa-to-deps

Convert npm-package-arg (npa) parsing results to standardized dependency value objects. 將 npm-package-arg (npa) 解析結果轉換為標準化的依賴值物件。

Features / 功能特點

  • Handles various input types including git URLs, version tags, semver ranges, and local file paths / 處理各種輸入類型,包括 git URL、版本標籤、semver 範圍和本地檔案路徑
  • Converts npm-package-arg results to standardized dependency objects / 將 npm-package-arg 結果轉換為標準化的依賴物件
  • Supports options for preserving tags and ranges / 支援保留標籤和範圍的選項

Install / 安裝

yarn add @yarn-tool/npa-to-deps
yarn-tool add @yarn-tool/npa-to-deps
yt add @yarn-tool/npa-to-deps

Usage / 使用方式

import { npaToDepsValue, npaResultToDepsValue } from '@yarn-tool/npa-to-deps';
import { npa } from '@yarn-tool/npm-package-arg-util';

// Parse and convert in one step
// 一步完成解析和轉換
const deps = npaToDepsValue('lodash@^4.17.0');
// => { name: 'lodash', operator: '^', fetchQuery: true, result: ... }

// With preserveTag option
// 使用 preserveTag 選項
const tagDeps = npaToDepsValue('lodash@latest', { preserveTag: true });
// => { name: 'lodash', semver: 'latest', result: ... }

// Convert existing npa result
// 轉換現有的 npa 結果
const result = npa('github:user/repo#branch');
const gitDeps = npaResultToDepsValue(result);
// => { name: 'repo', semver: 'github:user/repo#branch', result: ... }

API / API 文件

npaToDepsValue<T>(arg: string, options?: IOptions): IDepsResult<T>

Parse a package argument string and convert to dependency value. 解析套件參數字串並轉換為依賴值。

Parameters / 參數:

  • arg - The package argument string to parse / 要解析的套件參數字串
  • options - Parsing and conversion options / 解析和轉換選項
    • where - Base directory for resolving relative paths / 解析相對路徑的基礎目錄
    • preserveTag - Preserve tag instead of converting to ^ / 保留標籤而不是轉換為 ^
    • preserveRange - Preserve original range instead of normalizing / 保留原始範圍而不是正規化

Returns / 返回:

  • Standardized dependency value object / 標準化的依賴值物件

npaResultToDepsValue<T>(result: T, options?: IOptions): IDepsResult<T>

Convert an npm-package-arg result to a dependency value object. 將 npm-package-arg 結果轉換為依賴值物件。

Parameters / 參數:

  • result - The npm-package-arg parsing result / npm-package-arg 解析結果
  • options - Conversion options / 轉換選項

IOptions Interface

interface IOptions {
  where?: string;           // Base directory for resolving relative paths
  preserveTag?: boolean;    // Preserve tag instead of converting to ^
  preserveRange?: boolean;  // Preserve original range
}

IDepsResult<T> Interface

interface IDepsResult<T> {
  name: string;         // Package name / 套件名稱
  semver?: string;      // Semantic version string / 語義化版本字串
  operator?: string;    // Version operator (^, ~, >=) / 版本運算子
  fetchQuery?: boolean; // Whether to fetch from registry / 是否從 registry 查詢
  result: T;            // Original npm-package-arg result / 原始結果
}

Examples / 範例

Git Repository / Git 儲存庫

const result = npa('github:user/repo#branch');
npaResultToDepsValue(result);
// => { name: 'repo', semver: 'github:user/repo#branch', result: ... }

Version Tag / 版本標籤

// Default behavior - convert to ^
// 預設行為 - 轉換為 ^
npaToDepsValue('lodash@latest');
// => { name: 'lodash', operator: '^', fetchQuery: true, ... }

// Preserve tag
// 保留標籤
npaToDepsValue('lodash@latest', { preserveTag: true });
// => { name: 'lodash', semver: 'latest', ... }

Semver Range / Semver 範圍

npaToDepsValue('lodash@^4.17.0');
// => { name: 'lodash', operator: '^', fetchQuery: true, ... }

npaToDepsValue('lodash@>=4.0.0 <5.0.0');
// => { name: 'lodash', semver: '>=4.0.0 <5.0.0', ... }

Exact Version / 精確版本

npaToDepsValue('[email protected]');
// => { name: 'lodash', semver: '4.17.21', ... }

Related / 相關專案

License / 授權

ISC