SetLike.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.default = void 0;
  4. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  6. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  7. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  8. // for environments without Set we fallback to arrays with unique members
  9. var SetLike = /*#__PURE__*/function () {
  10. function SetLike() {
  11. var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  12. _classCallCheck(this, SetLike);
  13. _defineProperty(this, "items", void 0);
  14. this.items = items;
  15. }
  16. _createClass(SetLike, [{
  17. key: "add",
  18. value: function add(value) {
  19. if (this.has(value) === false) {
  20. this.items.push(value);
  21. }
  22. return this;
  23. }
  24. }, {
  25. key: "clear",
  26. value: function clear() {
  27. this.items = [];
  28. }
  29. }, {
  30. key: "delete",
  31. value: function _delete(value) {
  32. var previousLength = this.items.length;
  33. this.items = this.items.filter(function (item) {
  34. return item !== value;
  35. });
  36. return previousLength !== this.items.length;
  37. }
  38. }, {
  39. key: "forEach",
  40. value: function forEach(callbackfn) {
  41. var _this = this;
  42. this.items.forEach(function (item) {
  43. callbackfn(item, item, _this);
  44. });
  45. }
  46. }, {
  47. key: "has",
  48. value: function has(value) {
  49. return this.items.indexOf(value) !== -1;
  50. }
  51. }, {
  52. key: "size",
  53. get: function get() {
  54. return this.items.length;
  55. }
  56. }]);
  57. return SetLike;
  58. }();
  59. var _default = typeof Set === "undefined" ? Set : SetLike;
  60. exports.default = _default;
  61. //# sourceMappingURL=SetLike.js.map