lib/overload.js
function compatible(value, descriptor) {
  if (!value) {
    // If we're a null, then we can't validate.
    return false;
  } else if (!descriptor) {
    return true;
  }

  const descriptorType = typeof descriptor;
  if (descriptorType === 'string') {
    return typeof value === descriptor;
  } else if (descriptorType === 'function') {
    return descriptor(value);
  } else if (descriptorType === 'object') {
    let matched = true;
    Object.keys(descriptor).forEach((key) => {
      const fromValue = value[key];
      const fromDescriptor = descriptor[key];
      if (!compatible(fromValue, fromDescriptor)) {
        matched = false;
      }
    });
    return matched;
  }

  throw new Error('Unknown descriptor type: ' + descriptorType);
}
function compatible(value, descriptor) {
  if (!value) {
    // If we're a null, then we can't validate.
    return false;
  } else if (!descriptor) {
    return true;
  }

  const descriptorType = typeof descriptor;
  if (descriptorType === 'string') {
    return typeof value === descriptor;
  } else if (descriptorType === 'function') {
    return descriptor(value);
  } else if (descriptorType === 'object') {
    let matched = true;
    Object.keys(descriptor).forEach((key) => {
      const fromValue = value[key];
      const fromDescriptor = descriptor[key];
      if (!compatible(fromValue, fromDescriptor)) {
        matched = false;
      }
    });
    return matched;
  }

  throw new Error('Unknown descriptor type: ' + descriptorType);
}
function compatible ( value , descriptor ) { if ( ! value ) { // If we're a null, then we can't validate. return false ; } else if ( ! descriptor ) { return true ; } const descriptorType = typeof descriptor ; if ( descriptorType === 'string' ) { return typeof value === descriptor ; } else if ( descriptorType === 'function' ) { return descriptor ( value ) ; } else if ( descriptorType === 'object' ) { let matched = true ; Object . keys ( descriptor ) . forEach ( ( key ) => { const fromValue = value [ key ] ; const fromDescriptor = descriptor [ key ] ; if ( ! compatible ( fromValue , fromDescriptor ) ) { matched = false ; } } ) ; return matched ; } throw new Error ( 'Unknown descriptor type: ' + descriptorType ) ; }
Is the specified value equivelent to the descriptor?
@param {object}      value       - Value to check.
@param {object}      descriptor  - Descriptor to compare to.
@returns {Boolean}               - True if equivelent.
Is the specified value equivelent to the descriptor?