54edda60f79c3793a10bc497828a6657a1cbe295932eb448939bcd34e9e4f20bb80ce15c14553361fb075b219b607c02f267aa29b7dd9b4dfdcfdd6457a27e 847 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. const Chainable = require('./Chainable');
  2. module.exports = class extends Chainable {
  3. constructor(parent) {
  4. super(parent);
  5. this.store = new Set();
  6. }
  7. add(value) {
  8. this.store.add(value);
  9. return this;
  10. }
  11. prepend(value) {
  12. this.store = new Set([value, ...this.store]);
  13. return this;
  14. }
  15. clear() {
  16. this.store.clear();
  17. return this;
  18. }
  19. delete(value) {
  20. this.store.delete(value);
  21. return this;
  22. }
  23. values() {
  24. return [...this.store];
  25. }
  26. has(value) {
  27. return this.store.has(value);
  28. }
  29. merge(arr) {
  30. this.store = new Set([...this.store, ...arr]);
  31. return this;
  32. }
  33. when(
  34. condition,
  35. whenTruthy = Function.prototype,
  36. whenFalsy = Function.prototype,
  37. ) {
  38. if (condition) {
  39. whenTruthy(this);
  40. } else {
  41. whenFalsy(this);
  42. }
  43. return this;
  44. }
  45. };