X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=node_modules%2Funderscore.string%2FtoBoolean.js;fp=node_modules%2Funderscore.string%2FtoBoolean.js;h=ba82db6dddf29d91035e7e382f8d9f2639895a43;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/node_modules/underscore.string/toBoolean.js b/node_modules/underscore.string/toBoolean.js new file mode 100644 index 000000000..ba82db6dd --- /dev/null +++ b/node_modules/underscore.string/toBoolean.js @@ -0,0 +1,20 @@ +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]; + if (!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; +};