all files / src/validators/ format.js

100% Statements 12/12
100% Branches 4/4
100% Functions 2/2
100% Lines 12/12
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 33 34 35 36                                               
"use strict";
 
const semver = require("semver");
const validator = require("validator");
 
/**
 * Determines whether or not the node's value is lowercase
 * @param  {object} packageJsonData Valid JSON
 * @param  {string} nodeName        Name of a node in the package.json file
 * @return {boolean}                True if the node is lowercase or is missing. False if it is not.
 */
const isLowercase = function(packageJsonData, nodeName) {
  if (!packageJsonData.hasOwnProperty(nodeName)) {
    return true;
  }
 
  return validator.isLowercase(packageJsonData[nodeName]);
};
 
/**
 * Determines whether or not the node's value is a valid semantic version
 * @param  {object} packageJsonData Valid JSON
 * @param  {string} nodeName        Name of a node in the package.json file
 * @return {boolean}                True if the node is a valid version number or is missing. False if it is not.
 */
const isValidVersionNumber = function(packageJsonData, nodeName) {
  if (!packageJsonData.hasOwnProperty(nodeName)) {
    return true;
  }
 
  return semver.valid(packageJsonData[nodeName]) !== null;
};
 
module.exports.isLowercase = isLowercase;
module.exports.isValidVersionNumber = isValidVersionNumber;