1 var trim = require('./trim');
3 function boolMatch(s, matchers) {
4 var i, matcher, down = s.toLowerCase();
5 matchers = [].concat(matchers);
6 for (i = 0; i < matchers.length; i += 1) {
8 if (!matcher) continue;
9 if (matcher.test && matcher.test(s)) return true;
10 if (matcher.toLowerCase() === down) return true;
14 module.exports = function toBoolean(str, trueValues, falseValues) {
15 if (typeof str === "number") str = "" + str;
16 if (typeof str !== "string") return !!str;
18 if (boolMatch(str, trueValues || ["true", "1"])) return true;
19 if (boolMatch(str, falseValues || ["false", "0"])) return false;