<commit_before>'use strict';

module.exports = {
  prop: function (property) {
    var negate;
    if (/^!/.test(property)) {
      negate = true;
      property = property.slice(1);
    }
    return function ($el, value, previousValue) {
      $el = $($el);

      $el.prop(property, negate && !value || !negate && !!value);
    };
  },

  booleanClass: function (setClass, unsetClass) {
    return function ($el, value, previousValue) {
      $el = $($el);

      $el.toggleClass(setClass, !!value).toggleClass(unsetClass, !value);
    };
  },

  html: function ($el, value, previousValue) {
    $el = $($el);

    $el.html(value);

    $el.trigger('change', { internal: true });
  },

  text: function ($el, value, previousValue) {
    $el = $($el);

    $el.text(value);

    $el.trigger('change', { internal: true });
  },

  value: function ($el, value, previousValue) {
    $el = $($el);

    if ($el[0].type === 'radio' || $el[0].type === 'checkbox') {
      if ($el.length === 1) {
        $el.prop('checked', !!value);
      } else {
        $el.prop('checked', false);

        if (value)
          $el.filter((_.isArray(value) ? value : [ value ]).map(function (value) {
            return '[value="' + value + '"]';
          }).join(',')).prop('checked', true);
      }
    } else {
      if (value != null) value = value.toString();

      $el.val(value);
    }

    $el.trigger('change', { internal: true });
  },

  published: function ($el, value) {
    $el = $($el);

    $el = $el.closest('[data-published]');

    $el.attr('data-published', (!!value).toString());
  },

  parts: function ($el, value) {
    $el = $($el);

    if (!_.isDate(value)) value = new Date(value);

    var ref = value.toLocaleString('se-SV').split(' ');

    $el.find('[data-part]').toArray().forEach(function (part, index) {
      $(part).val(ref[index]);
    });
  },

  src: function ($el, value) {
    $el = $($el);

    $el.attr('src', value);
  },

  selectMultiple: function ($el, value) {
    $el = $($el);

    if (!value) $el.val(null);

    else
      value.forEach(function (value) {
        $el.find('[value="' + value + '"]').prop('selected', true);
      });
  }
};
<commit_msg>Smarter value setter.<commit_after>'use strict';

module.exports = {
  prop: function (property) {
    var negate;
    if (/^!/.test(property)) {
      negate = true;
      property = property.slice(1);
    }
    return function ($el, value, previousValue) {
      $el = $($el);

      $el.prop(property, negate && !value || !negate && !!value);
    };
  },

  booleanClass: function (setClass, unsetClass) {
    return function ($el, value, previousValue) {
      $el = $($el);

      $el.toggleClass(setClass, !!value).toggleClass(unsetClass, !value);
    };
  },

  html: function ($el, value, previousValue) {
    $el = $($el);

    $el.html(value);

    $el.trigger('change', { internal: true });
  },

  text: function ($el, value, previousValue) {
    $el = $($el);

    $el.text(value);

    $el.trigger('change', { internal: true });
  },

  value: function (el, value, previousValue) {
    if (el.type === 'radio' || el.type === 'checkbox') {
      if (el.name && el.form)
        el = el.form[el.name];

      if ('length' in el) {
        $(el).prop('checked', false);

        if (value != null)
          _.each(el, function (el) {
            if (_.isArray(value) && value.indexOf(el.value) > -1 || el.value === value)
              el.checked = true;
          });
      } else {
        el.checked = !!value;
      }
    } else {
      if (value != null) value = value.toString();

      $(el).val(value);
    }

    $(el).trigger('change', { internal: true });
  },

  published: function ($el, value) {
    $el = $($el);

    $el = $el.closest('[data-published]');

    $el.attr('data-published', (!!value).toString());
  },

  parts: function ($el, value) {
    $el = $($el);

    if (!_.isDate(value)) value = new Date(value);

    var ref = value.toLocaleString('se-SV').split(' ');

    $el.find('[data-part]').toArray().forEach(function (part, index) {
      $(part).val(ref[index]);
    });
  },

  src: function ($el, value) {
    $el = $($el);

    $el.attr('src', value);
  },

  selectMultiple: function ($el, value) {
    $el = $($el);

    if (!value) $el.val(null);

    else
      value.forEach(function (value) {
        $el.find('[value="' + value + '"]').prop('selected', true);
      });
  }
};

{'fraction_non_alphanumeric': 0.22048846675712347, 'fraction_numerical': 0.0013568521031207597, 'mean_word_length': 2.4909234411996843, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '6137161', 'n_tokens_mistral': 1556, 'n_tokens_neox': 1502, 'n_words': 320}