UNPKG

@ticatec/web-bean-validator

Version:

A TypeScript/JavaScript library for rule-based entity validation with boundary checking for strings, numbers, dates, enums, objects, and arrays.

20 lines (19 loc) 540 B
import BaseValidator from "./BaseValidator"; export default class BooleanValidator extends BaseValidator { constructor(field, options) { super(field, options); } checkType(value) { if (typeof value == "number") { return value != 0; } else if (typeof value == 'string') { let v = value.toLowerCase().trim(); return v == 'true' || v == '1'; } else if (typeof value == 'boolean') { return value; } return null; } }