You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

readme.md 3.5KB

4 anni fa
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # package-json [![Build Status](https://travis-ci.org/sindresorhus/package-json.svg?branch=master)](https://travis-ci.org/sindresorhus/package-json)
  2. > Get metadata of a package from the npm registry
  3. ## Install
  4. ```
  5. $ npm install package-json
  6. ```
  7. ## Usage
  8. ```js
  9. const packageJson = require('package-json');
  10. (async () => {
  11. console.log(await packageJson('ava'));
  12. //=> {name: 'ava', ...}
  13. // Also works with scoped packages
  14. console.log(await packageJson('@sindresorhus/df'));
  15. })();
  16. ```
  17. ## API
  18. ### packageJson(packageName, options?)
  19. #### packageName
  20. Type: `string`
  21. Name of the package.
  22. #### options
  23. Type: `object`
  24. ##### version
  25. Type: `string`<br>
  26. Default: `latest`
  27. Package version such as `1.0.0` or a [dist tag](https://docs.npmjs.com/cli/dist-tag) such as `latest`.
  28. The version can also be in any format supported by the [semver](https://github.com/npm/node-semver) module. For example:
  29. - `1` - Get the latest `1.x.x`
  30. - `1.2` - Get the latest `1.2.x`
  31. - `^1.2.3` - Get the latest `1.x.x` but at least `1.2.3`
  32. - `~1.2.3` - Get the latest `1.2.x` but at least `1.2.3`
  33. ##### fullMetadata
  34. Type: `boolean`<br>
  35. Default: `false`
  36. By default, only an abbreviated metadata object is returned for performance reasons. [Read more.](https://github.com/npm/registry/blob/master/docs/responses/package-metadata.md)
  37. ##### allVersions
  38. Type: `boolean`<br>
  39. Default: `false`
  40. Return the [main entry](https://registry.npmjs.org/ava) containing all versions.
  41. ##### registryUrl
  42. Type: `string`<br>
  43. Default: Auto-detected
  44. The registry URL is by default inferred from the npm defaults and `.npmrc`. This is beneficial as `package-json` and any project using it will work just like npm. This option is **only** intended for internal tools. You should **not** use this option in reusable packages. Prefer just using `.npmrc` whenever possible.
  45. ##### agent
  46. Type: `http.Agent | https.Agent | object | false`
  47. Overwrite the `agent` option that is passed down to [`got`](https://github.com/sindresorhus/got#agent). This might be useful to add [proxy support](https://github.com/sindresorhus/got#proxies).
  48. ### packageJson.PackageNotFoundError
  49. The error thrown when the given package name cannot be found.
  50. ### packageJson.VersionNotFoundError
  51. The error thrown when the given package version cannot be found.
  52. ## Authentication
  53. Both public and private registries are supported, for both scoped and unscoped packages, as long as the registry uses either bearer tokens or basic authentication.
  54. ## Related
  55. - [package-json-cli](https://github.com/sindresorhus/package-json-cli) - CLI for this module
  56. - [latest-version](https://github.com/sindresorhus/latest-version) - Get the latest version of an npm package
  57. - [pkg-versions](https://github.com/sindresorhus/pkg-versions) - Get the version numbers of a package from the npm registry
  58. - [npm-keyword](https://github.com/sindresorhus/npm-keyword) - Get a list of npm packages with a certain keyword
  59. - [npm-user](https://github.com/sindresorhus/npm-user) - Get user info of an npm user
  60. - [npm-email](https://github.com/sindresorhus/npm-email) - Get the email of an npm user
  61. ---
  62. <div align="center">
  63. <b>
  64. <a href="https://tidelift.com/subscription/pkg/npm-package-json?utm_source=npm-package-json&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
  65. </b>
  66. <br>
  67. <sub>
  68. Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
  69. </sub>
  70. </div>