SetLike.mjs 2.2 KB

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