all files / src/validators/ valid-values.js

100% Statements 6/6
100% Branches 2/2
100% Functions 1/1
100% Lines 6/6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21                    10×          
'use strict';
 
const inArray = require('in-array');
 
/**
 * Determines whether a node has a valid value
 * @param  {object} packageJsonData Valid JSON
 * @param  {string} nodeName        Name of a node in the package.json file
 * @param  {array}  validValues     Array of valid values to validate against
 * @return {boolean}                True if the node is equal to one of the valid values or is missing. False if it is not.
 */
const isValidValue = function(packageJsonData, nodeName, validValues) {
  if (!packageJsonData.hasOwnProperty(nodeName)) {
    return true;
  }
 
  return inArray(validValues, packageJsonData[nodeName]);
};
 
module.exports.isValidValue = isValidValue;