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/anchor/index.js
/**
 * Module dependencies
 */

var _ = require('@sailshq/lodash');
var match = require('./lib/match');


/**
 * Public access
 */

module.exports = function (entity, ruleset) {

  var errors = [];

  // If ruleset doesn't contain any explicit rule keys,
  // assume that this is a type

  // Look for explicit rules
  for (var rule in ruleset) {


    // TODO: In next major version, remove this: It should definitely not be here.
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    // Normalize the value if it looks like a boolean
    if(ruleset[rule] === 'true') {
      ruleset[rule] = true;
    }

    if(ruleset[rule] === 'false') {
      ruleset[rule] = false;
    }
    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    // If the value is false, then we shouldn't even run the validation
    if(ruleset[rule] === false) {
      break;
    }

    // If the rule value is a boolean we don't need to pass the value along.
    // Otherwise we can pass it along so it's options are available in
    // the validation.
    var ruleVal = _.isBoolean(ruleset[rule]) ? undefined : ruleset[rule];
    errors = errors.concat(match(entity, rule, ruleVal));

  }

  // If errors exist, return the list of them
  if (errors.length) {
    return errors;
  }

  // No errors, so return false
  else {
    return [];
  }

};