SetLike.mjs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. 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); }
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. 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); } }
  4. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  5. 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; }
  6. function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
  7. 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); }
  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. export default typeof Set === "undefined" ? Set : SetLike;
  60. //# sourceMappingURL=SetLike.mjs.map