All files utils.js

90.91% Statements 10/11
100% Branches 11/11
100% Functions 4/4
90.91% Lines 10/11
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                  71x 71x                 210x 325x 200x 125x         92x     325x             86x 61x      
export function clone({
  title,
  description,
  base,
  canonical,
  meta,
  link,
  auto
}) {
  try {
    return JSON.parse(
      JSON.stringify({ title, description, base, canonical, meta, link, auto })
    );
  } catch (x) {
    return {};
  }
}
 
export function defaults(target, source) {
  return Object.keys(source).reduce((acc, key) => {
    if (!target.hasOwnProperty(key)) {
      target[key] = source[key];
    } else if (
      typeof target[key] === 'object' &&
      !Array.isArray(target[key]) &&
      target[key]
    ) {
      defaults(target[key], source[key]);
    }
 
    return target;
  }, target);
}
 
// This is needed as not all browsers,
// including Edge and IE has not implemented .forEach() on NodeList
export function forEach(nodes, fn) {
  if (nodes && nodes.length) {
    Array.prototype.slice.call(nodes).forEach(fn);
  }
}