.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / node_modules / read-pkg / index.js
1 'use strict';
2 const path = require('path');
3 const loadJsonFile = require('load-json-file');
4 const pathType = require('path-type');
5
6 module.exports = (fp, opts) => {
7         if (typeof fp !== 'string') {
8                 opts = fp;
9                 fp = '.';
10         }
11
12         opts = opts || {};
13
14         return pathType.dir(fp)
15                 .then(isDir => {
16                         if (isDir) {
17                                 fp = path.join(fp, 'package.json');
18                         }
19
20                         return loadJsonFile(fp);
21                 })
22                 .then(x => {
23                         if (opts.normalize !== false) {
24                                 require('normalize-package-data')(x);
25                         }
26
27                         return x;
28                 });
29 };
30
31 module.exports.sync = (fp, opts) => {
32         if (typeof fp !== 'string') {
33                 opts = fp;
34                 fp = '.';
35         }
36
37         opts = opts || {};
38         fp = pathType.dirSync(fp) ? path.join(fp, 'package.json') : fp;
39
40         const x = loadJsonFile.sync(fp);
41
42         if (opts.normalize !== false) {
43                 require('normalize-package-data')(x);
44         }
45
46         return x;
47 };