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 (4)
<a name="v3.16.0"></a>
## [v3.16.0] - 2023-02-26
### Add Features
- new transformer commands (date, map, time, dayofweek, timestamp...)
<a name="v3.15.0"></a> <a name="v3.15.0"></a>
## [v3.15.0] - 2023-02-23 ## [v3.15.0] - 2023-02-23
### Add Features ### Add Features
...@@ -325,6 +331,7 @@ ...@@ -325,6 +331,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.16.0]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.15.0...v3.16.0
[v3.15.0]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.14.1...v3.15.0 [v3.15.0]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.14.1...v3.15.0
[v3.14.1]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.14.0...v3.14.1 [v3.14.1]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.14.0...v3.14.1
[v3.14.0]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.13.1...v3.14.0 [v3.14.0]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.13.1...v3.14.0
......
{ {
"name": "@schukai/monster", "name": "@schukai/monster",
"version": "3.14.1", "version": "3.15.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",
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html * 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 {Base} from "../types/base.mjs";
import {getGlobal, getGlobalObject} from "../types/global.mjs"; import {getGlobal, getGlobalObject} from "../types/global.mjs";
import {ID} from "../types/id.mjs"; import {ID} from "../types/id.mjs";
...@@ -169,6 +170,11 @@ function transform(value) { ...@@ -169,6 +170,11 @@ function transform(value) {
let element; let element;
let attribute; let attribute;
let translations; let translations;
let date;
let locale;
let timestamp;
let map;
let keyValue;
switch (this.command) { switch (this.command) {
case "static": case "static":
...@@ -491,6 +497,117 @@ function transform(value) { ...@@ -491,6 +497,117 @@ function transform(value) {
throw new Error("type not supported"); throw new Error("type not supported");
case "map":
map = new Map();
while (args.length > 0) {
keyValue = args.shift();
if (keyValue === undefined) {
throw new Error("missing key parameter");
}
keyValue = keyValue.split("=");
map.set(keyValue[0], keyValue[1]);
}
return map.get(value);
case "timestamp":
date = new Date(value);
timestamp = date.getTime();
if (isNaN(timestamp)) {
throw new Error("invalid date");
}
return timestamp;
case "time":
date = new Date(value);
if (isNaN(date.getTime())) {
throw new Error("invalid date");
}
try {
locale = getLocaleOfDocument();
return date.toLocaleTimeString(locale);
} catch (e) {
throw new Error("unsupported locale or missing format (" + e.message + ")");
}
case "year":
date = new Date(value);
if (isNaN(date.getTime())) {
throw new Error("invalid date");
}
return date.getFullYear();
case "month":
date = new Date(value);
if (isNaN(date.getTime())) {
throw new Error("invalid date");
}
return date.getMonth() + 1;
case "day":
date = new Date(value);
if (isNaN(date.getTime())) {
throw new Error("invalid date");
}
return date.getDate();
case "weekday":
date = new Date(value);
if (isNaN(date.getTime())) {
throw new Error("invalid date");
}
return date.getDay();
case "hour":
case "hours":
date = new Date(value);
if (isNaN(date.getTime())) {
throw new Error("invalid date");
}
return date.getHours();
case "minute":
case "minutes":
date = new Date(value);
if (isNaN(date.getTime())) {
throw new Error("invalid date");
}
return date.getMinutes();
case "second":
case "seconds":
date = new Date(value);
if (isNaN(date.getTime())) {
throw new Error("invalid date");
}
return date.getSeconds();
case "date":
date = new Date(value);
if (isNaN(date.getTime())) {
throw new Error("invalid date");
}
try {
locale = getLocaleOfDocument();
return date.toLocaleDateString(locale);
} catch (e) {
throw new Error("unsupported locale or missing format (" + e.message + ")");
}
case "i18n": case "i18n":
case "translation": case "translation":
translations = getDocumentTranslations(); translations = getDocumentTranslations();
......
...@@ -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.14.1"); monsterVersion = new Version("3.15.0");
return monsterVersion; return monsterVersion;
} }
{ {
"name": "monster", "name": "monster",
"version": "3.14.1", "version": "3.15.0",
"description": "monster", "description": "monster",
"repository": { "repository": {
"type": "git", "type": "git",
......
...@@ -27,6 +27,17 @@ describe('Transformer', function () { ...@@ -27,6 +27,17 @@ describe('Transformer', function () {
describe('Transformer.run()', function () { describe('Transformer.run()', function () {
[ [
['map:a=4:b=5:c=6', "a", "4"],
['date', "2023-02-14", "14.2.2023"],
['year', "2023-02-14", 2023],
['month', "2023-02-14", 2],
['day', "2023-02-14", 14],
['weekday', "2023-02-14", 2],
['minutes', "2023-02-14 06:12:21", 12],
['seconds', "2023-02-14 06:12:21", 21],
['hours', "2023-02-14 06:12:21", 6],
['time', "2023-02-14 06:12:21", "06:12:21"],
['timestamp', "2023-02-14", 1676332800000],
['concat:a.b.c:test:a.b.d', {a: {b: {c: 4, d: 6}}}, "4test6"], ['concat:a.b.c:test:a.b.d', {a: {b: {c: 4, d: 6}}}, "4test6"],
['concat:a.b.c:\\ \\ :a.b.d', {a: {b: {c: 4, d: 6}}}, "4 6"], ['concat:a.b.c:\\ \\ :a.b.d', {a: {b: {c: 4, d: 6}}}, "4 6"],
['concat:a.b.c:,:a.b.d', {a: {b: {c: 4, d: 6}}}, "4,6"], ['concat:a.b.c:,:a.b.d', {a: {b: {c: 4, d: 6}}}, "4,6"],
......
...@@ -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.14.1") monsterVersion = new Version("3.15.0")
let m = getMonsterVersion(); let m = getMonsterVersion();
......
{"version":"3.15.0"} {"version":"3.16.0"}