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 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # read-pkg [![Build Status](https://travis-ci.org/sindresorhus/read-pkg.svg?branch=master)](https://travis-ci.org/sindresorhus/read-pkg)
  2. > Read a package.json file
  3. ## Why
  4. - [Gracefully handles filesystem issues](https://github.com/isaacs/node-graceful-fs)
  5. - [Strips UTF-8 BOM](https://github.com/sindresorhus/strip-bom)
  6. - [Throws more helpful JSON errors](https://github.com/sindresorhus/parse-json)
  7. - [Normalizes the data](https://github.com/npm/normalize-package-data#what-normalization-currently-entails)
  8. ## Install
  9. ```
  10. $ npm install --save read-pkg
  11. ```
  12. ## Usage
  13. ```js
  14. var readPkg = require('read-pkg');
  15. readPkg().then(function (pkg) {
  16. console.log(pkg);
  17. //=> {name: 'read-pkg', ...}
  18. });
  19. readPkg(__dirname).then(function (pkg) {
  20. console.log(pkg);
  21. //=> {name: 'read-pkg', ...}
  22. });
  23. readPkg(path.join('unicorn', 'package.json')).then(function (pkg) {
  24. console.log(pkg);
  25. //=> {name: 'read-pkg', ...}
  26. });
  27. ```
  28. ## API
  29. ### readPkg([path], [options])
  30. Returns a promise that resolves to the parsed JSON.
  31. ### readPkg.sync([path], [options])
  32. Returns the parsed JSON.
  33. #### path
  34. Type: `string`
  35. Default: `.`
  36. Path to a `package.json` file or its directory.
  37. #### options
  38. ##### normalize
  39. Type: `boolean`
  40. Default: `true`
  41. [Normalize](https://github.com/npm/normalize-package-data#what-normalization-currently-entails) the package data.
  42. ## Related
  43. - [read-pkg-up](https://github.com/sindresorhus/read-pkg-up) - Read the closest package.json file
  44. - [write-pkg](https://github.com/sindresorhus/write-pkg) - Write a `package.json` file
  45. - [load-json-file](https://github.com/sindresorhus/load-json-file) - Read and parse a JSON file
  46. ## License
  47. MIT © [Sindre Sorhus](http://sindresorhus.com)