UNPKG

abolish

Version:

A javascript object validator.

41 lines (40 loc) 1.02 kB
"use strict"; module.exports = { name: "boolean", error: ":param is not a valid boolean", /** * @param str * @param option * @param {ObjectModifier} modifier * @return {boolean} */ validator: (str, option, { modifier }) => { if (typeof str == "boolean") { return true; } else if (typeof str === "string") { str = str.toLowerCase(); if (str === "true") { modifier.setThis(true); return true; } else if (str === "false") { modifier.setThis(false); return true; } } else if (typeof str === "number") { if (str === 1) { modifier.setThis(true); return true; } else if (str === 0) { modifier.setThis(false); return true; } } else { return false; } } };