All files / src helpers.js

75% Statements 9/12
80% Branches 8/10
66.67% Functions 2/3
75% Lines 9/12

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 389x     17x 3x   14x         14x 6x       14x             1x                 9x          
const { parse, stringify } = require('flatted/cjs');
 
function isNullOrEmpty(obj) {
  if (obj === undefined) {
    return true;
  }
  Iif (obj === null) {
    return true;
  }
  // Check for an empty array too
  // eslint-disable-next-line no-prototype-builtins
  if (obj.hasOwnProperty('length')) {
    Iif (obj.length === 0) {
      return true;
    }
  }
  return (Object.keys(obj).length === 0 && obj.constructor === Object);
}
 
// uses flatted library to allow stringifing on an object with circular references
// NOTE: This does not produce output similar to JSON.stringify, it has it's own format
// to allow you to stringify and parse and get back an object with circular references
function stringifySafe(obj) {
  return stringify(obj);
}
 
// this is the inverse of stringifySafe
// if converts a specially stringifyied string (created by stringifySafe) back into an object
function parseSafe(string) {
  return parse(string);
}
 
module.exports = {
  isNullOrEmpty,
  parseSafe,
  stringifySafe
};