all files / lib/ utils.js

100% Statements 21/21
81.82% Branches 9/11
100% Functions 6/6
100% Lines 15/15
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        40× 40×     208× 328× 172×   156× 120×     328×       48×                                 61×     12×    
/**
 * Tools
 */
 
export function clone ({ children, ...source }) {
  return source ? JSON.parse( JSON.stringify( source ) ) : {};
}
 
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);
}
 
export function forEach ( arr, fn ) {
  Array.prototype.slice.call( arr || [] ).forEach( fn );
}
 
/**
 * Validation
 */
 
// const VALID_PROPS = ['title', 'description', 'canonical', 'meta', 'link'];
 
// export function isValidProp ( propKey ) {
//   return ~VALID_PROPS.indexOf( propKey );
// }
 
/**
 * Document manipulation
 */
 
function removeNode ( node ) {
  node.parentNode.removeChild(node);
}
 
export function removeDocumentMeta () {
  forEach(document.querySelectorAll('head [data-rdm]'), removeNode);
}