|
|
@@ -0,0 +1,41 @@
|
|
|
+import { type_manager } from "./functions.js";
|
|
|
+
|
|
|
+class parser {
|
|
|
+ #locale;
|
|
|
+ #content;
|
|
|
+
|
|
|
+ constructor(content, locale) {
|
|
|
+ if (!(content instanceof Object)) {
|
|
|
+ throw "Content to create parser from must be an object.";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (type_manager.is_string(locale)) {
|
|
|
+ throw "Locale of the content to show errors must be string.";
|
|
|
+ }
|
|
|
+
|
|
|
+ this.#content = content;
|
|
|
+ this.#locale = locale;
|
|
|
+ }
|
|
|
+
|
|
|
+ exists(target) {
|
|
|
+ if (!type_manager.is_string(target)) {
|
|
|
+ throw "Name of the element to parse must be an string.";
|
|
|
+ }
|
|
|
+
|
|
|
+ return this.#content.hasOwnProperty(target);
|
|
|
+ }
|
|
|
+
|
|
|
+ get(target) {
|
|
|
+ if (!this.exists(target)) {
|
|
|
+ throw "Can not get " + target + " from " + this.#locale + ".";
|
|
|
+ }
|
|
|
+
|
|
|
+ return this.#content[target];
|
|
|
+ }
|
|
|
+
|
|
|
+ get_parser(target) {
|
|
|
+ return new self(this.get(target), this.#locale + "." + target);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+export { parser };
|