How to use the isBoolean function from validator

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

37
38
39
40
41
42
43
44
45
46
this.isBefore = (date) => (subject) => {
    return StringValidator.isBefore(subject, date) ? null : subject + ' is not before' + date;
}

this.isBoolean = (subject) => {
    return StringValidator.isBoolean(subject) ? null : subject + ' is not boolean';
}

this.isBIC = (subject) => {
    return StringValidator.isBIC(subject) ? null : subject + ' is not BIC(Bank Idenfication Code) or SWIFT code.';
fork icon1
star icon4
watch icon2

+ 3 other calls in file

215
216
217
218
219
220
221
222
223
224
case 'alpha':
  isValid = validator.isAlpha(stringValue);
  break;

case 'bool':
  isValid = validator.isBoolean(stringValue);
  break;

case 'date':
  isValid = validator.isDate(stringValue);
fork icon0
star icon2
watch icon1

+ 31 other calls in file

49
50
51
52
53
54
55
56
57
58
59
function postGame(event, callback) {


  //validate the body - see if isPlayer2Bot is set and true
  const jsonBody = utilities.parseJson(event.body);  //deals with nulls and JSON parse errors
  var isPlayer2Bot = false;
  if (('isPlayer2Bot' in jsonBody) && validator.isBoolean(jsonBody.isPlayer2Bot + '', { loose: false }) && ['true', '1'].includes(jsonBody.isPlayer2Bot + '')) {
    //Check this request not made by bot2 - can't play bot2 against bot 2
    if (isBot2) {
      var error = new Error('Bot2 can not be player 1 and player 2'); error.status = 422;
      return callback(null, utilities.errorResponse(event, error));      
fork icon0
star icon0
watch icon1

36
37
38
39
40
41
42
43
44
45
    headerBackground = req.body.headerBackground;

if (req.body.sshterm && /^(([a-z]|[A-Z]|\d|[!^(){}\-_~])+)?\w$/.test(req.body.sshterm))
    sshterm = req.body.sshterm;

if (req.body.cursorBlink && validator.isBoolean(`${req.body.cursorBlink}`))
    cursorBlink = parseBool(req.body.cursorBlink);

if (req.body.scrollback && validator.isInt(`${req.body.scrollback}`, {min: 1, max: 200000}))
    scrollback = req.body.scrollback;
fork icon0
star icon0
watch icon0

46
47
48
49
50
51
52
53
54
55
case 'int':
  return validator.isInt;
case 'safe_string':
  return validator.isAlphanumeric;
case 'boolean':
  return validator.isBoolean;
case 'string':
  return function (value) {
    return typeof value === 'string';
  };
fork icon0
star icon0
watch icon0

329
330
331
332
333
334
335
336
337
338
    return validator1.isFloat(String(value), ...this.options);
  }
case 'isBoolean':
  if (typeof value === 'string') {
    this.parsedValue = validator1.toBoolean(value);
    return validator1.isBoolean(value);
  } else {
    this.parsedValue = value;
    return validator1.isBoolean(String(value));
  }
fork icon0
star icon0
watch icon0

+ 7 other calls in file

121
122
123
124
125
126
127
128
129
130
  ? response.data.StaffEmail
  : "",
TerritoryCode: escape(response.data.FirmStructure.TerritoryCode),
LoS: escape(response.data.FirmStructure.LoS),
LoSDescription: escape(response.data.FirmStructure.LoSDescription),
IsAuthenticated: validator.isBoolean(
  response.data.IsAuthenticated.toString()
)
  ? response.data.IsAuthenticated
  : "",
fork icon0
star icon0
watch icon0