/* eslint valid-typeof: 0
965271
function TypeCheckExtended(parameter, type, required = true, format = null) {
  /*
  Used at top of functions to validate type of parameters received.
    parameter  <-----  Any (The parameter that's being checked)
    type       <-----  String (See types)
    required   <-----  String (If not required, value must be falsey to pass check)
    format     <-----  Array (used by enum)

  To allow intuitive type checking, TypeCheck alters default JS 'typeof' as follows:
    'array': now independent type separate from object
    'object': now excludes objects that are also arrays
    'enum': ensures parameter is in specfied array. Pass allowed values as 'format'
  */
  const types = [
    'array',
    'boolean',
    'enum',
    'function',
    'number',
    'object',
    'string',
    'symbol',
    'undefined',
  ];

  const extendedTypes = ['array', 'enum'];

  if (!types.includes(type)) {
    throw new Error(`TypeCheck Error: (${type}) is not a valid type.`);
  }

  if (required || (!required && parameter)) {
    // Differentiate between arrays and non-array objects
    if (
      (type === 'array' && !Array.isArray(parameter)) ||
      (type === 'object' && Array.isArray(parameter))
    ) {
      throw new Error(`TypeCheck Error: (${parameter}) should be ${type}`);
    }

    // Enum Checks
    if (type === 'enum') {
      if (format.includes(parameter)) {
        return true;
      }
      throw new Error(`TypeCheck Error: (${parameter}) is invalid enum.`);
    }

    if (!extendedTypes.includes(type) && typeof parameter !== type) {
      throw new Error(`TypeCheck Error: (${parameter}) should be ${type}`);
    }
  }

  return true;
}
1003762
function typeName(item) {
  if (isNull(item)) {
    return "null";
  }
  else if (isUndefined(item)) {
    return "undefined";
  }

  return /\[.+ ([^\]]+)/.exec(toString(item))[1].toLowerCase();
}
330174
function validate (type, value) {
  const { t } = readType(type)
  if (value === undefined || value === null) return { require: true }

  switch (t) {
    case SOPHIA_TYPES.int:
      return isNaN(value) || ['boolean'].includes(typeof value)
    case SOPHIA_TYPES.bool:
      return typeof value !== 'boolean'
    case SOPHIA_TYPES.address:
      return !(value[2] === '_' && ['ak', 'ct'].includes(value.slice(0, 2)))
    default:
      return false
  }
}
1327559
function (type, fn) {
  var result;
  try {
    result = fn();
  }
  catch (e) {
    result = {error: e};
  }

  if (result && !result.type && type)
    result.type = type;

  return result;
}
1280270
function checkTypeOf(variable, expectedType) {
    // @ts-ignore
    expectedType = expectedType.toLowerCase();
    if (typeof variable !== expectedType)
        throw new Error('Input must be ' + expectedType);
}
920752
function isValid (type, value) {
      switch (type) {
        case 'email':
          return validator.isEmail(value);
          break;
        case 'url':
          return validator.isURL(value);
          break;
        case 'domain':
          return validator.isFQDN(value);
          break;
        case 'ip':
          return validator.isIP(value);
          break;
        case 'alpha':
          return validator.isAlpha(value);
          break;
        case 'number':
          return validator.isNumeric(value);
          break;
        case 'alphanumeric':
          return validator.isAlphanumeric(value);
          break;
        case 'base64':
          return validator.isBase64(value);
          break;
        case 'hexadecimal':
          return validator.isHexadecimal(value);
          break;
        case 'hexcolor':
          return validator.isHexColor(value);
          break;
        case 'int':
          return validator.isInt(value);
          break;
        case 'float':
          return validator.isFloat(value);
          break;
        case 'null':
          return validator.isNull(value);
          break;
        case 'uuid':
          return validator.isUUID(value);
          break;
        case 'date':
          return validator.isDate(value);
          break;
        case 'creditcard':
          return validator.isCreditCard(value);
          break;
        case 'isbn':
          return validator.isISBN(value);
          break;
        case 'mobilephone':
          return validator.isMobilePhone(value);
          break;
        case 'json':
          return validator.isJSON(value);
          break;
        case 'ascii':
          return validator.isAscii(value);
          break;
        case 'mongoid':
          return validator.isMongoId(value);
          break;
        default:
          return false;
          break;
      }
    }
