Code coverage report for master/toBoolean.js

Statements: 95.45% (21 / 22)      Branches: 95% (19 / 20)      Functions: 100% (2 / 2)      Lines: 100% (15 / 15)      Ignored: none     

All files » master/ » toBoolean.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 211   1 33 33 33 53 53 53 50       1 23 23 21 21 12    
var trim = require('./trim');
 
function boolMatch(s, matchers) {
  var i, matcher, down = s.toLowerCase();
  matchers = [].concat(matchers);
  for (i = 0; i < matchers.length; i += 1) {
    matcher = matchers[i];
    Iif (!matcher) continue;
    if (matcher.test && matcher.test(s)) return true;
    if (matcher.toLowerCase() === down) return true;
  }
}
 
module.exports = function toBoolean(str, trueValues, falseValues) {
  if (typeof str === "number") str = "" + str;
  if (typeof str !== "string") return !!str;
  str = trim(str);
  if (boolMatch(str, trueValues || ["true", "1"])) return true;
  if (boolMatch(str, falseValues || ["false", "0"])) return false;
};