<commit_before>/* eslint prefer-spread: "off" */
/* eslint no-param-reassign: "off" */
/* eslint prefer-rest-params: "off" */
/* eslint no-unused-expressions: "off" */
/* eslint consistent-return: "off" */
/* eslint no-plusplus: "off" */
/* eslint no-void: "off" */
/* eslint new-cap: "off" */

import _ from 'lodash';
import extend from './utils/extend';
import sync from './sync';
import Model from './model';

// Splices `insert` into `array` at index `at`.
const splice = function(array, insert, at) {
  at = Math.min(Math.max(at, 0), array.length);
  const tail = Array(array.length - at);
  const length = insert.length;
  let i;
  for (i = 0; i < tail.length; i++) tail[i] = array[i + at];
  for (i = 0; i < length; i++) array[i + at] = insert[i];
  for (i = 0; i < tail.length; i++) array[i + length + at] = tail[i];
};

const Collection = function(models, options) {
  options || (options = {});
  if (options.model) this.model = options.model;
  if (options.comparator !== void 0) {
    this.comparator = options.comparator;
  }
  this._reset();
  this.initialize.apply(this, arguments);
  if (models) {
    this.reset(models, _.extend({ silent: true }, options));
  }
};

// Attach all inheritable methods to the Model prototype.
_.extend(Collection.prototype, {

  // The default model for a collection is just a **Backbone.Model**.
  // This should be overridden in most cases.
  model: Model,

  // Initialize is an empty function by default. Override it with your own
  // initialization logic.
  initialize: function() {},

  // Add a model, or list of models to the set. `models` may be Backbone
  // Models or raw JavaScript objects to be converted to Models, or any
  // combination of the two.
  add: function(models, options) {
    return this.set(models, _.extend({}, options));
  },

  // Update a collection by `set`-ing a new list of models, adding new ones,
  // removing models that are no longer present, and merging models that
  // already exist in the collection, as necessary. Similar to **Model#set**,
  // the core operation for updating the data contained by the collection.
  set: function(models, options) {
    if (models == null) return;

    options = options || {};<commit_msg>[lore-models] add toJSON method to collections<commit_after>/* eslint prefer-spread: "off" */
/* eslint no-param-reassign: "off" */
/* eslint prefer-rest-params: "off" */
/* eslint no-unused-expressions: "off" */
/* eslint consistent-return: "off" */
/* eslint no-plusplus: "off" */
/* eslint no-void: "off" */
/* eslint new-cap: "off" */

import _ from 'lodash';
import extend from './utils/extend';
import sync from './sync';
import Model from './model';

// Splices `insert` into `array` at index `at`.
const splice = function(array, insert, at) {
  at = Math.min(Math.max(at, 0), array.length);
  const tail = Array(array.length - at);
  const length = insert.length;
  let i;
  for (i = 0; i < tail.length; i++) tail[i] = array[i + at];
  for (i = 0; i < length; i++) array[i + at] = insert[i];
  for (i = 0; i < tail.length; i++) array[i + length + at] = tail[i];
};

const Collection = function(models, options) {
  options || (options = {});
  if (options.model) this.model = options.model;
  if (options.comparator !== void 0) {
    this.comparator = options.comparator;
  }
  this._reset();
  this.initialize.apply(this, arguments);
  if (models) {
    this.reset(models, _.extend({ silent: true }, options));
  }
};

// Attach all inheritable methods to the Model prototype.
_.extend(Collection.prototype, {

  // The default model for a collection is just a **Backbone.Model**.
  // This should be overridden in most cases.
  model: Model,

  // Initialize is an empty function by default. Override it with your own
  // initialization logic.
  initialize: function() {},

  // return a copy of the collections data
  toJSON: function () {
    return this.models.map(function (model) {
      return model.toJSON();
    })
  },

  // Add a model, or list of models to the set. `models` may be Backbone
  // Models or raw JavaScript objects to be converted to Models, or any
  // combination of the two.
  add: function(models, options) {
    return this.set(models, _.extend({}, options));
  },

  // Update a collection by `set`-ing a new list of models, adding new ones,
  // removing models that are no longer present, and merging models that
  // already exist in the collection, as necessary. Similar to **Model#set**,
  // the core operation for updating the data contained by the collection.
  set: function(models, options) {
    if (models == null) return;

    options = options || {};
{'fraction_non_alphanumeric': 0.15073529411764705, 'fraction_numerical': 0.0021626297577854673, 'mean_word_length': 3.302325581395349, 'pattern_counts': {'":': 0, '<': 9, '<?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': '5511059', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1422, 'n_words': 527}