How to use the toInt function from validator

Find comprehensive JavaScript validator.toInt code examples handpicked from public code repositorys.

1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
 */
Chain.prototype.toInt = function() {
  this._pushValidator({
    name: 'toInt',
    func: function(value, baton, callback) {
      callback(null, check.toInt(value));
    },
    help: null
  });
  return this;
fork icon11
star icon96
watch icon0

31
32
33
34
35
36
37
38
39
40
}
if (sanitization.toBoolean) {
  sanitizefield = Validator.toBoolean(sanitizefield);
}
if (sanitization.toInt) {
  sanitizefield = Validator.toInt(sanitizefield);
}
if (sanitization.toFloat) {
  sanitizefield = Validator.toFloat(sanitizefield);
}
fork icon0
star icon3
watch icon0

15
16
17
18
19
20
21
22
23
24
socket.on('message', function(msg) {
  let message = validator.escape(msg.toString('utf-8'));
  console.log('SOCKET Received : ', message);
  result = message.split('  ');
  checkPassword(result[0], (auth) => {
    let userId = validator.toInt(result[1]);
    let action = validator.toInt(result[2]);
    pool.getConnection((err, conn) => {
      refreshCommand(userId, () => {
        switch (action) {
fork icon0
star icon2
watch icon0

83
84
85
86
87
88
89
90
91
92
    });
} else {
    if (!(amount && validator.isInt(amount + ''))) {
        throw new BidError('Please specify the amount you want to bid');
    }
    amount = validator.toInt(amount + '');

    const openBidPrice = this.get('openBidPrice');

    if (amount < openBidPrice) {
fork icon0
star icon2
watch icon3

224
225
226
227
228
229
230
231
232
233
}
if (sanitization.toFloat) {
  req.body[field] = Validator.toFloat(req.body[field]);
}
if (sanitization.toInt) {
  req.body[field] = Validator.toInt(req.body[field]);
}
if (sanitization.trim) {
  req.body[field] = Validator.trim(req.body[field]);
}
fork icon0
star icon0
watch icon0

+ 11 other calls in file

312
313
314
315
316
317
318
319
320
321
  return this.validateFunction(value, ...this.options);
} else {
  switch (this.validateFunction) {
    case 'isInt':
      if (typeof value === 'string') {
        this.parsedValue = validator1.toInt(value);
        return validator1.isInt(value, ...this.options);
      } else {
        this.parsedValue = value;
        return validator1.isInt(String(value), ...this.options);
fork icon0
star icon0
watch icon0

+ 3 other calls in file

80
81
82
83
84
85
86
87
88
89
 * 字符串转int
 * @param input 输入字符串
 * @param radix 精度
 */
toInt(input, radix) {
  return validator1.toInt(input, radix);
}

/**
 * 字符串转float
fork icon0
star icon0
watch icon0

402
403
404
405
406
407
408
409
410
411
},
'string': {
  converter: (val) => val.toString()
},
'int': {
  converter: (val) => _.isString(val) ? V.toInt(val) : parseInt(val)
},
'float': {
  converter: (val) => _.isString(val) ? V.toFloat(val) : parseFloat(val)
},
fork icon0
star icon0
watch icon0