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.

41 lines
1.3 KiB

4 years ago
  1. 'use strict';
  2. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  3. module.exports = function duplicates() {
  4. var _this = this;
  5. var occuredValues = [];
  6. var duplicateValues = {};
  7. var stringifiedValue = function stringifiedValue(value) {
  8. if (Array.isArray(value) || (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') {
  9. return JSON.stringify(value);
  10. }
  11. return value;
  12. };
  13. if (Array.isArray(this.items)) {
  14. this.items.forEach(function (value, index) {
  15. var valueAsString = stringifiedValue(value);
  16. if (occuredValues.indexOf(valueAsString) === -1) {
  17. occuredValues.push(valueAsString);
  18. } else {
  19. duplicateValues[index] = value;
  20. }
  21. });
  22. } else if (_typeof(this.items) === 'object') {
  23. Object.keys(this.items).forEach(function (key) {
  24. var valueAsString = stringifiedValue(_this.items[key]);
  25. if (occuredValues.indexOf(valueAsString) === -1) {
  26. occuredValues.push(valueAsString);
  27. } else {
  28. duplicateValues[key] = _this.items[key];
  29. }
  30. });
  31. }
  32. return new this.constructor(duplicateValues);
  33. };