SetLike.js 3.2 KB

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