parser.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { type_manager } from "./functions.js";
  2. class parser {
  3. #locale;
  4. #content;
  5. constructor(content, locale) {
  6. if (!(content instanceof Object)) {
  7. throw "Content to create parser from must be an object.";
  8. }
  9. if (!type_manager.is_string(locale)) {
  10. throw "Location of potential missing object must be string.";
  11. }
  12. this.#content = content;
  13. this.#locale = locale;
  14. }
  15. exists(target) {
  16. if (!type_manager.is_string(target)) {
  17. throw "Name of the element to parse must be an string.";
  18. }
  19. return this.#content.hasOwnProperty(target);
  20. }
  21. get(target) {
  22. if (!this.exists(target)) {
  23. throw "Can not get " + target + " from " + this.#locale + ".";
  24. }
  25. return this.#content[target];
  26. }
  27. get properties() {
  28. return Object.getOwnPropertyNames(this.#content);
  29. }
  30. get_parser(target) {
  31. return new parser(this.get(target), this.#locale + "." + target);
  32. }
  33. }
  34. export { parser };