<commit_before>var AmpersandCollection = require('ampersand-collection');
var type = require('./type');

module.exports = AmpersandCollection.extend({
  mainIndex: '_id',
  model: function(attrs, options) {
    if (attrs && Object.keys(attrs).length === 0) return;

    var val = attrs.value;
    var T = (val && val._bsonType) || Object.prototype.toString.call(val).replace(/\[object (\w+)\]/, '$1');
    var Klass = type[T];

    if (!Klass) {
      throw new TypeError('No value type for ' + T);
    }
    return new Klass({
      value: val
    }, options);
  }
});<commit_msg>debugging proper handling of falsey values<commit_after>var AmpersandCollection = require('ampersand-collection');
var type = require('./type');

module.exports = AmpersandCollection.extend({
  mainIndex: '_id',
  model: function(attrs, options) {
    if (attrs && Object.keys(attrs).length === 0) return;

    var val = attrs.value;
    var T = (val && val._bsontype) || Object.prototype.toString.call(val).replace(/\[object (\w+)\]/, '$1');
    var Klass = type[T];

    if (!Klass) {
      throw new TypeError('No value type for ' + T);
    }

    if (!val) {
      val = '' + val;
    }
    return new Klass({
        value: val
      }, options);
  }
});
{'fraction_non_alphanumeric': 0.17580645161290323, 'fraction_numerical': 0.0032258064516129032, 'mean_word_length': 3.109271523178808, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6175026', 'n_tokens_mistral': 409, 'n_tokens_neox': 399, 'n_words': 101}