submissions_list.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { type_manager } from "./functions.js";
  2. import { submission } from "./submission.js";
  3. class submissions_list {
  4. #content;
  5. constructor() {
  6. this.#content = {};
  7. }
  8. append(target) {
  9. if (!(target instanceof submission)) {
  10. throw "New target on list must be instance of an submission.";
  11. }
  12. if (this.exists(target)) {
  13. throw "This submission already exists on list.";
  14. }
  15. this.#content[target.title] = target;
  16. }
  17. exists(target) {
  18. if (target instanceof submission) {
  19. target = target.title;
  20. }
  21. if (!(type_manager.is_string(target))) {
  22. throw "Target must be instance of string or submission.";
  23. }
  24. return this.#content.hasOwnProperty(target);
  25. }
  26. get(target) {
  27. if (!this.exists(target)) {
  28. throw "Submission with that name not exists in the list.";
  29. }
  30. return this.#content[target];
  31. }
  32. get content() {
  33. return Object.assign({}, this.#content);
  34. }
  35. }
  36. export { submissions_list };