HEX
Server: nginx/1.24.0
System: Linux nowruzgan 6.8.0-57-generic #59-Ubuntu SMP PREEMPT_DYNAMIC Sat Mar 15 17:40:59 UTC 2025 x86_64
User: babak (1000)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: /var/dev/nowruzgan/rest/node_modules/rttc/lib/is-invalid-example.js
/**
 * Module dependencies
 */

var _ = require('lodash');
var infer = require('./infer');


/**
 * isInvalidExample()
 *
 * Although `undefined` technically is inferred as "ref", this function
 * considers it an invalid example
 *
 * @param  {*} example
 * @return {===} truthy if the provided example is invalid,
 *               false otherwise.
 */
module.exports = function isInvalidExample(example){

  if (_.isUndefined(example)) {
    return new Error('Invalid example: `undefined` is not a valid example.');
  }
  try {
    var typeSchema = infer(example);
    if (_.isUndefined(typeSchema) || _.isNull(typeSchema)) {
      return new Error('Invalid example: could not infer type schema.');
    }
  }
  catch (e) {
    return e;
  }

  return false;
};