all files / src/validators/ type.js

100% Statements 21/21
100% Branches 8/8
100% Functions 4/4
100% Lines 21/21
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65                                                          21×     13×                 22×     13×      
"use strict";
 
let isPlainObj = require("is-plain-obj");
 
/**
 * Determines whether or not the node's value is an Array
 * @param  {object} packageJsonData Valid JSON
 * @param  {string} nodeName        Name of a node in the package.json file
 * @return {boolean}                True if the node is an array or is missing. False if it is not.
 */
let isArray = function(packageJsonData, nodeName) {
  if (!packageJsonData.hasOwnProperty(nodeName)) {
    return true;
  }
 
  return Array.isArray(packageJsonData[nodeName]);
};
 
/**
 * Determines whether or not the node's value is a boolean
 * @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 boolean or is missing. False if it is not.
 */
let isBoolean = function(packageJsonData, nodeName) {
  if (!packageJsonData.hasOwnProperty(nodeName)) {
    return true;
  }
 
  return typeof packageJsonData[nodeName] === "boolean";
};
 
/**
 * Determines whether or not the node's value is an object
 * @param  {object} packageJsonData Valid JSON
 * @param  {string} nodeName        Name of a node in the package.json file
 * @return {boolean}                True if the node is an object or is missing. False if it is not.
 */
let isObject = function(packageJsonData, nodeName) {
  if (!packageJsonData.hasOwnProperty(nodeName)) {
    return true;
  }
 
  return isPlainObj(packageJsonData[nodeName]);
};
 
/**
 * Determines whether or not the node's value is a string
 * @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 string or is missing. False if it is not.
 */
let isString = function(packageJsonData, nodeName) {
  if (!packageJsonData.hasOwnProperty(nodeName)) {
    return true;
  }
 
  return typeof packageJsonData[nodeName] === "string";
};
 
module.exports.isArray = isArray;
module.exports.isBoolean = isBoolean;
module.exports.isObject = isObject;
module.exports.isString = isString;