How to use the validator.isInt function in validator

To help you get started, we’ve selected a few validator examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pro-grid / pro-grid / test / spec / server / server-tests.js View on Github external
function validateData(data, dimensions) {
    // yeah so what it's a long return statement why you talkin shit
    return validator.isInt(data.row) && validator.isInt(data.col) && validator.isHexColor(data.color) && data.row < dimensions && data.col < dimensions;
  }
github panitw / easy-rpm / tasks / lib / spec-validator.js View on Github external
function _validateNoGeneric(list, indices, result, messages) {
    var i, index, indexInt, hasError = false,
        hasWarning = false;
    for (i = 0; i < indices.length; i++) {
        // No need for duplicate errors and/or warnings.
        if (hasError && hasWarning) {
            return;
        }

        index = indices[i];
        if (!validator.isInt(index)) {
            result.errors.push(messages.nonIntegralError);
            hasError = true;
        } else {
            indexInt = validator.toInt(index);
            if (indexInt > (list.length - 1) || indexInt < 0) {
                result.warnings.push(messages.outOfRangeWarning);
                hasWarning = true;
            }
        }
    }
}
github daftspunk / pond / app / services / Provisioners / PondProvisionerBase.js View on Github external
async validateConfiguration(errorBag, websites) {
        if (validator.isEmpty(toSafeString(this.website.localPort))) {
            errorBag.add('localPort', 'websites.create_website.error_local_port_empty');
            return;
        }

        if (!validator.isInt(toSafeString(this.website.localPort))) {
            errorBag.add('localPort', 'websites.create_website.error_local_port_not_integer');
            return;
        }

        const otherWebsite = portFinder.isInUseByAWebsite(this.website.localPort, websites)
        if (otherWebsite && otherWebsite.id != this.website.id) {
            errorBag.add('localPort', 'websites.create_website.error_local_port_used_by_another_website');
            return;
        }

        try {
            await portFinder.isInUseByAnotherApp(this.website.localPort, '127.0.0.1');
        }
        catch (e) {
            if (this.website.runtime && this.website.runtime.status != ONLINE) {
                // If the port is in use by this very website and it's online,
github AugurProject / augur / test / MarketActions.js View on Github external
t.plan(29 + rawInfo.numOutcomes*8 + rawInfo.numEvents*11);
    t.false(rawInfo.id, "raw marketInfo's id field is unassigned");
    t.true(validator.isHexadecimal(abi.unfork(rawInfo._id)), "unfork(_id) is valid hex");
    t.true(validator.isNumeric(rawInfo.network), "network is numeric");
    t.true(validator.isIn(rawInfo.network, ["7", "10101"]), "network is 7 or 10101");
    t.true(validator.isInt(rawInfo.traderCount), "traderCount is an integer");
    t.true(rawInfo.traderIndex > -1, "traderIndex > -1");
    t.equal(rawInfo.alpha, "0.00790000000000000001", "alpha == 0.00790000000000000001");
    t.true(validator.isInt(rawInfo.tradingPeriod), "tradingPeriod is an integer");
    t.true(validator.isFloat(rawInfo.tradingFee), "tradingFee is a float");
    t.true(rawInfo.tradingFee > 0, "tradingFee > 0");
    t.true(rawInfo.tradingFee <= 1, "tradingFee <= 1");
    t.true(validator.isHexadecimal(abi.unfork(rawInfo.branchId)), "unfork(branchId) is valid hex");
    t.true(validator.isInt(rawInfo.numEvents), "numEvents is an integer");
    t.true(rawInfo.numEvents >= 1, "numEvents >= 1");
    t.true(validator.isInt(rawInfo.cumulativeScale), "cumulativeScale is a (string) integer");
    t.true(validator.isInt(rawInfo.creationFee), "creationFee is a (string) integer");
    t.true(Number(rawInfo.creationFee) > 0, "Number(creationFee) > 0");
    t.true(validator.isHexadecimal(abi.unfork(rawInfo.author)), "unfork(author) is valid hex");
    t.true(validator.isInt(rawInfo.endDate), "endDate is an integer");
    t.equal(rawInfo.participants.constructor, Object, "participants is an object");
    t.true(Object.keys(rawInfo.participants).length > 0, "number of participants > 0");
    t.true(validator.isInt(rawInfo.numOutcomes), "numOutcomes is an integer");
    t.true(rawInfo.numOutcomes > 1, "numOutcomes > 1");
    t.equal(rawInfo.outcomes.constructor, Array, "outcomes is an array");
    t.equal(rawInfo.numOutcomes, rawInfo.outcomes.length, "numOutcomes == outcomes.length");
    var outcome;
    for (var i = 0; i < rawInfo.numOutcomes; ++i) {
        outcome = rawInfo.outcomes[i];
        t.equal(outcome.constructor, Object, "outcome is an object");
        t.true(validator.isInt(outcome.id), "outcome.id is an integer");
        t.true(outcome.id > 0, "outcome.id > 0");
github regular-ui / regular-ui / src / js / base / validator.js View on Github external
if(rule.type === 'is')
            rule.success = rule.reg.test(value);
        else if(rule.type === 'isRequired')
            rule.success = !!value;
        else if(rule.type === 'isFilled')
            rule.success = !!value && (value + '').trim();
        else if(rule.type === 'isEmail')
            rule.success = vali.isEmail(value);
        else if(rule.type === 'isMobilePhone')
            rule.success = vali.isMobilePhone(value, 'zh-CN');
        else if(rule.type === 'isURL')
            rule.success = vali.isURL(value);
        else if(rule.type === 'isNumber')
            rule.success = vali.isInt(value);
        else if(rule.type === 'isInt')
            rule.success = vali.isInt(value);
        else if(rule.type === 'isFloat')
            rule.success = vali.isFloat(value);
        else if(rule.type === 'isLength')
            rule.success = vali.isLength(value, rule.min, rule.max);
        else
            rule.success = rule.method(value);

        if(!rule.success && result.success) {
            result.success = false;
            result.message = rule.message;
        }
    });
github marvinroger / homie-server / lib / validators / property.js View on Github external
canReceive (type, property, value) {
    let propertyObject = this._getPropertyObject(type, property);
    if (!propertyObject) {
      return false;
    }

    switch (propertyObject.type) {
      case 'boolean':
        return validator.isIn(value, ['true', 'false']);
      case 'float':
        return validator.isFloat(value);
      case 'percentage':
        return validator.isInt(value, { min: 0, max: 100 });
      case 'enum':
        return validator.isIn(value, propertyObject.oneOf);
      case 'blank':
        return true;
      case 'string':
        return true;
      default:
        return false;
    }
  }
github inxilpro / node-checkenv / src / index.js View on Github external
case 'iso8601':
				if (!validator.isISO8601(value)) {
					errors.push('Must be an ISO8601-formatted date');
				}
				break;

			case 'enum':
			case 'in':
				validateOptions(name, options, 'array');
				if (!validator.isIn(value, options)) {
					errors.push('Must be on of: "' + options.join('", "') + '"');
				}
				break;

			case 'int':
				if (!validator.isInt(value, options)) {
					errors.push('Must be an integer' + minMaxMessage(options));
				}
				break;

			case 'json':
				if (!validator.isJSON(value)) {
					errors.push('Must be JSON');
				}
				break;

			case 'length':
				validateOptions(name, options, 'object');
				if (!options.min && !options.max) {
					throw new Error(`The "${name}" validator requires a "min" or a "max" option`);
				}
github open-apparel-registry / open-apparel-registry / src / app / src / components / ClaimedFacilitiesDetails.jsx View on Github external
() => {
                            if (isEmpty(data.facility_workers_count)) {
                                return false;
                            }

                            return !isInt(
                                data.facility_workers_count,
                                { min: 0 },
                            );
                        }
                    }
github dxwc / vidlist / index.js View on Github external
.then(() =>
    {
        if(typeof num === 'string' && validator.isInt(num)) return Number(num);
        return list_subscriptions(true)
        .then(() =>
        {
            return new Promise((resolve, reject) =>
            {
                require('readline').createInterface
                ({
                    input: process.stdin,
                    output: process.stdout
                })
                .question
                (
                    'Enter the channel number you wish to update: ',
                    (answer) =>
                    {
                        if(validator.isInt(answer)) return resolve(Number(answer));
github sparkswap / broker-cli / utils / validations.js View on Github external
function isDecimal (str) {
  if ((validatorIsDecimal(str, { decimal_places: '1,19' }) || isInt(str)) && Big(str).lte(MAX_VALUE)) {
    return str
  }

  throw new ValidationError('Invalid decimal format')
}