Sha256: 3696296cfdc07247025ec35e3a22dfee455ae9af06edc9480e9e389e7cfe2b39

Contents?: true

Size: 668 Bytes

Versions: 19

Compression:

Stored size: 668 Bytes

Contents

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;
};

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
ela-4.1.6 node_modules/underscore.string/toBoolean.js
ela-4.1.5 node_modules/underscore.string/toBoolean.js
ela-4.1.4 node_modules/underscore.string/toBoolean.js
ela-4.1.3 node_modules/underscore.string/toBoolean.js
ela-4.1.2 node_modules/underscore.string/toBoolean.js
ela-4.1.1 node_modules/underscore.string/toBoolean.js
ela-4.1.0 node_modules/underscore.string/toBoolean.js
ela-4.0.0 node_modules/underscore.string/toBoolean.js
ela-3.4.3 node_modules/underscore.string/toBoolean.js
ela-3.4.2 node_modules/underscore.string/toBoolean.js
ela-3.4.0 node_modules/underscore.string/toBoolean.js
ela-3.3.1 node_modules/underscore.string/toBoolean.js
ela-3.3.0 node_modules/underscore.string/toBoolean.js
ela-3.2.0 node_modules/underscore.string/toBoolean.js
ela-3.1.1 node_modules/underscore.string/toBoolean.js
ela-3.1.0 node_modules/underscore.string/toBoolean.js
ela-3.0.0 node_modules/underscore.string/toBoolean.js
ela-2.0.0 node_modules/underscore.string/toBoolean.js
ela-1.1.0 node_modules/underscore.string/toBoolean.js