266864
function isValidId(value :any) :boolean {

  return Object.prototype.toString.call(value) === STRING_TAG && value.length > 0;
}
690114
function typeName( error ) {
	var i;
	for ( i = 0; i < CTORS.length; i++ ) {
		if ( error instanceof CTORS[ i ][ 0 ] ) {
			return CTORS[ i ][ 1 ];
		}
	}
}
1165775
function typeOf (value) {
  if (value === null) return 'null'
  var valueType = typeof value
  if (valueType === 'object') {
    valueType = value.constructor.name.toLowerCase()
  }
  return valueType
}
1111087
function validate(key, values) {
  if(this.arity > 0 && values.length !== this.arity) {
    throw new TypeDefError(
      util.format('bad arity for \'%s\', expected %s got %s',
        key, this.arity, values.length));
  }
  var types = Array.isArray(this.type) ? this.type : [this.type]
    , i
    , type
    , val
    , num
    , coerced = []
    , enumerable = false;

  for(i = 0;i < types.length;i++) {
    type = types[i];
    val = values[i];
    enumerable = Array.isArray(type);
    if(enumerable) {
      if(!~type.indexOf(val)) {
        throw new TypeDefError(
          util.format('enum error on key \'%s\', got \'%s\' expected one of %s',
            key, val, type.join(', ')));
      }
    }
    switch(type) {
      case ByteSize:
        val = ByteSize.parse(val);
        break;
      case Boolean:
        if(val !== YES && val !== NO) {
          throw new Error(
            util.format('argument must be \'%s\' or \'%s\'', YES, NO));
        }
        val = val === YES ? true : false;
        break;
      case String:
        // strings can be quoted
        val = val.replace(/^"/, '').replace(/"$/, '');
        break;
      case Number:
        num = parseInt(val);
        if(isNaN(num) || !/^-?[0-9]+$/.test(val)) {
          throw new TypeDefError(
            util.format('number expected for \'%s\', got %s', key, val));
        }
        val = num;
        break;
    }

    coerced[i] = val;
  }
  if(this.arity === 1 && !this.repeats) return coerced[0];
  return Array.isArray(this.type) ? coerced : coerced[0];
}
570609
function _any(o) {
        if (typeof o!=='object') throw new Error('Invalid Arg: not an object');
        // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
        if (Object.keys(o).length===0) return false;
        for (var x in o) {
          if (o[x]!==null && !/undefined|boolean/.test(typeof o[x]) || typeof o[x]==='boolean' && o[x].toString()!=='false') {
            return true;
          }
        }
        return false;
      }
737374
function typeOf (value) {
  var type = {
    hasValue: false,
    isArray: false,
    isPOJO: false,
    isNumber: false,
  };

  if (value !== undefined && value !== null) {
    type.hasValue = true;
    var typeName = typeof value;

    if (typeName === 'number') {
      type.isNumber = !isNaN(value);
    }
    else if (Array.isArray(value)) {
      type.isArray = true;
    }
    else {
      type.isPOJO =
        (typeName === 'object') &&
        !(value instanceof RegExp) &&
        !(value instanceof Date);
    }
  }

  return type;
}
51657
function (value, node) {
        var valid = false;
        if (typeof value === (node.name === "component" ? "object" : "function"))
            valid = (_cs.annotation(value, "type") === node.name);
        return valid;
    }
881752
function Function_(types) {
    var tuples = Z.reduce (function(tuples, t) {
      tuples.push (['$' + show (tuples.length + 1), K ([]), t]);
      return tuples;
    }, [], types);

    function format(outer, inner) {
      return when (tuples.length !== 2)
                  (parenthesize (outer))
                  (joinWith (outer (', '),
                             Z.map (function(tuple) {
                               return when (tuple[2].type === FUNCTION)
                                           (parenthesize (outer))
                                           (inner (tuple[0])
                                                  (show (tuple[2])));
                             }, init (tuples)))) +
             outer (' -> ') +
             inner ((last (tuples))[0])
                   (show ((last (tuples))[2]));
    }

    return _Type (FUNCTION,
                  '',
                  '',
                  types.length,
                  format,
                  [AnyFunction],
                  K (K (true)),
                  tuples);
  }
29101
function $$safeEvalFn(str) {
    let keyStr = '';

    // Perform any parsing that needs to be performed on the scope value
    for (let key in this) {
        let val = this[ key ];
        if (!val && val !== 0 && val !== '') {
            continue;
        } else if (
            typeof val === 'symbol' ||
            typeof val === 'string'
        ) {
            val = `"${val}"`;
        } else if (typeof val === 'object') {
            val = JSON.stringify(val);
        }

        // I don't like having to use var here
        keyStr += `var ${key}=${val};`;
    }

    // Literal eval is executed in its own context here to reduce security issues
    /* eslint-disable */
    return eval([ keyStr, str ].join(''));

    /* eslint-enable */
}
812977
function( type ) {
    type = ( type + '' ).toLowerCase()
    return Array.isArray( this.type ) ?
      this.type.indexOf( type ) >= 0 :
      this.type === type
  }
880459
function __typeCheck(type, valueToCheck, optional) {
    var correct = typeof(valueToCheck) == type;
    if(optional) {
        // Exception if the variable is optional, than it also may be undefined or null
        correct = correct || valueToCheck === undefined || valueToCheck === null;
    }
    if(!correct) {
        throw new Error("Invalid argument type received; expected "+type+
            ", but received "+typeof(valueToCheck));
    }
}