npm-view
选择命令行版本:
See Details
目录
概要
¥Synopsis
npm view [<package-spec>] [<field>[.subfield]...]aliases: info, show, v
描述
¥Description
此命令显示有关包的数据并将其打印到标准输出。
¥This command shows data about a package and prints it to stdout.
例如,要从注册表中查看有关 connect
包的信息,你可以运行:
¥As an example, to view information about the connect
package from the registry, you would run:
npm view connect
如果未指定,则默认版本为 "latest"
。
¥The default version is "latest"
if unspecified.
可以在包描述符之后指定字段名称。例如,要显示 0.3.5
版本的 ronn
包的依赖,你可以执行以下操作:
¥Field names can be specified after the package descriptor. For example, to show the dependencies of the ronn
package at version 0.3.5
, you could do the following:
npm view ronn@0.3.5 dependencies
默认情况下,npm view
显示有关当前项目上下文的数据(通过查找 package.json
)。要显示当前项目的字段数据,请使用文件路径(即 .
):
¥By default, npm view
shows data about the current project context (by looking for a package.json
). To show field data for the current project use a file path (i.e. .
):
npm view . dependencies
你可以通过用句点分隔子字段来查看子 字段。要查看最新版本 npm
的 git 存储库 URL,你将运行以下命令:
¥You can view child fields by separating them with a period. To view the git repository URL for the latest version of npm
, you would run the following command:
npm view npm repository.url
这使得使用一些 shell 脚本可以轻松查看有关依赖的信息。例如,要查看 ronn
所依赖的 opts
版本的所有数据,可以这样写:
¥This makes it easy to view information about a dependency with a bit of shell scripting. For example, to view all the data about the version of opts
that ronn
depends on, you could write the following:
npm view opts@$(npm view ronn dependencies.opts)
对于数组字段,请求非数字字段将返回列表中对象的所有值。例如,要获取 express
包的所有贡献者电子邮件地址,你可以运行:
¥For fields that are arrays, requesting a non-numeric field will return all of the values from the objects in the list. For example, to get all the contributor email addresses for the express
package, you would run:
npm view express contributors.email
你还可以在方括号中使用数字索引来专门选择数组字段中的项目。要获取列表中第一个贡献者的电子邮件地址,你可以运行:
¥You may also use numeric indices in square braces to specifically select an item in an array field. To just get the email address of the first contributor in the list, you can run:
npm view express contributors[0].email
如果你要查询的字段值是对象的属性,你应该运行:
¥If the field value you are querying for is a property of an object, you should run:
npm view express time'[4.8.0]'
可以指定多个字段,并且将一个接一个地打印。例如,要获取所有贡献者名称和电子邮件地址,你可以这样做: