You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
518 B

4 years ago
  1. 'use strict';
  2. module.exports = function merge(value) {
  3. var arrayOrObject = value;
  4. if (typeof arrayOrObject === 'string') {
  5. arrayOrObject = [arrayOrObject];
  6. }
  7. if (Array.isArray(this.items) && Array.isArray(arrayOrObject)) {
  8. return new this.constructor(this.items.concat(arrayOrObject));
  9. }
  10. var collection = JSON.parse(JSON.stringify(this.items));
  11. Object.keys(arrayOrObject).forEach(function (key) {
  12. collection[key] = arrayOrObject[key];
  13. });
  14. return new this.constructor(collection);
  15. };