Initial commit
[yaffs-website] / node_modules / read-pkg / index.js
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
7 module.exports = function (fp, opts) {
8         if (typeof fp !== 'string') {
9                 opts = fp;
10                 fp = '.';
11         }
12
13         opts = opts || {};
14
15         return pathType.dir(fp)
16                 .then(function (isDir) {
17                         if (isDir) {
18                                 fp = path.join(fp, 'package.json');
19                         }
20
21                         return loadJsonFile(fp);
22                 })
23                 .then(function (x) {
24                         if (opts.normalize !== false) {
25                                 normalizePackageData(x);
26                         }
27
28                         return x;
29                 });
30 };
31
32 module.exports.sync = function (fp, opts) {
33         if (typeof fp !== 'string') {
34                 opts = fp;
35                 fp = '.';
36         }
37
38         opts = opts || {};
39         fp = pathType.dirSync(fp) ? path.join(fp, 'package.json') : fp;
40
41         var x = loadJsonFile.sync(fp);
42
43         if (opts.normalize !== false) {
44                 normalizePackageData(x);
45         }
46
47         return x;
48 };