diff --git a/application/source/data/buildmap.mjs b/application/source/data/buildmap.mjs index ae9400ed5bf8b02120f383287d4fc1f6028477ac..a6c4b9821e8a56d96b1ab611b1e1bc56196f9fca 100644 --- a/application/source/data/buildmap.mjs +++ b/application/source/data/buildmap.mjs @@ -19,27 +19,26 @@ export { buildMap, PARENT, assembleParts }; const PARENT = "^"; /** - * With the help of the function `buildMap()`, maps can be easily created from data objects. + * Maps can be easily created from data objects with the help of the function `buildMap()`. * - * Either a simple definition `a.b.c` or a template `${a.b.c}` can be specified as the path. + * The path can be specified as either a simple definition a.b.c or a template ${a.b.c}. * Key and value can be either a definition or a template. The key does not have to be defined. - * * The templates determine the appearance of the keys and the value of the map. Either a single value - * `id` can be taken or a composite key `${id} ${name}` can be used. + * id can be taken or a composite key ${id} ${name} can be used. * - * If you want to access values of the parent data set, you have to use the `^` character `${id} ${^.name}`. + * If you want to access values of the parent data set, you have to use the ^ character, for example ${id} ${^.name}. * * @externalExample ../../example/data/buildmap.mjs - * @param {*} subject - * @param {string|Monster.Data~exampleSelectorCallback} selector - * @param {string} [valueTemplate] - * @param {string} [keyTemplate] - * @param {Monster.Data~exampleFilterCallback} [filter] - * @return {*} + * @param {*} subject - The data object from which the map will be created + * @param {string|Monster.Data~exampleSelectorCallback} selector - The path to the data object, or a callback that returns a map. + * @param {string} [valueTemplate] - A template for the value of the map. + * @param {string} [keyTemplate] - A template for the key of the map. + * @param {Monster.Data~exampleFilterCallback} [filter] - A callback function to filter out values. + * @return {*} - The created map. * @memberOf Monster.Data - * @throws {TypeError} value is neither a string nor a function - * @throws {TypeError} the selector callback must return a map - */ + * @throws {TypeError} - If the value is neither a string nor a function. + * @throws {TypeError} - If the selector callback does not return a map. + **/ function buildMap(subject, selector, valueTemplate, keyTemplate, filter) { return assembleParts(subject, selector, filter, function (v, k, m) { k = build(v, keyTemplate, k); @@ -49,13 +48,66 @@ function buildMap(subject, selector, valueTemplate, keyTemplate, filter) { } /** + * The assembleParts function is a private function that helps in building a map from a subject object based on a provided + * selector. The selector can either be a string or a callback function. This function is meant to be used as a + * helper function by other functions in the module. + * + * The function takes four parameters: + * + * subject: The subject object from which the map is to be built + * selector: The selector to determine the structure of the map. It can be a string or a callback function. + * filter (optional): A callback function that can be used to filter values based on some criteria. + * callback: A function to be called for each element in the map. + * If the selector parameter is a callback function, it is executed passing the subject as its argument, + * and the resulting value must be an instance of Map. Otherwise, if the selector parameter is a string, + * buildFlatMap is called to build a flat map with keys and values extracted from the subject object based on the selector. + * + * If the filter parameter is provided, it will be used to filter out certain elements from the map, based on some + * criteria. The callback will be passed the value, key, and map object, and if it returns false, the element will be skipped. + * + * For each element in the map, the callback function is called with the following parameters: + * + * v: The value of the element + * k: The key of the element + * m: The map object + * The function returns a new map with the processed values. If map is not an instance of Map, an empty map will be returned. + * + * Example Usage: + * + * ```javascript + * const obj = { + * name: "John", + * age: 30, + * address: { + * city: "New York", + * state: "NY", + * country: "USA", + * }, + * }; + * + * const selector = "address"; + * + * const map = assembleParts(obj, selector, null, function (v, k, m) { + * this.set(k, v); + * }); + * + * console.log(map); + * // Output: Map(3) { + * // "address.city" => "New York", + * // "address.state" => "NY", + * // "address.country" => "USA" + * // } + * ``` + * + * * @private - * @param {*} subject - * @param {string|Monster.Data~exampleSelectorCallback} selector - * @param {Monster.Data~exampleFilterCallback} [filter] - * @param {function} callback - * @return {Map} - * @throws {TypeError} selector is neither a string nor a function + * @param {*} subject - The subject object from which the map is to be built. + * @param {string|Monster.Data~exampleSelectorCallback} selector - The selector to determine the structure of the map. It can be a string or a callback function. + * @param {Monster.Data~exampleFilterCallback} [filter] - A callback function that can be used to filter values based on some criteria. + * @param {function} callback - A function to be called for each element in the map. + * @return {Map} - A new map with the processed values. + * @throws {TypeError} - When selector is neither a string nor a function. + * @memberOf Monster.Data */ function assembleParts(subject, selector, filter, callback) { const result = new Map(); diff --git a/application/source/data/buildtree.mjs b/application/source/data/buildtree.mjs index 10bb03c439fe90374df51fec53a332b46883d003..3a36a9c1041abd3a51c4cc95716ab9dedf31ec48 100644 --- a/application/source/data/buildtree.mjs +++ b/application/source/data/buildtree.mjs @@ -33,19 +33,102 @@ const rootSymbol = Symbol("root"); */ /** - * With the help of the function `buildTree()`, nodes can be easily created from data objects. - * - * @param {*} subject - * @param {string|Monster.Data~exampleSelectorCallback} selector - * @param {string} idKey - * @param {string} parentIDKey - * @param {buildTreeOptions} [options] - * @return {*} - * @memberOf Monster.Data - * @throws {TypeError} value is neither a string nor a function - * @throws {TypeError} the selector callback must return a map - * @throws {Error} the object has no value for the specified id + * Creates a tree structure from a given subject using a selector and specified ID and parent ID keys. + * + * The buildTree function is a powerful tool for creating tree-like data structures from plain JavaScript + * objects. It takes in four required parameters: the subject object that you want to turn into a tree, a + * selector that identifies which parts of the subject to use when building the tree, and two keys + * (idKey and parentIDKey) that specify which properties in the subject represent the unique identifiers + * and parent-child relationships between nodes in the tree. + * + * Optionally, you can also pass in an options object to further configure the behavior of the function, + * such as specifying which values should be treated as roots of the tree, or providing a custom filter + * function to only include certain nodes in the final output. + * + * The buildTree function works by first using the assembleParts helper function to extract the relevant + * parts of the subject based on the selector, and then iterates over the resulting map to create Node + * objects and organize them into parent-child relationships based on the values of the idKey and parentIDKey properties. + * + * The resulting NodeList represents the tree structure, with each Node object containing the original + * object data as well as additional metadata about its position in the tree. You can then use the childNodes + * property of each Node to access its children, or the parent property to access its parent. + * + * Overall, the buildTree function is a flexible and powerful way to transform flat data into hierarchical + * structures, and can be especially useful in scenarios such as displaying folder structures or + * visualizing complex data relationships. + * + * Let's say you have an array of data objects representing a file system directory structure, and you want + * to turn it into a tree-like structure where each node represents a folder or file, and child nodes + * represent the contents of the folder: + * + * ```javascript + * const fileSystem = [ + * { id: 'folder1', name: 'Folder 1', type: 'folder', parent: null }, + * { id: 'file1', name: 'File 1', type: 'file', parent: 'folder1' }, + * { id: 'file2', name: 'File 2', type: 'file', parent: 'folder1' }, + * { id: 'subfolder1', name: 'Subfolder 1', type: 'folder', parent: 'folder1' }, + * { id: 'file3', name: 'File 3', type: 'file', parent: 'subfolder1' }, + * { id: 'file4', name: 'File 4', type: 'file', parent: 'subfolder1' }, + * { id: 'subfolder2', name: 'Subfolder 2', type: 'folder', parent: 'folder1' }, + * { id: 'file5', name: 'File 5', type: 'file', parent: 'subfolder2' }, + * { id: 'file6', name: 'File 6', type: 'file', parent: 'subfolder2' }, + * { id: 'folder2', name: 'Folder 2', type: 'folder', parent: null }, + * { id: 'file7', name: 'File 7', type: 'file', parent: 'folder2' }, + * { id: 'file8', name: 'File 8', type: 'file', parent: 'folder2' }, + * { id: 'subfolder3', name: 'Subfolder 3', type: 'folder', parent: 'folder2' }, + * { id: 'file9', name: 'File 9', type: 'file', parent: 'subfolder3' }, + * { id: 'file10', name: 'File 10', type: 'file', parent: 'subfolder3' }, + * ]; + * + * const tree = buildTree(fileSystem, 'id', 'id', 'parent', { rootReferences: [null] }); + * + * console.log(tree.toString()); + * ``` + * + * The buildTree function takes in the array of data objects, as well as some configuration options specifying + * the keys to use for identifying nodes and their parent-child relationships. In this example, we use the id + * key to identify nodes, and the parent key to specify the parent of each node. + * + * The resulting tree object is a nested tree structure, where each node is an object representing a file or + * folder, and has child nodes representing its contents. The toString method of the tree object + * can be used to print out the tree in a readable format: + * + * ```markdown + * - Folder 1 + * - File 1 + * - File 2 + * - Subfolder 1 + * - File 3 + * - File 4 + * - Subfolder 2 + * - File 5 + * - File 6 + * - Folder 2 + * - File 7 + * - File 8 + * - Subfolder 3 + * - File 9 + * - File 10 + * ``` + * + * @memberof Monster.Data + * + * @param {*} subject - The object or array to build the tree from. + * @param {string|Monster.Data~exampleSelectorCallback} selector - Either a string to specify a property of each object to use as a selector, or a selector function to generate a map of objects. + * @param {string} idKey - The property key to use as the unique ID of each node. + * @param {string} parentIDKey - The property key to use as the parent ID of each node. + * @param {object} [options] - Additional options to modify the function behavior. + * @param {Array<*>} [options.rootReferences=[null, undefined]] - An array of values to treat as root references when creating the tree. + * @param {function} [options.filter] - A filter function to apply to each node. + * + * @return {*} The resulting tree structure as a NodeList. + * + * @throws {TypeError} selector is neither a string nor a function. + * @throws {TypeError} the selector callback must return a map. + * @throws {Error} the object has no value for the specified id. + * * @license AGPLv3 + * * @since 1.26.0 */ function buildTree(subject, selector, idKey, parentIDKey, options) { diff --git a/application/source/data/datasource/dom.mjs b/application/source/data/datasource/dom.mjs index 6625019df64643e1a17531e9755a1ccbae288d96..749ab68f55f015b8185264fad1308a077055d846 100644 --- a/application/source/data/datasource/dom.mjs +++ b/application/source/data/datasource/dom.mjs @@ -5,12 +5,11 @@ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html */ -import { instanceSymbol } from "../../constants.mjs"; -import { isObject } from "../../types/is.mjs"; +import { instanceSymbol } from "../../constants.mjs"; +import { isObject } from "../../types/is.mjs"; import { Datasource } from "../datasource.mjs"; -export {DomStorage}; - +export { DomStorage }; /** * The DomStorage is a class that stores data in memory. @@ -53,7 +52,7 @@ class DomStorage extends Datasource { }, write: { selector: undefined, - } + }, }); } @@ -78,13 +77,12 @@ class DomStorage extends Datasource { return new Promise((resolve, reject) => { try { let data = JSON.parse(storage.innerHTML); - self.set(data) + self.set(data); resolve(data); } catch (e) { reject(e); } - ; - }) + }); } /** @@ -93,7 +91,6 @@ class DomStorage extends Datasource { * @throws {Error} There are no storage element */ write() { - const self = this; let selector = self.getOption("write.selector"); @@ -113,10 +110,6 @@ class DomStorage extends Datasource { } catch (e) { reject(e); } - }) - - + }); } - } - diff --git a/application/source/data/datasource/server/restapi.mjs b/application/source/data/datasource/server/restapi.mjs index 71719b34efd48632d477ea4e416a973d91d1e364..6550ac2de95735bb810d0f38a8878fdec9875066 100644 --- a/application/source/data/datasource/server/restapi.mjs +++ b/application/source/data/datasource/server/restapi.mjs @@ -6,7 +6,7 @@ */ import { internalSymbol, instanceSymbol } from "../../../constants.mjs"; -import { isObject,isFunction } from "../../../types/is.mjs"; +import { isObject, isFunction } from "../../../types/is.mjs"; import { Server } from "../server.mjs"; import { WriteError } from "./restapi/writeerror.mjs"; @@ -127,11 +127,12 @@ class RestAPI extends Server { if (!init["method"]) init["method"] = "GET"; let callback = self.getOption("read.responseCallback"); - if(!callback) callback = (obj) => { - self.set(self.transformServerPayload.call(self, obj)); - }; - - return fetchData.call(this, init,"read", callback); + if (!callback) + callback = (obj) => { + self.set(self.transformServerPayload.call(self, obj)); + }; + + return fetchData.call(this, init, "read", callback); } /** @@ -199,7 +200,6 @@ function fetchData(init, key, callback) { obj = JSON.parse(body); response[rawDataSymbol] = obj; - } catch (e) { if (body.length > 100) { body = `${body.substring(0, 97)}...`; @@ -211,7 +211,7 @@ function fetchData(init, key, callback) { if (callback && isFunction(callback)) { callback(obj); } - + return response; }); } diff --git a/application/source/data/transformer.mjs b/application/source/data/transformer.mjs index 1bb67ddebc546259b600dbd24366a7693d0a9cbd..c0cafd46899f8d3ef76c8c7391f5cf14f1e972bd 100644 --- a/application/source/data/transformer.mjs +++ b/application/source/data/transformer.mjs @@ -5,12 +5,12 @@ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html */ -import {getLocaleOfDocument} from "../dom/locale.mjs"; -import {Base} from "../types/base.mjs"; -import {getGlobal, getGlobalObject} from "../types/global.mjs"; -import {ID} from "../types/id.mjs"; -import {isArray, isObject, isString, isPrimitive} from "../types/is.mjs"; -import {getDocumentTranslations, Translations} from "../i18n/translations.mjs"; +import { getLocaleOfDocument } from "../dom/locale.mjs"; +import { Base } from "../types/base.mjs"; +import { getGlobal, getGlobalObject } from "../types/global.mjs"; +import { ID } from "../types/id.mjs"; +import { isArray, isObject, isString, isPrimitive } from "../types/is.mjs"; +import { getDocumentTranslations, Translations } from "../i18n/translations.mjs"; import { validateFunction, validateInteger, @@ -19,10 +19,10 @@ import { validateString, validateBoolean, } from "../types/validate.mjs"; -import {clone} from "../util/clone.mjs"; -import {Pathfinder} from "./pathfinder.mjs"; +import { clone } from "../util/clone.mjs"; +import { Pathfinder } from "./pathfinder.mjs"; -export {Transformer}; +export { Transformer }; /** * The transformer class is a swiss army knife for manipulating values. especially in combination with the pipe, processing chains can be built up. @@ -576,7 +576,6 @@ function transform(value) { throw new Error("type not supported"); - case "map": map = new Map(); while (args.length > 0) { @@ -592,7 +591,6 @@ function transform(value) { return map.get(value); case "equals": - if (args.length === 0) { throw new Error("missing value parameter"); } @@ -631,11 +629,10 @@ function transform(value) { case "money": case "currency": - try { locale = getLocaleOfDocument(); } catch (e) { - throw new Error("unsupported locale or missing format (" + e.message + ")"); + throw new Error(`unsupported locale or missing format (${e.message})`); } const currency = value.substring(0, 3); @@ -672,9 +669,8 @@ function transform(value) { try { locale = getLocaleOfDocument(); return date.toLocaleTimeString(locale); - } catch (e) { - throw new Error("unsupported locale or missing format (" + e.message + ")"); + throw new Error(`unsupported locale or missing format (${e.message})`); } case "datetime": @@ -686,9 +682,8 @@ function transform(value) { try { locale = getLocaleOfDocument(); return date.toLocaleString(locale); - } catch (e) { - throw new Error("unsupported locale or missing format (" + e.message + ")"); + throw new Error(`unsupported locale or missing format (${e.message})`); } case "date": @@ -700,12 +695,10 @@ function transform(value) { try { locale = getLocaleOfDocument(); return date.toLocaleDateString(locale); - } catch (e) { - throw new Error("unsupported locale or missing format (" + e.message + ")"); + throw new Error(`unsupported locale or missing format (${e.message})`); } - case "year": date = new Date(value); if (isNaN(date.getTime())) { diff --git a/application/source/dom/customelement.mjs b/application/source/dom/customelement.mjs index d2721e0985eacf58429ae5d6cdf1bbebc8dd5cb4..114a3620c98203fc339267d2c41dfec80f783d75 100644 --- a/application/source/dom/customelement.mjs +++ b/application/source/dom/customelement.mjs @@ -5,19 +5,19 @@ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html */ -import {internalSymbol} from "../constants.mjs"; -import {extend} from "../data/extend.mjs"; -import {Pathfinder} from "../data/pathfinder.mjs"; -import {Formatter} from "../text/formatter.mjs"; - -import {parseDataURL} from "../types/dataurl.mjs"; -import {getGlobalObject} from "../types/global.mjs"; -import {isArray, isFunction, isIterable, isObject, isString} from "../types/is.mjs"; -import {Observer} from "../types/observer.mjs"; -import {ProxyObserver} from "../types/proxyobserver.mjs"; -import {validateFunction, validateInstance, validateObject, validateString} from "../types/validate.mjs"; -import {clone} from "../util/clone.mjs"; -import {addAttributeToken, getLinkedObjects, hasObjectLink} from "./attributes.mjs"; +import { internalSymbol } from "../constants.mjs"; +import { extend } from "../data/extend.mjs"; +import { Pathfinder } from "../data/pathfinder.mjs"; +import { Formatter } from "../text/formatter.mjs"; + +import { parseDataURL } from "../types/dataurl.mjs"; +import { getGlobalObject } from "../types/global.mjs"; +import { isArray, isFunction, isIterable, isObject, isString } from "../types/is.mjs"; +import { Observer } from "../types/observer.mjs"; +import { ProxyObserver } from "../types/proxyobserver.mjs"; +import { validateFunction, validateInstance, validateObject, validateString } from "../types/validate.mjs"; +import { clone } from "../util/clone.mjs"; +import { addAttributeToken, getLinkedObjects, hasObjectLink } from "./attributes.mjs"; import { ATTRIBUTE_DISABLED, ATTRIBUTE_ERRORMESSAGE, @@ -25,11 +25,11 @@ import { ATTRIBUTE_OPTIONS_SELECTOR, customElementUpdaterLinkSymbol, } from "./constants.mjs"; -import {findDocumentTemplate, Template} from "./template.mjs"; -import {addObjectWithUpdaterToElement} from "./updater.mjs"; -import {instanceSymbol} from "../constants.mjs"; -import {getDocumentTranslations, Translations} from "../i18n/translations.mjs"; -import {getSlottedElements} from "./slotted.mjs"; +import { findDocumentTemplate, Template } from "./template.mjs"; +import { addObjectWithUpdaterToElement } from "./updater.mjs"; +import { instanceSymbol } from "../constants.mjs"; +import { getDocumentTranslations, Translations } from "../i18n/translations.mjs"; +import { getSlottedElements } from "./slotted.mjs"; export { CustomElement, @@ -286,7 +286,6 @@ class CustomElement extends HTMLElement { }; } - /** * This method updates the labels of the element. * The labels are defined in the options object. @@ -315,26 +314,25 @@ class CustomElement extends HTMLElement { if (isString(def)) { const text = translations.getText(key, def); if (text !== def) { - this.setOption("labels." + key, text); + this.setOption(`labels.${key}`, text); } continue; } else if (isObject(def)) { for (const k in def) { const d = def[k]; - + const text = translations.getPluralRuleText(key, k, d); if (!isString(text)) { throw new Error("Invalid labels definition"); } if (text !== d) { - this.setOption("labels." + key + "." + k, text); + this.setOption(`labels.${key}.${k}`, text); } } continue; } throw new Error("Invalid labels definition"); - } return this; } @@ -352,7 +350,6 @@ class CustomElement extends HTMLElement { throw new Error("the method getTag must be overwritten by the derived class."); } - /** * At this point a `CSSStyleSheet` object can be returned. If the environment does not * support a constructor, then an object can also be built using the following detour. @@ -422,8 +419,7 @@ class CustomElement extends HTMLElement { try { value = new Pathfinder(this[internalSymbol].getRealSubject()["options"]).getVia(path); - } catch (e) { - } + } catch (e) {} if (value === undefined) return defaultValue; return value; @@ -493,8 +489,7 @@ class CustomElement extends HTMLElement { try { initShadowRoot.call(self); elements = self.shadowRoot.childNodes; - } catch (e) { - } + } catch (e) {} try { initCSSStylesheet.call(this); @@ -545,8 +540,7 @@ class CustomElement extends HTMLElement { * @return {void} * @since 1.7.0 */ - disconnectedCallback() { - } + disconnectedCallback() {} /** * The custom element has been moved into a new document (e.g. someone called document.adoptNode(el)). @@ -554,8 +548,7 @@ class CustomElement extends HTMLElement { * @return {void} * @since 1.7.0 */ - adoptedCallback() { - } + adoptedCallback() {} /** * Called when an observed attribute has been added, removed, updated, or replaced. Also called for initial @@ -792,8 +785,7 @@ function parseOptionsJSON(data) { try { let dataUrl = parseDataURL(data); data = dataUrl.content; - } catch (e) { - } + } catch (e) {} try { obj = JSON.parse(data); @@ -815,7 +807,6 @@ function initHtmlContent() { } catch (e) { let html = this.getOption("templates.main", ""); if (isString(html) && html.length > 0) { - const mapping = this.getOption("templateMapping", {}); if (isObject(mapping)) { html = new Formatter(mapping).format(html); @@ -938,7 +929,7 @@ function initShadowRoot() { */ function registerCustomElement(element) { validateFunction(element); - const customElements = getGlobalObject("customElements") + const customElements = getGlobalObject("customElements"); if (customElements === undefined) { throw new Error("customElements is not supported."); } diff --git a/application/source/dom/dimension.mjs b/application/source/dom/dimension.mjs index b0de0e8ba71710347cdf051ebf68eea0da079478..d145a44bd422ae30762aab041183e4775db6ed4e 100644 --- a/application/source/dom/dimension.mjs +++ b/application/source/dom/dimension.mjs @@ -5,9 +5,9 @@ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html */ -import {getWindow} from './util.mjs'; +import { getWindow } from "./util.mjs"; -export {convertToPixels, getDeviceDPI} +export { convertToPixels, getDeviceDPI }; /** * Stores the DPI of the device. @@ -20,7 +20,7 @@ export {convertToPixels, getDeviceDPI} let CURRENT_DEVICE_DPI = function () { let i = 0; for (i = 56; i < 2000; i++) { - if (getWindow().matchMedia("(max-resolution: " + i + "dpi)").matches === true) { + if (getWindow().matchMedia(`(max-resolution: ${i}dpi)`).matches === true) { return i; } } @@ -36,14 +36,13 @@ let CURRENT_DEVICE_DPI = function () { */ function getDeviceDPI() { // only call the function once - if (typeof CURRENT_DEVICE_DPI === 'function') { + if (typeof CURRENT_DEVICE_DPI === "function") { CURRENT_DEVICE_DPI = CURRENT_DEVICE_DPI(); } return getWindow().devicePixelRatio * CURRENT_DEVICE_DPI; } - /** * Converts a CSS value to pixels. * @@ -79,30 +78,28 @@ function convertToPixels(value, parentElement = document.documentElement, fontSi const number = parseFloat(num); const dpi = getDeviceDPI(); - if (unit === 'px') { + if (unit === "px") { return number; - } else if (unit === 'em') { + } else if (unit === "em") { const fontSize = parseFloat(window.getComputedStyle(fontSizeElement).fontSize); return number * fontSize; - } else if (unit === 'rem') { + } else if (unit === "rem") { const rootFontSize = parseFloat(window.getComputedStyle(parentElement).fontSize); return number * rootFontSize; - } else if (unit === '%') { + } else if (unit === "%") { const parentWidth = parseFloat(window.getComputedStyle(parentElement).width); return (number * parentWidth) / 100; - } else if (unit === 'in') { + } else if (unit === "in") { return number * dpi; - } else if (unit === 'cm') { + } else if (unit === "cm") { return (number * dpi) / 2.54; - } else if (unit === 'mm') { + } else if (unit === "mm") { return (number * dpi) / 25.4; - } else if (unit === 'pt') { + } else if (unit === "pt") { return (number * dpi) / 72; - } else if (unit === 'pc') { + } else if (unit === "pc") { return (number * dpi) / 6; } else { throw new Error(`Unsupported unit: ${unit}`); } } - - diff --git a/application/source/dom/resourcemanager.mjs b/application/source/dom/resourcemanager.mjs index da0730b4566d6f960e3a397d807c24d6dfe24d5e..3457de5a303cfa13e58a2bb0bba7eb478e53422a 100644 --- a/application/source/dom/resourcemanager.mjs +++ b/application/source/dom/resourcemanager.mjs @@ -8,7 +8,7 @@ import { extend } from "../data/extend.mjs"; import { Base } from "../types/base.mjs"; import { getGlobalObject } from "../types/global.mjs"; -import {equipWithInternal} from "../types/internal.mjs"; +import { equipWithInternal } from "../types/internal.mjs"; import { isArray } from "../types/is.mjs"; import { ATTRIBUTE_HREF, ATTRIBUTE_SRC } from "./constants.mjs"; import { Resource } from "./resource.mjs"; @@ -74,14 +74,17 @@ class ResourceManager extends Base { * @property {Array} resources.data=[] array with {@link Monster.DOM.Resource.Data} objects */ get internalDefaults() { - return Object.assign({}, { - document: getGlobalObject("document"), - resources: { - scripts: [], - stylesheets: [], - data: [], + return Object.assign( + {}, + { + document: getGlobalObject("document"), + resources: { + scripts: [], + stylesheets: [], + data: [], + }, }, - }); + ); } /** diff --git a/application/source/dom/slotted.mjs b/application/source/dom/slotted.mjs index 8a47b696dc09ae04ba6b57309f2d94b95a7d3154..53f8047bc78f7d25d4b7c4703a72d9949057851d 100644 --- a/application/source/dom/slotted.mjs +++ b/application/source/dom/slotted.mjs @@ -1,7 +1,7 @@ -import {isString} from "../types/is.mjs"; -import {validateString} from "../types/validate.mjs"; +import { isString } from "../types/is.mjs"; +import { validateString } from "../types/validate.mjs"; -export {getSlottedElements, getSlottedNodes}; +export { getSlottedElements, getSlottedNodes }; /** * @private @@ -16,7 +16,7 @@ export {getSlottedElements, getSlottedNodes}; function getSlottedNodes(query, name) { const self = this; const result = new Set(); - + if (!self.shadowRoot) { return result; } @@ -57,7 +57,6 @@ function getSlottedNodes(query, name) { return result; } - /** * @private * @param {String|undefined} query diff --git a/application/source/dom/updater.mjs b/application/source/dom/updater.mjs index a92590fabbfb12cb2b8e15f4a51fbd174e33e307..6412d34c42b6ae5e8d404719d65ec46fea69f017 100644 --- a/application/source/dom/updater.mjs +++ b/application/source/dom/updater.mjs @@ -5,10 +5,10 @@ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html */ -import {internalSymbol} from "../constants.mjs"; -import {diff} from "../data/diff.mjs"; -import {Pathfinder} from "../data/pathfinder.mjs"; -import {Pipe} from "../data/pipe.mjs"; +import { internalSymbol } from "../constants.mjs"; +import { diff } from "../data/diff.mjs"; +import { Pathfinder } from "../data/pathfinder.mjs"; +import { Pipe } from "../data/pipe.mjs"; import { ATTRIBUTE_ERRORMESSAGE, ATTRIBUTE_UPDATER_ATTRIBUTES, @@ -17,21 +17,21 @@ import { ATTRIBUTE_UPDATER_INSERT_REFERENCE, ATTRIBUTE_UPDATER_REMOVE, ATTRIBUTE_UPDATER_REPLACE, - ATTRIBUTE_UPDATER_SELECT_THIS + ATTRIBUTE_UPDATER_SELECT_THIS, } from "../dom/constants.mjs"; -import {Base} from "../types/base.mjs"; -import {isArray, isInstance, isIterable} from "../types/is.mjs"; -import {Observer} from "../types/observer.mjs"; -import {ProxyObserver} from "../types/proxyobserver.mjs"; -import {validateArray, validateInstance} from "../types/validate.mjs"; -import {clone} from "../util/clone.mjs"; -import {trimSpaces} from "../util/trimspaces.mjs"; -import {addToObjectLink} from "./attributes.mjs"; -import {findTargetElementFromEvent} from "./events.mjs"; -import {findDocumentTemplate} from "./template.mjs"; +import { Base } from "../types/base.mjs"; +import { isArray, isInstance, isIterable } from "../types/is.mjs"; +import { Observer } from "../types/observer.mjs"; +import { ProxyObserver } from "../types/proxyobserver.mjs"; +import { validateArray, validateInstance } from "../types/validate.mjs"; +import { clone } from "../util/clone.mjs"; +import { trimSpaces } from "../util/trimspaces.mjs"; +import { addToObjectLink } from "./attributes.mjs"; +import { findTargetElementFromEvent } from "./events.mjs"; +import { findDocumentTemplate } from "./template.mjs"; -export {Updater, addObjectWithUpdaterToElement}; +export { Updater, addObjectWithUpdaterToElement }; /** * The updater class connects an object with the dom. In this way, structures and contents in the DOM can be programmatically adapted via attributes. @@ -172,7 +172,7 @@ class Updater extends Base { run() { // the key __init__has no further meaning and is only // used to create the diff for empty objects. - this[internalSymbol].last = {__init__: true}; + this[internalSymbol].last = { __init__: true }; return this[internalSymbol].subject.notifyObservers(); } @@ -322,7 +322,7 @@ function retrieveAndSetValue(element) { let options = element?.selectedOptions; if (options === undefined) options = element.querySelectorAll(":scope option:checked"); - value = Array.from(options).map(({value}) => value); + value = Array.from(options).map(({ value }) => value); break; } @@ -436,7 +436,7 @@ function insertElement(change) { const attributes = containerElement.getAttribute(ATTRIBUTE_UPDATER_INSERT); if (attributes === null) continue; - + let def = trimSpaces(attributes); let i = def.indexOf(" "); let key = trimSpaces(def.substr(0, i)); @@ -492,7 +492,7 @@ function insertElement(change) { let nodes = containerElement.querySelectorAll( `[${ATTRIBUTE_UPDATER_INSERT_REFERENCE}*="${refPrefix}"]`, ); - + for (const [, node] of Object.entries(nodes)) { if (!available.has(node.getAttribute(ATTRIBUTE_UPDATER_INSERT_REFERENCE))) { try { @@ -719,7 +719,7 @@ function runUpdateAttributes(container, parts, subject) { if (mem.has(element)) return; mem.add(element); - // this case occurs when the ATTRIBUTE_UPDATER_SELECT_THIS attribute is set + // this case occurs when the ATTRIBUTE_UPDATER_SELECT_THIS attribute is set if (!element.hasAttribute(ATTRIBUTE_UPDATER_ATTRIBUTES)) { continue; } diff --git a/application/source/dom/util.mjs b/application/source/dom/util.mjs index 38c5e14175e3ef9eb74f7e0cff6521b4fd557339..42939ea8e9dab954dc34361f3b1928ac65b20d53 100644 --- a/application/source/dom/util.mjs +++ b/application/source/dom/util.mjs @@ -152,7 +152,6 @@ function getDocumentFragmentFromString(html) { return template.content; } - /** * Recursively searches upwards from a given element to find an ancestor element * with a specified ID, considering both normal DOM and shadow DOM. @@ -199,4 +198,4 @@ function findElementWithIdUpwards(element, targetId) { // Otherwise, search the current element's parent return findElementWithIdUpwards(element.parentElement, targetId); -} \ No newline at end of file +} diff --git a/application/source/i18n/formatter.mjs b/application/source/i18n/formatter.mjs index a30bb4470829e7826f6ff3c9d977fb1fdb6b93e1..2ea43acb0fd051b5fab348351e6d7a7865dc9108 100644 --- a/application/source/i18n/formatter.mjs +++ b/application/source/i18n/formatter.mjs @@ -5,14 +5,14 @@ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html */ -import {instanceSymbol, internalSymbol} from "../constants.mjs"; -import {extend} from "../data/extend.mjs"; +import { instanceSymbol, internalSymbol } from "../constants.mjs"; +import { extend } from "../data/extend.mjs"; -import {Formatter as TextFormatter} from "../text/formatter.mjs"; -import {validateInstance, validateString} from "../types/validate.mjs"; -import {Translations} from "./translations.mjs"; +import { Formatter as TextFormatter } from "../text/formatter.mjs"; +import { validateInstance, validateString } from "../types/validate.mjs"; +import { Translations } from "./translations.mjs"; -export {Formatter}; +export { Formatter }; /** * @private diff --git a/application/source/i18n/locale.mjs b/application/source/i18n/locale.mjs index 6eefd159798870e5a8972062a165902b3dd6c1ed..2511ba9c507325da3c4c3099956034ecba240f56 100644 --- a/application/source/i18n/locale.mjs +++ b/application/source/i18n/locale.mjs @@ -5,7 +5,7 @@ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html */ -import {instanceSymbol} from "../constants.mjs"; +import { instanceSymbol } from "../constants.mjs"; import { Base } from "../types/base.mjs"; import { validateString } from "../types/validate.mjs"; import { clone } from "../util/clone.mjs"; diff --git a/application/source/i18n/provider.mjs b/application/source/i18n/provider.mjs index 16577cc99925c1f29e1e7264031b4f66e871a404..8a5207d63b50ff3ea57eca066a188305e6483d96 100644 --- a/application/source/i18n/provider.mjs +++ b/application/source/i18n/provider.mjs @@ -5,14 +5,14 @@ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html */ -import {instanceSymbol} from "../constants.mjs"; -import {hasObjectLink, getLinkedObjects,addToObjectLink} from "../dom/attributes.mjs"; -import {getLocaleOfDocument} from "../dom/locale.mjs"; -import {BaseWithOptions} from "../types/basewithoptions.mjs"; -import {Locale} from "./locale.mjs"; -import {Translations} from "./translations.mjs"; +import { instanceSymbol } from "../constants.mjs"; +import { hasObjectLink, getLinkedObjects, addToObjectLink } from "../dom/attributes.mjs"; +import { getLocaleOfDocument } from "../dom/locale.mjs"; +import { BaseWithOptions } from "../types/basewithoptions.mjs"; +import { Locale } from "./locale.mjs"; +import { Translations } from "./translations.mjs"; -export {Provider, translationsLinkSymbol}; +export { Provider, translationsLinkSymbol }; /** * @memberOf Monster.I18n @@ -33,7 +33,6 @@ const translationsLinkSymbol = Symbol.for("@schukai/monster/i18n/translations@@l * @see {@link https://datatracker.ietf.org/doc/html/rfc3066} */ class Provider extends BaseWithOptions { - /** * This method is called by the `instanceof` operator. * @returns {symbol} @@ -41,14 +40,13 @@ class Provider extends BaseWithOptions { */ static get [instanceSymbol]() { return Symbol.for("@schukai/monster/i18n/provider@@instance"); - } - + } + /** * @param {Locale|string} locale * @return {Promise} */ getTranslations(locale) { - if (locale === undefined) { locale = getLocaleOfDocument(); } @@ -68,7 +66,6 @@ class Provider extends BaseWithOptions { * @return {Provider} */ assignToElement(locale, element) { - if (locale === undefined) { locale = getLocaleOfDocument(); } @@ -86,7 +83,6 @@ class Provider extends BaseWithOptions { } return this.getTranslations(locale).then((obj) => { - let translations = null; if (hasObjectLink(element, translationsLinkSymbol)) { const objects = getLinkedObjects(element, translationsLinkSymbol); @@ -96,21 +92,17 @@ class Provider extends BaseWithOptions { break; } } - + if (!(translations instanceof Translations)) { throw new Error("Object is not an instance of Translations"); } - + translations.assignTranslations(obj); - } else { addToObjectLink(element, translationsLinkSymbol, obj); } - return obj; }); - } - } diff --git a/application/source/i18n/providers/embed.mjs b/application/source/i18n/providers/embed.mjs index e15b5d9631534c3ce595272bcd219daa9c6624a8..00744830d700df57e1544eec9fbd5acae1bac650 100644 --- a/application/source/i18n/providers/embed.mjs +++ b/application/source/i18n/providers/embed.mjs @@ -5,16 +5,16 @@ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html */ -import {internalSymbol} from "../../constants.mjs"; -import {extend} from "../../data/extend.mjs"; -import {getDocument} from "../../dom/util.mjs"; -import {isString} from "../../types/is.mjs"; -import {validateObject, validateString} from "../../types/validate.mjs"; -import {parseLocale} from "../locale.mjs"; -import {Provider} from "../provider.mjs"; -import {Translations} from "../translations.mjs"; +import { internalSymbol } from "../../constants.mjs"; +import { extend } from "../../data/extend.mjs"; +import { getDocument } from "../../dom/util.mjs"; +import { isString } from "../../types/is.mjs"; +import { validateObject, validateString } from "../../types/validate.mjs"; +import { parseLocale } from "../locale.mjs"; +import { Provider } from "../provider.mjs"; +import { Translations } from "../translations.mjs"; -export {Embed}; +export { Embed }; /** * The Embed provider retrieves a JSON file from the given Script Tag. @@ -91,7 +91,6 @@ class Embed extends Provider { } return new Promise((resolve, reject) => { - if (this.translateElement === null) { reject(new Error("Text not found")); return; @@ -127,7 +126,6 @@ class Embed extends Provider { }); } - /** * Initializes the translations for the current document. * @@ -137,7 +135,7 @@ class Embed extends Provider { * @returns {Promise<unknown[]>} */ static assignTranslationsToElement(element) { - const d = getDocument() + const d = getDocument(); if (!(element instanceof HTMLElement)) { element = d.querySelector("body"); @@ -149,7 +147,7 @@ class Embed extends Provider { } const promises = []; - + list.forEach((translationElement) => { const p = new Embed(translationElement); promises.push(p.assignToElement(undefined, element)); @@ -157,5 +155,4 @@ class Embed extends Provider { return Promise.all(promises); } - } diff --git a/application/source/i18n/translations.mjs b/application/source/i18n/translations.mjs index 9f5678e15a83d754b15621275bf274437648810f..e7589ef211e9a9541e5ff52ee9cfe320a855de85 100644 --- a/application/source/i18n/translations.mjs +++ b/application/source/i18n/translations.mjs @@ -5,18 +5,17 @@ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html */ -import {instanceSymbol} from "../constants.mjs"; -import {getLinkedObjects, hasObjectLink} from "../dom/attributes.mjs"; -import {ATTRIBUTE_OBJECTLINK} from "../dom/constants.mjs"; -import {getDocument} from "../dom/util.mjs"; -import {Base} from "../types/base.mjs"; -import {isObject, isString} from "../types/is.mjs"; -import {validateInteger, validateObject, validateString} from "../types/validate.mjs"; -import {Locale, parseLocale} from "./locale.mjs"; -import {translationsLinkSymbol} from "./provider.mjs"; - - -export {Translations, getDocumentTranslations}; +import { instanceSymbol } from "../constants.mjs"; +import { getLinkedObjects, hasObjectLink } from "../dom/attributes.mjs"; +import { ATTRIBUTE_OBJECTLINK } from "../dom/constants.mjs"; +import { getDocument } from "../dom/util.mjs"; +import { Base } from "../types/base.mjs"; +import { isObject, isString } from "../types/is.mjs"; +import { validateInteger, validateObject, validateString } from "../types/validate.mjs"; +import { Locale, parseLocale } from "./locale.mjs"; +import { translationsLinkSymbol } from "./provider.mjs"; + +export { Translations, getDocumentTranslations }; /** * With this class you can manage translations and access the keys. @@ -211,11 +210,10 @@ class Translations extends Base { * @memberOf Monster.I18n */ function getDocumentTranslations(element) { - - const d = getDocument() + const d = getDocument(); if (!(element instanceof HTMLElement)) { - element = d.querySelector('[' + ATTRIBUTE_OBJECTLINK + '~="' + translationsLinkSymbol.toString() + '"]'); + element = d.querySelector(`[${ATTRIBUTE_OBJECTLINK}~="${translationsLinkSymbol.toString()}"]`); if (element === null) { throw new Error("Cannot find element with translations. Add a translations object to the document."); } @@ -238,7 +236,4 @@ function getDocumentTranslations(element) { } throw new Error("Missing translations."); - } - - diff --git a/application/source/text/util.mjs b/application/source/text/util.mjs index 5c71e7d3b566a72c7cf7c3803b811a5950d9752e..64704efcc74f9a3880d0083b8c7606da304e44d8 100644 --- a/application/source/text/util.mjs +++ b/application/source/text/util.mjs @@ -1,7 +1,40 @@ -export {generateRangeComparisonExpression} +export { generateRangeComparisonExpression }; /** - * Generates a comparison expression for a comma-separated string of ranges and single values. + * The `generateRangeComparisonExpression()` function is function that generates a string representation + * of a comparison expression based on a range of values. It takes three arguments: + * + * - expression (required): a string representation of a range of values in the format of start1-end1,start2-end2,value3.... + * - valueName (required): a string representing the name of the value that is being compared to the range of values. + * - options (optional): an object containing additional options to customize the comparison expression. + * + * The generateRangeComparisonExpression() function returns a string representation of the comparison expression. + * + * ## Options + * The options parameter is an object that can have the following properties: + * + * urlEncode (boolean, default: false): if set to true, URL encodes the comparison operators. + * andOp (string, default: '&&'): the logical AND operator to use in the expression. + * orOp (string, default: '||'): the logical OR operator to use in the expression. + * eqOp (string, default: '=='): the equality operator to use in the expression. + * geOp (string, default: '>='): the greater than or equal to operator to use in the expression. + * leOp (string, default: '<='): the less than or equal to operator to use in the expression. + * + * Examples + * + * ```javascript + * const expression = '0-10,20-30'; + * const valueName = 'age'; + * const options = { urlEncode: true, andOp: 'and', orOp: 'or', eqOp: '=', geOp: '>=', leOp: '<=' }; + * const comparisonExpression = generateRangeComparisonExpression(expression, valueName, options); + * + * console.log(comparisonExpression); // age%3E%3D0%20and%20age%3C%3D10%20or%20age%3E%3D20%20and%20age%3C%3D30 + * ``` + * + * In this example, the generateRangeComparisonExpression() function generates a string representation of the comparison + * expression for the expression and valueName parameters with the specified options. The resulting comparison + * expression is 'age>=0 and age<=10 or age>=20 and age<=30', URL encoded according to the urlEncode option. + * * @param {string} expression - The string expression to generate the comparison for. * @param {string} valueName - The name of the value to compare against. * @param {Object} [options] - The optional parameters. @@ -13,33 +46,29 @@ export {generateRangeComparisonExpression} * @param {string} [options.leOp='<='] - The comparison operator for less than or equal to to use. * @returns {string} The generated comparison expression. * @throws {Error} If the input is invalid. + * @memberOf Monster.Text + * @summary Generates a comparison expression based on a range of values. */ function generateRangeComparisonExpression(expression, valueName, options = {}) { - const { - urlEncode = false, - andOp = '&&', - orOp = '||', - eqOp = '==', - geOp = '>=', - leOp = '<=', - } = options; - const ranges = expression.split(','); - let comparison = ''; + const { urlEncode = false, andOp = "&&", orOp = "||", eqOp = "==", geOp = ">=", leOp = "<=" } = options; + const ranges = expression.split(","); + let comparison = ""; for (let i = 0; i < ranges.length; i++) { const range = ranges[i].trim(); - if (range === '') { + if (range === "") { throw new Error(`Invalid range '${range}'`); - } else if (range.includes('-')) { - const [start, end] = range.split('-').map(s => (s === '' ? null : parseFloat(s))); + } else if (range.includes("-")) { + const [start, end] = range.split("-").map((s) => (s === "" ? null : parseFloat(s))); if ((start !== null && isNaN(start)) || (end !== null && isNaN(end))) { throw new Error(`Invalid value in range '${range}'`); } if (start !== null && end !== null && start > end) { throw new Error(`Invalid range '${range}'`); } - const compStart = start !== null ? `${valueName}${urlEncode ? encodeURIComponent(geOp) : geOp}${start}` : ''; - const compEnd = end !== null ? `${valueName}${urlEncode ? encodeURIComponent(leOp) : leOp}${end}` : ''; - const compRange = `${compStart}${compStart && compEnd ? ` ${andOp} ` : ''}${compEnd}`; + const compStart = + start !== null ? `${valueName}${urlEncode ? encodeURIComponent(geOp) : geOp}${start}` : ""; + const compEnd = end !== null ? `${valueName}${urlEncode ? encodeURIComponent(leOp) : leOp}${end}` : ""; + const compRange = `${compStart}${compStart && compEnd ? ` ${andOp} ` : ""}${compEnd}`; comparison += ranges.length > 1 ? `(${compRange})` : compRange; } else { const value = parseFloat(range); diff --git a/application/source/types/base.mjs b/application/source/types/base.mjs index 5675c32a004cb2626fecbefe645090200d007e61..1e48be0780dd4b92b4f87171a4b1491a0bc00473 100644 --- a/application/source/types/base.mjs +++ b/application/source/types/base.mjs @@ -17,7 +17,7 @@ export { Base }; * * Therefor the class has a static method ` [Symbol.hasInstance](that)` which returns true if the object * is an instance of the class. - * + * * @see [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance](developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance) * * Derived classes should implement a static getter `instanceSymbol` which returns a unique symbol. diff --git a/application/source/types/internal.mjs b/application/source/types/internal.mjs index 5a14cf4c5b07bc9bbb1493ab437d229ea81ae5d6..323b4068e2764d5fcea9b30c22b060c8f704aa16 100644 --- a/application/source/types/internal.mjs +++ b/application/source/types/internal.mjs @@ -4,34 +4,34 @@ * This file is licensed under the AGPLv3 License. * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html */ -import {internalSymbol} from "../constants.mjs"; -import {extend} from "../data/extend.mjs"; -import {Pathfinder} from "../data/pathfinder.mjs"; -import {parseDataURL} from "./dataurl.mjs"; -import {isString} from "./is.mjs"; -import {Observer} from "./observer.mjs"; -import {ProxyObserver} from "./proxyobserver.mjs"; -import {validateObject} from "./validate.mjs"; -import {isObject} from "./is.mjs"; - -export {equipWithInternal} +import { internalSymbol } from "../constants.mjs"; +import { extend } from "../data/extend.mjs"; +import { Pathfinder } from "../data/pathfinder.mjs"; +import { parseDataURL } from "./dataurl.mjs"; +import { isString } from "./is.mjs"; +import { Observer } from "./observer.mjs"; +import { ProxyObserver } from "./proxyobserver.mjs"; +import { validateObject } from "./validate.mjs"; +import { isObject } from "./is.mjs"; + +export { equipWithInternal }; /** * @private * @type {string} */ -const propertyName = 'internalDefaults' +const propertyName = "internalDefaults"; /** * This function extends the given object with the following methods: - * + * * - attachInternalObserver * - detachInternalObserver * - containsInternalObserver * - setInternal * - setInternals * - getInternal - * + * * @license AGPLv3 * @since 3.15.0 * @copyright schukai GmbH @@ -45,7 +45,7 @@ function equipWithInternal() { Object.defineProperty(self, propertyName, { get: function () { return {}; - } + }, }); } @@ -61,7 +61,7 @@ function equipWithInternal() { self["attachInternalObserver"] = (observer) => { self[internalSymbol].attachObserver(observer); return self; - } + }; /** * Detach a observer @@ -72,18 +72,17 @@ function equipWithInternal() { self["detachInternalObserver"] = (observer) => { self[internalSymbol].detachObserver(observer); return self; - } + }; /** * Check if a observer is attached - * + * * @param {Observer} observer * @returns {boolean} */ self["containsInternalObserver"] = (observer) => { return self[internalSymbol].containsObserver(observer); - } - + }; /** * Set an internal value, nested internals can be specified by path `a.b.c` @@ -95,11 +94,11 @@ function equipWithInternal() { self["setInternal"] = (path, value) => { new Pathfinder(self[internalSymbol].getSubject()).setVia(path, value); return self; - } + }; /** * set multiple internals at once - * + * * @param {string|object} options * @return {Datasource} * @throws {Error} the options does not contain a valid json definition @@ -111,7 +110,7 @@ function equipWithInternal() { extend(self[internalSymbol].getSubject(), defaults, options); return self; - } + }; /** * nested internals can be specified by path `a.b.c` @@ -124,14 +123,12 @@ function equipWithInternal() { let value; try { - value = new Pathfinder(self[internalSymbol] - .getRealSubject()).getVia(path); - } catch (e) { - } + value = new Pathfinder(self[internalSymbol].getRealSubject()).getVia(path); + } catch (e) {} if (value === undefined) return defaultValue; return value; - } + }; } /** @@ -141,9 +138,8 @@ function equipWithInternal() { * @return {boolean} */ function hasGetter(obj, prop) { - while (isObject(obj)) { - if (Object.getOwnPropertyDescriptor(obj, prop)?.['get']) { + if (Object.getOwnPropertyDescriptor(obj, prop)?.["get"]) { return true; } obj = Object.getPrototypeOf(obj); @@ -168,8 +164,7 @@ function parseOptionsJSON(data) { try { let dataUrl = parseDataURL(data); data = dataUrl.content; - } catch (e) { - } + } catch (e) {} try { obj = JSON.parse(data); diff --git a/application/source/util/runtime.mjs b/application/source/util/runtime.mjs index 7040fc2526a70a5f2815514e63c83c84c2c06563..41803e3a1aba5a180be49daf3e51c4d0ae5c77b3 100644 --- a/application/source/util/runtime.mjs +++ b/application/source/util/runtime.mjs @@ -5,18 +5,50 @@ * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html */ -const ENV_AWS_LAMBDA = 'aws-lambda'; -const ENV_GOOGLE_FUNCTIONS = 'google-functions'; -const ENV_ELECTRON = 'electron'; -const ENV_NODE = 'node'; -const ENV_BROWSER = 'browser'; -const ENV_WEB_WORKER = 'web-worker'; -const ENV_DENO = 'deno'; -const ENV_UNKNOWN = 'unknown'; +/** + * @memberOf Monster.Util + * @type {string} + */ +const ENV_AWS_LAMBDA = "aws-lambda"; +/** + * @memberOf Monster.Util + * @type {string} + */ +const ENV_GOOGLE_FUNCTIONS = "google-functions"; +/** + * @memberOf Monster.Util + * @type {string} + */ +const ENV_ELECTRON = "electron"; +/** + * @memberOf Monster.Util + * @type {string} + */ +const ENV_NODE = "node"; +/** + * @memberOf Monster.Util + * @type {string} + */ +const ENV_BROWSER = "browser"; +/** + * @memberOf Monster.Util + * @type {string} + */ +const ENV_WEB_WORKER = "web-worker"; +/** + * @memberOf Monster.Util + * @type {string} + */ +const ENV_DENO = "deno"; +/** + * @memberOf Monster.Util + * @type {string} + */ +const ENV_UNKNOWN = "unknown"; /** * Detects and returns the current runtime environment. - * + * * - 'aws-lambda': AWS Lambda environment * - 'google-functions': Google Cloud Functions environment * - 'electron': Electron environment @@ -26,36 +58,24 @@ const ENV_UNKNOWN = 'unknown'; * - 'deno': Deno environment * - 'react-native': React Native environment * - 'unknown': Unknown environment - * + * * @since 3.34.0 * @memberOf Monster.Util * @returns {string} The detected runtime environment. Possible values are: */ function detectRuntimeEnvironment() { // AWS Lambda environment - if ( - typeof process !== 'undefined' && - process.env != null && - process.env.AWS_LAMBDA_FUNCTION_NAME - ) { + if (typeof process !== "undefined" && process.env != null && process.env.AWS_LAMBDA_FUNCTION_NAME) { return ENV_AWS_LAMBDA; } // Google Cloud Functions environment - if ( - typeof process !== 'undefined' && - process.env != null && - process.env.FUNCTION_NAME - ) { + if (typeof process !== "undefined" && process.env != null && process.env.FUNCTION_NAME) { return ENV_GOOGLE_FUNCTIONS; } // Node.js environment - if ( - typeof process !== 'undefined' && - process.versions != null && - process.versions.node != null - ) { + if (typeof process !== "undefined" && process.versions != null && process.versions.node != null) { // Electron environment if (process.versions.electron != null) { return ENV_ELECTRON; @@ -65,20 +85,20 @@ function detectRuntimeEnvironment() { // Browser environment if ( - typeof window !== 'undefined' && - typeof window.document !== 'undefined' && - typeof navigator !== 'undefined' && - typeof navigator.userAgent === 'string' + typeof window !== "undefined" && + typeof window.document !== "undefined" && + typeof navigator !== "undefined" && + typeof navigator.userAgent === "string" ) { // Web Worker environment - if (typeof self === 'object' && typeof importScripts === 'function') { + if (typeof self === "object" && typeof importScripts === "function") { return ENV_WEB_WORKER; } return ENV_BROWSER; } // Deno environment - if (typeof Deno !== 'undefined') { + if (typeof Deno !== "undefined") { return ENV_DENO; } @@ -95,4 +115,5 @@ export { ENV_WEB_WORKER, ENV_DENO, ENV_UNKNOWN, - detectRuntimeEnvironment} \ No newline at end of file + detectRuntimeEnvironment, +}; diff --git a/development/makefiles/project.mk b/development/makefiles/project.mk index fd40910d9e70d6412e5e9919bb62a2d649c27a7c..36e051efc6ad73755b1ad792d05420b787ff64e0 100644 --- a/development/makefiles/project.mk +++ b/development/makefiles/project.mk @@ -2,3 +2,4 @@ +DOCUMENTATION_S3_PATH ?= s3://monsterjs.org/en/doc/$(COMPONENT_SLUG)/ \ No newline at end of file diff --git a/documentation/README.md b/documentation/README.md index f6b55931709d5e5ecd9c32056aa8267ea70175b0..d8921164ec1a576a5fee59f04e47eec4a74f9e6e 100644 --- a/documentation/README.md +++ b/documentation/README.md @@ -1,20 +1,31 @@ -# Monster JS +# MonsterJS ## Introduction -Monster JS is a JavaScript library for creating interactive web applications. +MonsterJS is a versatile JavaScript library designed to simplify the development of interactive web applications. It offers a range of functionalities, including DOM manipulation, internationalization (i18n), and data processing capabilities. ## Installation - npm install @schukai/monster +To install MonsterJS, use the following command: +```bash +npm install @schukai/monster +``` ## Usage - import Monster from '@schukai/monster'; - +Import MonsterJS into your project: -## License +```javascript +import Monster from '@schukai/monster'; +``` + +Then, you can use MonsterJS's features to enhance your web application. + +## Documentation - AGPL-3.0 +For detailed documentation and examples of how to use MonsterJS, please visit the official MonsterJS documentation. + +## License +This project is licensed under the AGPL-3.0 License. \ No newline at end of file