Security update to Drupal 8.4.6
[yaffs-website] / node_modules / underscore.string / toBoolean.js
1 var trim = require('./trim');
2
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) {
7     matcher = matchers[i];
8     if (!matcher) continue;
9     if (matcher.test && matcher.test(s)) return true;
10     if (matcher.toLowerCase() === down) return true;
11   }
12 }
13
14 module.exports = function toBoolean(str, trueValues, falseValues) {
15   if (typeof str === "number") str = "" + str;
16   if (typeof str !== "string") return !!str;
17   str = trim(str);
18   if (boolMatch(str, trueValues || ["true", "1"])) return true;
19   if (boolMatch(str, falseValues || ["false", "0"])) return false;
20 };