.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / cosmiconfig / dist / loadPackageProp.js
1 //      
2 'use strict';
3
4 const path = require('path');
5 const readFile = require('./readFile');
6 const parseJson = require('./parseJson');
7
8 module.exports = function loadPackageProp(
9   packageDir        ,
10   options   
11                         
12                    
13    
14 )                                                     {
15   const packagePath = path.join(packageDir, 'package.json');
16
17   function parseContent(content         )                      {
18     if (!content) return null;
19     const parsedContent = parseJson(content, packagePath);
20     const packagePropValue = parsedContent[options.packageProp];
21     if (!packagePropValue) return null;
22
23     return {
24       config: packagePropValue,
25       filepath: packagePath,
26     };
27   }
28
29   return !options.sync
30     ? readFile(packagePath).then(parseContent)
31     : parseContent(readFile.sync(packagePath));
32 };