All files general.js

100% Statements 11/11
100% Branches 2/2
100% Functions 2/2
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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            1x 1x     1x   1x             3x                       5x 42x 42x 1x   41x     5x    
/**
 * General module for grocery-list project
 *
 * @module general
 */
 
const fs = require("fs");
const TC = require("title-case");
 
 
'use strict';
 
module.exports = {
  /**
   * Reads a text file into an array, where each line of the file denotes an element in the array
   * @param {string} fileName Path to file
   * @returns {string[]} File contents as an array
   */
  readFileIntoArray: function(fileName) {
    return fs.readFileSync(fileName).toString().split("\n");
  },
 
  /**
   * Filters duplicate values in two Objects. If an object already exists in the original
   * Object, the value is concatenated to the existing value
   *
   * @param existing_object {Object}
   * @param new_object {Object}
   * @returns {Object}
   */
  concatObjectMerge: function(existing_object, new_object) {
    for (const property in new_object) {
      const properKey = TC.titleCase(property);
      if (properKey in existing_object) {
        existing_object[properKey] += ", " + new_object[property];
      } else {
        existing_object[properKey] = new_object[property];
      }
    }
    return existing_object;
  }
};