HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux ip-10-0-8-47 6.8.0-1021-aws #23~22.04.1-Ubuntu SMP Tue Dec 10 16:31:58 UTC 2024 aarch64
User: ubuntu (1000)
PHP: 8.1.2-1ubuntu2.22
Disabled: NONE
Upload Files
File: /var/www/api.javaapp.co.uk_old/node_modules/node-input-validator/lib/rules/lengthBetween.js
const integer = require('./integer');

module.exports = function lengthBetween({ attr, value, args }) {
  if (args.length !== 2) {
    throw new Error(`The number of arguments for length between in the field ${attr} are invalid.`);
  }

  let [min, max] = args;

  const isIntMin = integer({ value: min });
  const isIntMax = integer({ value: max });

  if (!isIntMin || !isIntMax) {
    throw new Error('Seeds must be integer for lengthBetween rule.');
  }

  min = parseInt(min);
  max = parseInt(max);

  if (min >= max) {
    throw new Error('Seed min must be less then max in lengthBetween.');
  }

  // if (Array.isArray(attribute)) {

  //     if (attribute.length < min || attribute.length > max) {
  //         return false;
  //     }

  //     return true;
  // }

  if (typeof value === 'string' || Array.isArray(value)) {
    if (value.length < min || value.length > max) {
      return false;
    }

    return true;
  }

  return false;
};