All files / piscosour/lib/utils search.js

100% Statements 19/19
87.5% Branches 7/8
100% Functions 4/4
100% Lines 19/19
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32    1x 1x 1x 1x   1x   4x 4x 4x 8x 8x 104x 104x 104x     4x     2x 52x 1x     2x       1x
'use strict';
 
const fsUtils = require('./fsUtils');
const constants = require('./constants');
const path = require('path');
const logger = require('../logger');
 
const search = {
  searchNpm(filter, options) {
    const data = fsUtils.readConfig(constants.npmFile);
    let result = [];
    constants.npmDependencies.forEach((attribute) => {
      Eif (data && data[attribute]) {
        result = result.concat(Object.getOwnPropertyNames(data[attribute]).map((name) => {
          logger.trace('Looking into', name);
          return filter(fsUtils.readConfig(path.join(constants.npmFolder, name, constants.npmFile)), options);
        }).filter((element) => element));
      }
    });
    return result;
  },
  searchByKeyword(keyword) {
    const filter = (module, options) => {
      if (module.keywords && module.keywords.indexOf(options.keyword) >= 0) {
        return module;
      }
    };
    return search.searchNpm(filter, {keyword: keyword});
  }
};
 
module.exports = search;