1
0
mirror of https://github.com/thangisme/notes.git synced 2024-11-01 07:27:19 -04:00
notes/node_modules/cosmiconfig/lib/loadPackageProp.js

22 lines
570 B
JavaScript
Raw Normal View History

2017-03-09 13:16:08 -05:00
'use strict';
var path = require('path');
var parseJson = require('parse-json');
var readFile = require('./readFile');
module.exports = function (packageDir, options) {
var packagePath = path.join(packageDir, 'package.json');
return readFile(packagePath).then(function (content) {
if (!content) return null;
var parsedContent = parseJson(content, packagePath);
var packagePropValue = parsedContent[options.packageProp];
if (!packagePropValue) return null;
return {
config: packagePropValue,
filepath: packagePath,
};
});
};