Без опису

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. 'use strict';
  2. var path = require('path');
  3. var loadJsonFile = require('load-json-file');
  4. var normalizePackageData = require('normalize-package-data');
  5. var pathType = require('path-type');
  6. module.exports = function (fp, opts) {
  7. if (typeof fp !== 'string') {
  8. opts = fp;
  9. fp = '.';
  10. }
  11. opts = opts || {};
  12. return pathType.dir(fp)
  13. .then(function (isDir) {
  14. if (isDir) {
  15. fp = path.join(fp, 'package.json');
  16. }
  17. return loadJsonFile(fp);
  18. })
  19. .then(function (x) {
  20. if (opts.normalize !== false) {
  21. normalizePackageData(x);
  22. }
  23. return x;
  24. });
  25. };
  26. module.exports.sync = function (fp, opts) {
  27. if (typeof fp !== 'string') {
  28. opts = fp;
  29. fp = '.';
  30. }
  31. opts = opts || {};
  32. fp = pathType.dirSync(fp) ? path.join(fp, 'package.json') : fp;
  33. var x = loadJsonFile.sync(fp);
  34. if (opts.normalize !== false) {
  35. normalizePackageData(x);
  36. }
  37. return x;
  38. };