Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
Loading items

Target

Select target project
  • oss/libraries/javascript/monster
1 result
Select Git revision
Loading items
Show changes
Commits on Source (7)
<a name="v3.8.0"></a>
## [v3.8.0] - 2023-02-01
### Add Features
- pathfinder now works with array
### Changes
- code format (rome)
- doc
- docs
<a name="v3.7.0"></a> <a name="v3.7.0"></a>
## [v3.7.0] - 2023-01-26 ## [v3.7.0] - 2023-01-26
### Bug Fixes ### Bug Fixes
...@@ -218,6 +229,7 @@ ...@@ -218,6 +229,7 @@
<a name="1.8.0"></a> <a name="1.8.0"></a>
## 1.8.0 - 2021-08-15 ## 1.8.0 - 2021-08-15
[v3.8.0]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.7.0...v3.8.0
[v3.7.0]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.6.0...v3.7.0 [v3.7.0]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.6.0...v3.7.0
[v3.6.0]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.5.0...v3.6.0 [v3.6.0]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.5.0...v3.6.0
[v3.5.0]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.4.2...v3.5.0 [v3.5.0]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.4.2...v3.5.0
......
{ {
"name": "@schukai/monster", "name": "@schukai/monster",
"version": "3.5.0", "version": "3.7.0",
"description": "Monster is a simple library for creating fast, robust and lightweight websites.", "description": "Monster is a simple library for creating fast, robust and lightweight websites.",
"keywords": [ "keywords": [
"framework", "framework",
......
...@@ -6,9 +6,9 @@ ...@@ -6,9 +6,9 @@
*/ */
import { Base } from "../types/base.mjs"; import { Base } from "../types/base.mjs";
import { isArray, isInteger, isObject, isPrimitive } from "../types/is.mjs"; import { isArray, isInteger, isObject, isPrimitive, isString } from "../types/is.mjs";
import { Stack } from "../types/stack.mjs"; import { Stack } from "../types/stack.mjs";
import { validateInteger, validateString } from "../types/validate.mjs"; import { validateInteger, validateBoolean, validateString } from "../types/validate.mjs";
export { Pathfinder, DELIMITER, WILDCARD }; export { Pathfinder, DELIMITER, WILDCARD };
...@@ -103,7 +103,7 @@ class Pathfinder extends Base { ...@@ -103,7 +103,7 @@ class Pathfinder extends Base {
/** /**
* *
* @param {string} path * @param {string|array} path
* @since 1.4.0 * @since 1.4.0
* @returns {*} * @returns {*}
* @throws {TypeError} unsupported type * @throws {TypeError} unsupported type
...@@ -113,12 +113,12 @@ class Pathfinder extends Base { ...@@ -113,12 +113,12 @@ class Pathfinder extends Base {
* @throws {Error} unsupported action for this data type * @throws {Error} unsupported action for this data type
*/ */
getVia(path) { getVia(path) {
return getValueViaPath.call(this, this.object, validateString(path)); return getValueViaPath.call(this, this.object, path);
} }
/** /**
* *
* @param {string} path * @param {string|array} path
* @param {*} value * @param {*} value
* @returns {Pathfinder} * @returns {Pathfinder}
* @since 1.4.0 * @since 1.4.0
...@@ -128,7 +128,6 @@ class Pathfinder extends Base { ...@@ -128,7 +128,6 @@ class Pathfinder extends Base {
* @throws {Error} unsupported action for this data type * @throws {Error} unsupported action for this data type
*/ */
setVia(path, value) { setVia(path, value) {
validateString(path);
setValueViaPath.call(this, this.object, path, value); setValueViaPath.call(this, this.object, path, value);
return this; return this;
} }
...@@ -136,7 +135,7 @@ class Pathfinder extends Base { ...@@ -136,7 +135,7 @@ class Pathfinder extends Base {
/** /**
* Delete Via Path * Delete Via Path
* *
* @param {string} path * @param {string|array} path
* @returns {Pathfinder} * @returns {Pathfinder}
* @since 1.6.0 * @since 1.6.0
* @throws {TypeError} unsupported type * @throws {TypeError} unsupported type
...@@ -145,14 +144,13 @@ class Pathfinder extends Base { ...@@ -145,14 +144,13 @@ class Pathfinder extends Base {
* @throws {Error} unsupported action for this data type * @throws {Error} unsupported action for this data type
*/ */
deleteVia(path) { deleteVia(path) {
validateString(path);
deleteValueViaPath.call(this, this.object, path); deleteValueViaPath.call(this, this.object, path);
return this; return this;
} }
/** /**
* *
* @param {string} path * @param {string|array} path
* @return {bool} * @return {bool}
* @throws {TypeError} unsupported type * @throws {TypeError} unsupported type
* @throws {TypeError} value is not a string * @throws {TypeError} value is not a string
...@@ -160,7 +158,6 @@ class Pathfinder extends Base { ...@@ -160,7 +158,6 @@ class Pathfinder extends Base {
* @since 1.4.0 * @since 1.4.0
*/ */
exists(path) { exists(path) {
validateString(path);
try { try {
getValueViaPath.call(this, this.object, path, true); getValueViaPath.call(this, this.object, path, true);
return true; return true;
...@@ -173,8 +170,8 @@ class Pathfinder extends Base { ...@@ -173,8 +170,8 @@ class Pathfinder extends Base {
/** /**
* *
* @param {*} subject * @param {*} subject
* @param {string} path * @param {string|array} path
* @param {string} check * @param {boolean} check
* @return {Map} * @return {Map}
* @throws {TypeError} unsupported type * @throws {TypeError} unsupported type
* @throws {Error} the journey is not at its end * @throws {Error} the journey is not at its end
...@@ -182,8 +179,17 @@ class Pathfinder extends Base { ...@@ -182,8 +179,17 @@ class Pathfinder extends Base {
* @private * @private
*/ */
function iterate(subject, path, check) { function iterate(subject, path, check) {
if (check === undefined) {
check = false;
}
validateBoolean(check);
const result = new Map(); const result = new Map();
if (isArray(path)) {
path = path.join(DELIMITER);
}
if (isObject(subject) || isArray(subject)) { if (isObject(subject) || isArray(subject)) {
for (const [key, value] of Object.entries(subject)) { for (const [key, value] of Object.entries(subject)) {
result.set(key, getValueViaPath.call(this, value, path, check)); result.set(key, getValueViaPath.call(this, value, path, check));
...@@ -199,7 +205,7 @@ function iterate(subject, path, check) { ...@@ -199,7 +205,7 @@ function iterate(subject, path, check) {
/** /**
* *
* @param {*} subject * @param {*} subject
* @param [string} path * @param [string|array} path
* @param [boolean} check * @param [boolean} check
* @returns {*} * @returns {*}
* @throws {TypeError} unsupported type * @throws {TypeError} unsupported type
...@@ -208,11 +214,24 @@ function iterate(subject, path, check) { ...@@ -208,11 +214,24 @@ function iterate(subject, path, check) {
* @private * @private
*/ */
function getValueViaPath(subject, path, check) { function getValueViaPath(subject, path, check) {
if (check === undefined) {
check = false;
}
validateBoolean(check);
if (!(isArray(path) || isString(path))) {
throw new Error("type error: path must be a string or an array");
}
let parts;
if (isString(path)) {
if (path === "") { if (path === "") {
return subject; return subject;
} }
let parts = path.split(DELIMITER); parts = path.split(DELIMITER);
}
let current = parts.shift(); let current = parts.shift();
if (current === this.wildCard) { if (current === this.wildCard) {
...@@ -261,9 +280,9 @@ function getValueViaPath(subject, path, check) { ...@@ -261,9 +280,9 @@ function getValueViaPath(subject, path, check) {
/** /**
* *
* @param object * @param {object} subject
* @param path * @param {string|array} path
* @param value * @param {*} value
* @returns {void} * @returns {void}
* @throws {TypeError} unsupported type * @throws {TypeError} unsupported type
* @throws {TypeError} unsupported type * @throws {TypeError} unsupported type
...@@ -271,10 +290,22 @@ function getValueViaPath(subject, path, check) { ...@@ -271,10 +290,22 @@ function getValueViaPath(subject, path, check) {
* @throws {Error} unsupported action for this data type * @throws {Error} unsupported action for this data type
* @private * @private
*/ */
function setValueViaPath(object, path, value) { function setValueViaPath(subject, path, value) {
validateString(path); if (!(isArray(path) || isString(path))) {
throw new Error("type error: path must be a string or an array");
}
let parts;
if (isArray(path)) {
if (path.length === 0) {
return subject;
}
parts = path;
} else {
parts = path.split(DELIMITER);
}
let parts = path.split(DELIMITER);
let last = parts.pop(); let last = parts.pop();
let subpath = parts.join(DELIMITER); let subpath = parts.join(DELIMITER);
...@@ -282,7 +313,7 @@ function setValueViaPath(object, path, value) { ...@@ -282,7 +313,7 @@ function setValueViaPath(object, path, value) {
let current = subpath; let current = subpath;
while (true) { while (true) {
try { try {
getValueViaPath.call(this, object, current, true); getValueViaPath.call(this, subject, current, true);
break; break;
} catch (e) {} } catch (e) {}
...@@ -304,13 +335,13 @@ function setValueViaPath(object, path, value) { ...@@ -304,13 +335,13 @@ function setValueViaPath(object, path, value) {
} }
} }
setValueViaPath.call(this, object, current, obj); setValueViaPath.call(this, subject, current, obj);
} }
let anchor = getValueViaPath.call(this, object, subpath); let anchor = getValueViaPath.call(this, subject, subpath);
if (!(isObject(object) || isArray(object))) { if (!(isObject(subject) || isArray(subject))) {
throw TypeError(`unsupported type: ${typeof object}`); throw TypeError(`unsupported type: ${typeof subject}`);
} }
if (anchor instanceof Map || anchor instanceof WeakMap) { if (anchor instanceof Map || anchor instanceof WeakMap) {
...@@ -349,8 +380,8 @@ function assignProperty(object, key, value) { ...@@ -349,8 +380,8 @@ function assignProperty(object, key, value) {
/** /**
* *
* @param object * @param {object} subject
* @param path * @param {string} path
* @returns {void} * @returns {void}
* @throws {TypeError} unsupported type * @throws {TypeError} unsupported type
* @throws {TypeError} unsupported type * @throws {TypeError} unsupported type
...@@ -360,12 +391,26 @@ function assignProperty(object, key, value) { ...@@ -360,12 +391,26 @@ function assignProperty(object, key, value) {
* @since 1.6.0 * @since 1.6.0
* @private * @private
*/ */
function deleteValueViaPath(object, path) { function deleteValueViaPath(subject, path) {
const parts = path.split(DELIMITER); if (!(isArray(path) || isString(path))) {
throw new Error("type error: path must be a string or an array");
}
let parts;
if (isArray(path)) {
if (path.length === 0) {
return subject;
}
parts = path;
} else {
parts = path.split(DELIMITER);
}
let last = parts.pop(); let last = parts.pop();
const subpath = parts.join(DELIMITER); const subpath = parts.join(DELIMITER);
const anchor = getValueViaPath.call(this, object, subpath); const anchor = getValueViaPath.call(this, subject, subpath);
if (anchor instanceof Map) { if (anchor instanceof Map) {
anchor.delete(last); anchor.delete(last);
......
...@@ -20,12 +20,13 @@ const DEFAULT_LANGUAGE = "en"; ...@@ -20,12 +20,13 @@ const DEFAULT_LANGUAGE = "en";
/** /**
* With this function you can read the language version set by the document. * With this function you can read the language version set by the document.
* For this the attribute `lang` in the html tag is read. If no attribute is set, `en` is used as default. * For this the attribute `lang` in the html tag is read. If no attribute is set, `en` is used as default.
* Alternatively, the language version of the browser is used.
* *
* ```html * ```html
* <html lang="en"> * <html lang="en">
* ``` * ```
* *
* You can call the function via the monster namespace `new Monster.DOM.getLocaleOfDocument()`. * You can call the function via `getLocaleOfDocument()`.
* *
* @license AGPLv3 * @license AGPLv3
* @since 1.13.0 * @since 1.13.0
......
...@@ -182,22 +182,11 @@ class Locale extends Base { ...@@ -182,22 +182,11 @@ class Locale extends Base {
* *
* Limitations: The regex cannot handle multiple variants or private. * Limitations: The regex cannot handle multiple variants or private.
* *
* You can call the method via the monster namespace `Monster.I18n.createLocale()`. * You can call the method via this function individually:
* *
* ``` * ```javascript
* <script type="module">
* import {Monster} from '@schukai/monster/source/monster.mjs';
* new Monster.I18n.createLocale()
* </script>
* ```
*
* Alternatively, you can also integrate this function individually.
*
* ```
* <script type="module">
* import {createLocale} from '@schukai/monster/source/i18n/locale.mjs'; * import {createLocale} from '@schukai/monster/source/i18n/locale.mjs';
* createLocale() * createLocale()
* </script>
* ``` * ```
* *
* RFC * RFC
......
...@@ -112,9 +112,9 @@ class Translations extends Base { ...@@ -112,9 +112,9 @@ class Translations extends Base {
* Set a text for a key * Set a text for a key
* *
* ``` * ```
* translations.setText("text1": "Make my day!"); * translations.setText("text1", "Make my day!");
* // plural rules * // plural rules
* translations.setText("text6": { * translations.setText("text6", {
* "zero": "There are no files on Disk.", * "zero": "There are no files on Disk.",
* "one": "There is one file on Disk.", * "one": "There is one file on Disk.",
* "other": "There are files on Disk." * "other": "There are files on Disk."
......
...@@ -142,7 +142,7 @@ function getMonsterVersion() { ...@@ -142,7 +142,7 @@ function getMonsterVersion() {
} }
/** don't touch, replaced by make with package.json version */ /** don't touch, replaced by make with package.json version */
monsterVersion = new Version("3.5.0"); monsterVersion = new Version("3.7.0");
return monsterVersion; return monsterVersion;
} }
{ {
"name": "monster", "name": "monster",
"version": "3.5.0", "version": "3.7.0",
"description": "monster", "description": "monster",
"repository": { "repository": {
"type": "git", "type": "git",
......
...@@ -7,7 +7,7 @@ describe('Monster', function () { ...@@ -7,7 +7,7 @@ describe('Monster', function () {
let monsterVersion let monsterVersion
/** don´t touch, replaced by make with package.json version */ /** don´t touch, replaced by make with package.json version */
monsterVersion = new Version("3.5.0") monsterVersion = new Version("3.7.0")
let m = getMonsterVersion(); let m = getMonsterVersion();
......
{"version":"3.7.0"} {"version":"3.8.0"}