@schukai/monster 1.15.5 → 1.17.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. package/CHANGELOG +25 -0
  2. package/README.md +4 -4
  3. package/dist/modules/constants.js +1 -1
  4. package/dist/modules/constraints/abstract.js +1 -1
  5. package/dist/modules/constraints/abstractoperator.js +1 -1
  6. package/dist/modules/constraints/andoperator.js +1 -1
  7. package/dist/modules/constraints/invalid.js +1 -1
  8. package/dist/modules/constraints/isarray.js +1 -1
  9. package/dist/modules/constraints/isobject.js +1 -1
  10. package/dist/modules/constraints/namespace.js +2 -2
  11. package/dist/modules/constraints/oroperator.js +1 -1
  12. package/dist/modules/constraints/valid.js +1 -1
  13. package/dist/modules/data/buildmap.js +2 -2
  14. package/dist/modules/data/diff.js +2 -2
  15. package/dist/modules/data/extend.js +1 -1
  16. package/dist/modules/data/namespace.js +2 -2
  17. package/dist/modules/data/pathfinder.js +2 -2
  18. package/dist/modules/data/pipe.js +1 -1
  19. package/dist/modules/data/transformer.js +1 -1
  20. package/dist/modules/dom/assembler.js +1 -1
  21. package/dist/modules/dom/attributes.js +1 -1
  22. package/dist/modules/dom/constants.js +1 -1
  23. package/dist/modules/dom/customcontrol.js +1 -1
  24. package/dist/modules/dom/customelement.js +1 -1
  25. package/dist/modules/dom/events.js +1 -1
  26. package/dist/modules/dom/locale.js +1 -1
  27. package/dist/modules/dom/namespace.js +2 -2
  28. package/dist/modules/dom/template.js +1 -1
  29. package/dist/modules/dom/theme.js +1 -1
  30. package/dist/modules/dom/updater.js +1 -1
  31. package/dist/modules/dom/util.js +1 -1
  32. package/dist/modules/i18n/locale.js +1 -1
  33. package/dist/modules/i18n/namespace.js +2 -2
  34. package/dist/modules/i18n/provider.js +1 -1
  35. package/dist/modules/i18n/providers/fetch.js +1 -1
  36. package/dist/modules/i18n/providers/namespace.js +2 -2
  37. package/dist/modules/i18n/translations.js +1 -1
  38. package/dist/modules/logging/handler/console.js +2 -2
  39. package/dist/modules/logging/handler/namespace.js +2 -2
  40. package/dist/modules/logging/handler.js +1 -1
  41. package/dist/modules/logging/logentry.js +1 -1
  42. package/dist/modules/logging/logger.js +1 -1
  43. package/dist/modules/logging/namespace.js +2 -2
  44. package/dist/modules/math/namespace.js +2 -2
  45. package/dist/modules/math/random.js +1 -1
  46. package/dist/modules/monster.js +1 -1
  47. package/dist/modules/namespace.js +1 -1
  48. package/dist/modules/text/formatter.js +1 -1
  49. package/dist/modules/text/namespace.js +2 -2
  50. package/dist/modules/types/base.js +1 -1
  51. package/dist/modules/types/basewithoptions.js +1 -1
  52. package/dist/modules/types/global.js +1 -1
  53. package/dist/modules/types/id.js +1 -1
  54. package/dist/modules/types/is.js +1 -1
  55. package/dist/modules/types/namespace.js +2 -2
  56. package/dist/modules/types/observer.js +1 -1
  57. package/dist/modules/types/observerlist.js +1 -1
  58. package/dist/modules/types/proxyobserver.js +1 -1
  59. package/dist/modules/types/queue.js +1 -1
  60. package/dist/modules/types/randomid.js +1 -1
  61. package/dist/modules/types/stack.js +1 -1
  62. package/dist/modules/types/tokenlist.js +1 -1
  63. package/dist/modules/types/typeof.js +1 -1
  64. package/dist/modules/types/uniquequeue.js +1 -1
  65. package/dist/modules/types/validate.js +1 -1
  66. package/dist/modules/types/version.js +2 -2
  67. package/dist/modules/util/clone.js +1 -1
  68. package/dist/modules/util/comparator.js +1 -1
  69. package/dist/modules/util/freeze.js +1 -1
  70. package/dist/modules/util/namespace.js +2 -2
  71. package/dist/monster.dev.js +1293 -943
  72. package/dist/monster.dev.js.map +1 -1
  73. package/dist/monster.js +2 -2
  74. package/package.json +1 -1
  75. package/source/constraints/abstract.js +1 -1
  76. package/source/constraints/abstractoperator.js +1 -1
  77. package/source/constraints/andoperator.js +6 -6
  78. package/source/constraints/invalid.js +4 -4
  79. package/source/constraints/isarray.js +4 -4
  80. package/source/constraints/isobject.js +4 -4
  81. package/source/constraints/namespace.js +3 -2
  82. package/source/constraints/oroperator.js +6 -6
  83. package/source/constraints/valid.js +4 -4
  84. package/source/data/buildmap.js +245 -12
  85. package/source/data/diff.js +7 -6
  86. package/source/data/extend.js +3 -3
  87. package/source/data/namespace.js +3 -2
  88. package/source/data/pathfinder.js +15 -11
  89. package/source/data/pipe.js +4 -4
  90. package/source/data/transformer.js +4 -4
  91. package/source/dom/assembler.js +4 -4
  92. package/source/dom/attributes.js +36 -46
  93. package/source/dom/constants.js +16 -14
  94. package/source/dom/customcontrol.js +12 -8
  95. package/source/dom/customelement.js +24 -11
  96. package/source/dom/events.js +6 -6
  97. package/source/dom/locale.js +5 -4
  98. package/source/dom/namespace.js +3 -2
  99. package/source/dom/template.js +6 -6
  100. package/source/dom/theme.js +5 -4
  101. package/source/dom/updater.js +11 -5
  102. package/source/dom/util.js +9 -9
  103. package/source/i18n/locale.js +27 -15
  104. package/source/i18n/namespace.js +3 -2
  105. package/source/i18n/provider.js +3 -3
  106. package/source/i18n/providers/fetch.js +22 -6
  107. package/source/i18n/providers/namespace.js +3 -2
  108. package/source/i18n/translations.js +3 -3
  109. package/source/logging/handler/console.js +34 -10
  110. package/source/logging/handler/namespace.js +3 -2
  111. package/source/logging/handler.js +4 -4
  112. package/source/logging/logentry.js +5 -5
  113. package/source/logging/logger.js +13 -13
  114. package/source/logging/namespace.js +3 -2
  115. package/source/math/namespace.js +3 -2
  116. package/source/math/random.js +3 -3
  117. package/source/namespace.js +1 -1
  118. package/source/text/formatter.js +3 -3
  119. package/source/text/namespace.js +3 -2
  120. package/source/types/base.js +3 -3
  121. package/source/types/basewithoptions.js +3 -3
  122. package/source/types/global.js +7 -7
  123. package/source/types/id.js +3 -3
  124. package/source/types/is.js +30 -30
  125. package/source/types/namespace.js +3 -2
  126. package/source/types/observer.js +4 -4
  127. package/source/types/observerlist.js +3 -3
  128. package/source/types/proxyobserver.js +6 -6
  129. package/source/types/queue.js +4 -4
  130. package/source/types/randomid.js +3 -3
  131. package/source/types/stack.js +3 -3
  132. package/source/types/tokenlist.js +3 -3
  133. package/source/types/typeof.js +4 -4
  134. package/source/types/uniquequeue.js +3 -3
  135. package/source/types/validate.js +34 -34
  136. package/source/types/version.js +7 -7
  137. package/source/util/clone.js +3 -3
  138. package/source/util/comparator.js +37 -7
  139. package/source/util/freeze.js +4 -4
  140. package/source/util/namespace.js +3 -2
  141. package/test/cases/data/buildmap.js +242 -16
  142. package/test/cases/data/diff.js +36 -3
  143. package/test/cases/data/pathfinder.js +298 -196
  144. package/test/cases/logging/handler/console.js +20 -0
  145. package/test/cases/monster.js +1 -1
  146. package/test/web/import.js +1 -0
  147. package/test/web/monster-dev.html +3 -3
  148. package/test/web/monster.html +2 -2
  149. package/test/web/test.html +2 -2
  150. package/test/web/tests.js +3 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schukai/monster",
3
- "version": "1.15.5",
3
+ "version": "1.17.1",
4
4
  "description": "Monster is a simple library for creating fast, robust and lightweight websites.",
5
5
  "keywords": [
6
6
  "framework",
@@ -15,7 +15,7 @@ import {Base} from '../types/base.js';
15
15
  *
16
16
  * @since 1.3.0
17
17
  * @copyright schukai GmbH
18
- * @memberOf Monster/Constraints
18
+ * @memberOf Monster.Constraints
19
19
  */
20
20
  class AbstractConstraint extends Base {
21
21
 
@@ -11,7 +11,7 @@ import {AbstractConstraint} from "./abstract.js";
11
11
  *
12
12
  * @since 1.3.0
13
13
  * @copyright schukai GmbH
14
- * @memberOf Monster/Constraints
14
+ * @memberOf Monster.Constraints
15
15
  */
16
16
  class AbstractOperator extends AbstractConstraint {
17
17
 
@@ -12,7 +12,7 @@ import {AbstractOperator} from "./abstractoperator.js";
12
12
  *
13
13
  * ```
14
14
  * <script type="module">
15
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.5/dist/modules/constraints/andoperator.js';
15
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/constraints/andoperator.js';
16
16
  * new Monster.Constraint.AndOperator();
17
17
  * </script>
18
18
  * ```
@@ -21,16 +21,16 @@ import {AbstractOperator} from "./abstractoperator.js";
21
21
  *
22
22
  * ```
23
23
  * <script type="module">
24
- * import {AndOperator} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.5/dist/modules/constraints/andoperator.js';
24
+ * import {AndOperator} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/constraints/andoperator.js';
25
25
  * new AndOperator();
26
26
  * </script>
27
27
  * ```
28
28
  *
29
29
  * @example
30
30
  *
31
- * import {Valid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.5/dist/modules/constraints/valid.js';
32
- * import {Invalid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.5/dist/modules/constraints/invalid.js';
33
- * import {AndOperator} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.5/dist/modules/constraints/andoperator.js';
31
+ * import {Valid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/constraints/valid.js';
32
+ * import {Invalid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/constraints/invalid.js';
33
+ * import {AndOperator} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/constraints/andoperator.js';
34
34
  *
35
35
  * new AndOperator(
36
36
  * new Valid(), new Valid()).isValid()
@@ -46,7 +46,7 @@ import {AbstractOperator} from "./abstractoperator.js";
46
46
  *
47
47
  * @since 1.3.0
48
48
  * @copyright schukai GmbH
49
- * @memberOf Monster/Constraints
49
+ * @memberOf Monster.Constraints
50
50
  */
51
51
  class AndOperator extends AbstractOperator {
52
52
 
@@ -13,7 +13,7 @@ import {AbstractConstraint} from "./abstract.js";
13
13
  *
14
14
  * ```
15
15
  * <script type="module">
16
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.5/dist/modules/constraints/invalid.js';
16
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/constraints/invalid.js';
17
17
  * new Monster.Constraint.Invalid();
18
18
  * </script>
19
19
  * ```
@@ -22,14 +22,14 @@ import {AbstractConstraint} from "./abstract.js";
22
22
  *
23
23
  * ```
24
24
  * <script type="module">
25
- * import {Invalid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.5/dist/modules/constraints/invalid.js';
25
+ * import {Invalid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/constraints/invalid.js';
26
26
  * new Invalid();
27
27
  * </script>
28
28
  * ```
29
29
  *
30
30
  * @example
31
31
  *
32
- * import {Invalid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.5/dist/modules/constraints/invalid.js';
32
+ * import {Invalid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/constraints/invalid.js';
33
33
  *
34
34
  * new Invalid().isValid()
35
35
  * .then(()=>console.log(true))
@@ -38,7 +38,7 @@ import {AbstractConstraint} from "./abstract.js";
38
38
  *
39
39
  * @since 1.3.0
40
40
  * @copyright schukai GmbH
41
- * @memberOf Monster/Constraints
41
+ * @memberOf Monster.Constraints
42
42
  */
43
43
  class Invalid extends AbstractConstraint {
44
44
 
@@ -12,7 +12,7 @@ import {AbstractConstraint} from "./abstract.js";
12
12
  *
13
13
  * ```
14
14
  * <script type="module">
15
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.5/dist/modules/constraints/isarray.js';
15
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/constraints/isarray.js';
16
16
  * console.log(new Monster.Constraint.IsArray())
17
17
  * </script>
18
18
  * ```
@@ -21,14 +21,14 @@ import {AbstractConstraint} from "./abstract.js";
21
21
  *
22
22
  * ```
23
23
  * <script type="module">
24
- * import {IsArray} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.5/dist/modules/constraints/isarray.js';
24
+ * import {IsArray} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/constraints/isarray.js';
25
25
  * console.log(new IsArray())
26
26
  * </script>
27
27
  * ```
28
28
  *
29
29
  * @example
30
30
  *
31
- * import {IsArray} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.5/dist/modules/constraints/isarray.js';
31
+ * import {IsArray} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/constraints/isarray.js';
32
32
  *
33
33
  * new IsArray()
34
34
  * .isValid([])
@@ -42,7 +42,7 @@ import {AbstractConstraint} from "./abstract.js";
42
42
  *
43
43
  * @since 1.3.0
44
44
  * @copyright schukai GmbH
45
- * @memberOf Monster/Constraints
45
+ * @memberOf Monster.Constraints
46
46
  */
47
47
  class IsArray extends AbstractConstraint {
48
48
 
@@ -12,7 +12,7 @@ import {AbstractConstraint} from "./abstract.js";
12
12
  *
13
13
  * ```
14
14
  * <script type="module">
15
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.5/dist/modules/constraints/isobject.js';
15
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/constraints/isobject.js';
16
16
  * console.log(new Monster.Constraint.IsObject())
17
17
  * </script>
18
18
  * ```
@@ -21,14 +21,14 @@ import {AbstractConstraint} from "./abstract.js";
21
21
  *
22
22
  * ```
23
23
  * <script type="module">
24
- * import {IsObject} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.5/dist/modules/constraints/isobject.js';
24
+ * import {IsObject} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/constraints/isobject.js';
25
25
  * console.log(new IsObject())
26
26
  * </script>
27
27
  * ```
28
28
  *
29
29
  * @example
30
30
  *
31
- * import {IsObject} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.5/dist/modules/constraints/isobject.js';
31
+ * import {IsObject} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/constraints/isobject.js';
32
32
  *
33
33
  * new IsObject()
34
34
  * .isValid({})
@@ -43,7 +43,7 @@ import {AbstractConstraint} from "./abstract.js";
43
43
  *
44
44
  * @since 1.3.0
45
45
  * @copyright schukai GmbH
46
- * @memberOf Monster/Constraints
46
+ * @memberOf Monster.Constraints
47
47
  */
48
48
  class IsObject extends AbstractConstraint {
49
49
 
@@ -3,7 +3,8 @@
3
3
  /**
4
4
  * Constraints are used to define conditions that must be met by the value of a variable so that the value can be transferred to the system.
5
5
  *
6
- * @namespace Monster/Constraints
6
+ * @namespace Constraints
7
+ * @memberOf Monster
7
8
  * @author schukai GmbH
8
9
  */
9
10
 
@@ -11,4 +12,4 @@
11
12
  * @private
12
13
  * @type {string}
13
14
  */
14
- const namespace = "Monster.Constraints";
15
+ export const namespace = "Monster.Constraints";
@@ -11,7 +11,7 @@ import {AbstractOperator} from "./abstractoperator.js";
11
11
  *
12
12
  * ```
13
13
  * <script type="module">
14
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.5/dist/modules/constraint/oroperator.js';
14
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/constraint/oroperator.js';
15
15
  * new Monster.Constraint.OrOperator();
16
16
  * </script>
17
17
  * ```
@@ -20,16 +20,16 @@ import {AbstractOperator} from "./abstractoperator.js";
20
20
  *
21
21
  * ```
22
22
  * <script type="module">
23
- * import {OrOperator} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.5/dist/modules/constraint/oroperator.js';
23
+ * import {OrOperator} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/constraint/oroperator.js';
24
24
  * new OrOperator();
25
25
  * </script>
26
26
  * ```
27
27
  *
28
28
  * @example
29
29
  *
30
- * import {Valid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.5/dist/modules/constraints/valid.js';
31
- * import {Invalid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.5/dist/modules/constraints/invalid.js';
32
- * import {OrOperator} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.5/dist/modules/constraints/oroperator.js';
30
+ * import {Valid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/constraints/valid.js';
31
+ * import {Invalid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/constraints/invalid.js';
32
+ * import {OrOperator} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/constraints/oroperator.js';
33
33
  *
34
34
  * new OrOperator(
35
35
  * new Valid(), new Invalid()).isValid()
@@ -45,7 +45,7 @@ import {AbstractOperator} from "./abstractoperator.js";
45
45
  *
46
46
  * @since 1.3.0
47
47
  * @copyright schukai GmbH
48
- * @memberOf Monster/Constraints
48
+ * @memberOf Monster.Constraints
49
49
  */
50
50
  class OrOperator extends AbstractOperator {
51
51
 
@@ -13,7 +13,7 @@ import {AbstractConstraint} from "./abstract.js";
13
13
  *
14
14
  * ```
15
15
  * <script type="module">
16
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.5/dist/modules/constraints/valid.js';
16
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/constraints/valid.js';
17
17
  * new Monster.Constraint.Valid();
18
18
  * </script>
19
19
  * ```
@@ -22,14 +22,14 @@ import {AbstractConstraint} from "./abstract.js";
22
22
  *
23
23
  * ```
24
24
  * <script type="module">
25
- * import {Valid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.5/dist/modules/constraints/valid.js';
25
+ * import {Valid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/constraints/valid.js';
26
26
  * new Valid();
27
27
  * </script>
28
28
  * ```
29
29
  *
30
30
  * @example
31
31
  *
32
- * import {Valid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.5/dist/modules/constraints/valid.js';
32
+ * import {Valid} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/constraints/valid.js';
33
33
  *
34
34
  * new Valid().isValid()
35
35
  * .then(()=>console.log(true))
@@ -38,7 +38,7 @@ import {AbstractConstraint} from "./abstract.js";
38
38
  *
39
39
  * @since 1.3.0
40
40
  * @copyright schukai GmbH
41
- * @memberOf Monster/Constraints
41
+ * @memberOf Monster.Constraints
42
42
  */
43
43
  class Valid extends AbstractConstraint {
44
44
 
@@ -5,9 +5,10 @@
5
5
  */
6
6
 
7
7
  import {assignToNamespace, Monster} from '../namespace.js';
8
- import {isFunction} from "../types/is.js";
8
+ import {isFunction, isObject, isString} from "../types/is.js";
9
9
  import {validateString} from "../types/validate.js";
10
- import {Pathfinder} from "./pathfinder.js";
10
+ import {clone} from "../util/clone.js";
11
+ import {DELIMITER, Pathfinder, WILDCARD} from "./pathfinder.js";
11
12
 
12
13
  /**
13
14
  * With the help of the function `buildMap()`, maps can be easily created from data objects.
@@ -19,7 +20,7 @@ import {Pathfinder} from "./pathfinder.js";
19
20
  *
20
21
  * ```
21
22
  * <script type="module">
22
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.5/dist/modules/data/buildmap.js';
23
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/data/buildmap.js';
23
24
  * console.log(Monster.Data.buildMap())
24
25
  * </script>
25
26
  * ```
@@ -28,13 +29,18 @@ import {Pathfinder} from "./pathfinder.js";
28
29
  *
29
30
  * ```
30
31
  * <script type="module">
31
- * import {buildMap} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.5/dist/modules/types/buildmap.js';
32
+ * import {buildMap} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/data/buildmap.js';
32
33
  * console.log(buildMap())
33
34
  * </script>
34
35
  * ```
36
+ *
37
+ * 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.
38
+ *
39
+ * If you want to access values of the parent data set, you have to use the `^` character `${id} ${^.name}`.
35
40
  *
36
41
  * @example
37
42
  *
43
+ * import {buildMap} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/data/buildmap.js';
38
44
  * // a typical data structure as reported by an api
39
45
  *
40
46
  * let map;
@@ -103,24 +109,37 @@ import {Pathfinder} from "./pathfinder.js";
103
109
  * // }
104
110
  *
105
111
  * @param {*} subject
106
- * @param {string} selector
107
- * @param {string|undefined} valueTemplate
108
- * @param {string|undefined} keyTemplate
109
- * @param {function|undefined} filter
112
+ * @param {string|Monster.Data~exampleSelectorCallback} selector
113
+ * @param {string} [valueTemplate]
114
+ * @param {string} [keyTemplate]
115
+ * @param {Monster.Data~exampleFilterCallback} [filter]
110
116
  * @return {*}
117
+ * @memberOf Monster.Data
118
+ * @throws {TypeError} value is neither a string nor a function
119
+ * @throws {TypeError} the selector callback must return a map
111
120
  */
112
121
  function buildMap(subject, selector, valueTemplate, keyTemplate, filter) {
113
122
 
114
- validateString(selector);
115
123
  const result = new Map
116
124
 
117
- let finder = new Pathfinder(subject);
125
+ let map;
126
+ if (isFunction(selector)) {
127
+ map = selector(subject)
128
+ if (!(map instanceof Map)) {
129
+ throw new TypeError('the selector callback must return a map');
130
+ }
131
+ } else if (isString(selector)) {
132
+ map = new Map;
133
+ buildFlatMap.call(map, subject, selector);
134
+ } else {
135
+ throw new TypeError('value is neither a string nor a function')
136
+ }
118
137
 
119
- let map = finder.getVia(selector);
120
138
  if (!(map instanceof Map)) {
121
139
  return result;
122
140
  }
123
141
 
142
+
124
143
  map.forEach((v, k, m) => {
125
144
  if (isFunction(filter)) {
126
145
  if (filter.call(m, v, k) !== true) return;
@@ -135,6 +154,219 @@ function buildMap(subject, selector, valueTemplate, keyTemplate, filter) {
135
154
  return result;
136
155
  }
137
156
 
157
+ /**
158
+ * @private
159
+ * @param subject
160
+ * @param selector
161
+ * @param key
162
+ * @param parentMap
163
+ * @return {*}
164
+ */
165
+ function buildFlatMap(subject, selector, key, parentMap) {
166
+
167
+ const result = this;
168
+ const currentMap = new Map;
169
+
170
+ const resultLength = result.size;
171
+
172
+ if (key === undefined) key = [];
173
+
174
+ let parts = selector.split(DELIMITER);
175
+ let current = "", currentPath = [];
176
+ do {
177
+
178
+ current = parts.shift();
179
+ currentPath.push(current);
180
+
181
+ if (current === WILDCARD) {
182
+
183
+ let finder = new Pathfinder(subject);
184
+ let map
185
+ try {
186
+ map = finder.getVia(currentPath.join(DELIMITER));
187
+ } catch (e) {
188
+ let a = e;
189
+ map = new Map();
190
+ }
191
+
192
+
193
+ for (const [k, o] of map) {
194
+
195
+ let copyKey = clone(key);
196
+
197
+ currentPath.map((a) => {
198
+ copyKey.push((a === WILDCARD) ? k : a)
199
+ })
200
+
201
+ let kk = copyKey.join(DELIMITER);
202
+ let sub = buildFlatMap.call(result, o, parts.join(DELIMITER), copyKey, o);
203
+
204
+ if (isObject(sub)) {
205
+ sub['^'] = parentMap;
206
+ }
207
+
208
+ currentMap.set(kk, sub);
209
+ }
210
+
211
+ }
212
+
213
+
214
+ } while (parts.length > 0);
215
+
216
+ // no set in child run
217
+ if (resultLength === result.size) {
218
+ for (const [k, o] of currentMap) {
219
+ result.set(k, o);
220
+ }
221
+ }
222
+
223
+ return subject;
224
+
225
+ }
226
+
227
+
228
+ /**
229
+ * With the help of this filter callback, values can be filtered out. Only if the filter function returns true, the value is taken for the map.
230
+ *
231
+ * @callback Monster.Data~exampleFilterCallback
232
+ * @param {*} value Value
233
+ * @param {string} key Key
234
+ * @memberOf Monster.Data
235
+ * @see Monster.Data.buildMap
236
+ */
237
+
238
+ /**
239
+ * Alternatively to a string selector a callback can be specified. this must return a map.
240
+ *
241
+ * @example
242
+ * import {buildMap} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/data/buildmap.js';
243
+ *
244
+ * let obj = {
245
+ * "data": [
246
+ * {
247
+ * "id": 10,
248
+ * "name": "Cassandra",
249
+ * "enrichment": {
250
+ * variants: [
251
+ * {
252
+ * sku: 1, label: "XXS", price: [
253
+ * {vk: '12.12 €'},
254
+ * {vk: '12.12 €'}
255
+ * ]
256
+ * },
257
+ * {
258
+ * sku: 2, label: "XS", price: [
259
+ * {vk: '22.12 €'},
260
+ * {vk: '22.12 €'}
261
+ * ]
262
+ * },
263
+ * {
264
+ * sku: 3, label: "S", price: [
265
+ * {vk: '32.12 €'},
266
+ * {vk: '32.12 €'}
267
+ * ]
268
+ * },
269
+ * {
270
+ * sku: 4, label: "L", price: [
271
+ * {vk: '42.12 €'},
272
+ * {vk: '42.12 €'}
273
+ * ]
274
+ * }
275
+ * ]
276
+ *
277
+ * }
278
+ * },
279
+ * {
280
+ * "id": 20,
281
+ * "name": "Yessey!",
282
+ * "enrichment": {
283
+ * variants: [
284
+ * {
285
+ * sku: 1, label: "XXS", price: [
286
+ * {vk: '12.12 €'},
287
+ * {vk: '12.12 €'}
288
+ * ]
289
+ * },
290
+ * {
291
+ * sku: 2, label: "XS", price: [
292
+ * {vk: '22.12 €'},
293
+ * {vk: '22.12 €'}
294
+ * ]
295
+ * },
296
+ * {
297
+ * sku: 3, label: "S", price: [
298
+ * {vk: '32.12 €'},
299
+ * {vk: '32.12 €'}
300
+ * ]
301
+ * },
302
+ * {
303
+ * sku: 4, label: "L", price: [
304
+ * {vk: '42.12 €'},
305
+ * {vk: '42.12 €'}
306
+ * ]
307
+ * }
308
+ * ]
309
+ *
310
+ * }
311
+ * }
312
+ * ]
313
+ * };
314
+ *
315
+ * let callback = function (subject) {
316
+ * let m = new Map;
317
+ *
318
+ * for (const [i, b] of Object.entries(subject.data)) {
319
+ *
320
+ * let key1 = i;
321
+ *
322
+ * for (const [j, c] of Object.entries(b.enrichment.variants)) {
323
+ * let key2 = j;
324
+ *
325
+ * for (const [k, d] of Object.entries(c.price)) {
326
+ *
327
+ * let key3 = k;
328
+ *
329
+ * d.name = b.name;
330
+ * d.label = c.label;
331
+ * d.id = [key1, key2, key3].join('.');
332
+ *
333
+ * m.set(d.id, d);
334
+ * }
335
+ *
336
+ * }
337
+ * }
338
+ * return m;
339
+ * }
340
+ *
341
+ * let map = buildMap(obj, callback, '${name} ${vk}', '${id}')
342
+ *
343
+ * // ↦ Map(3) {
344
+ * // "0.0.0":"Cassandra 12.12 €",
345
+ * // "0.0.1":"Cassandra 12.12 €",
346
+ * // "0.1.0":"Cassandra 22.12 €",
347
+ * // "0.1.1":"Cassandra 22.12 €",
348
+ * // "0.2.0":"Cassandra 32.12 €",
349
+ * // "0.2.1":"Cassandra 32.12 €",
350
+ * // "0.3.0":"Cassandra 42.12 €",
351
+ * // "0.3.1":"Cassandra 42.12 €",
352
+ * // "1.0.0":"Yessey! 12.12 €",
353
+ * // "1.0.1":"Yessey! 12.12 €",
354
+ * // "1.1.0":"Yessey! 22.12 €",
355
+ * // "1.1.1":"Yessey! 22.12 €",
356
+ * // "1.2.0":"Yessey! 32.12 €",
357
+ * // "1.2.1":"Yessey! 32.12 €",
358
+ * // "1.3.0":"Yessey! 42.12 €",
359
+ * // "1.3.1":"Yessey! 42.12 €"
360
+ * // }
361
+ *
362
+ * @callback Monster.Data~exampleSelectorCallback
363
+ * @param {*} subject subject
364
+ * @return Map
365
+ * @since 1.17.0
366
+ * @memberOf Monster.Data
367
+ * @see Monster.Data.buildMap
368
+ */
369
+
138
370
  /**
139
371
  * @private
140
372
  * @param {*} subject
@@ -146,7 +378,7 @@ function build(subject, definition, defaultValue) {
146
378
  if (definition === undefined) return defaultValue ? defaultValue : subject;
147
379
  validateString(definition);
148
380
 
149
- const regexp = /(?<placeholder>\${(?<path>[a-z.\-_0-9]*)})/gm
381
+ const regexp = /(?<placeholder>\${(?<path>[a-z\^A-Z.\-_0-9]*)})/gm
150
382
  const array = [...definition.matchAll(regexp)];
151
383
 
152
384
  let finder = new Pathfinder(subject);
@@ -163,6 +395,7 @@ function build(subject, definition, defaultValue) {
163
395
  let path = groups?.['path']
164
396
 
165
397
  let v = finder.getVia(path);
398
+ if (v === undefined) v = defaultValue;
166
399
 
167
400
  definition = definition.replaceAll(placeholder, v);
168
401
 
@@ -6,6 +6,7 @@
6
6
 
7
7
  import {assignToNamespace, Monster} from '../namespace.js';
8
8
  import {isArray, isObject} from "../types/is.js";
9
+ import {typeOf} from "../types/typeof.js";
9
10
 
10
11
  /**
11
12
  * With the diff function you can perform the change of one object to another. The result shows the changes of the second object to the first object.
@@ -16,7 +17,7 @@ import {isArray, isObject} from "../types/is.js";
16
17
  *
17
18
  * ```
18
19
  * <script type="module">
19
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.5/dist/modules/data/diff.js';
20
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/data/diff.js';
20
21
  * console.log(Monster.Data.Diff(a, b))
21
22
  * </script>
22
23
  * ```
@@ -25,14 +26,14 @@ import {isArray, isObject} from "../types/is.js";
25
26
  *
26
27
  * ```
27
28
  * <script type="module">
28
- * import {Diff} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.5/dist/modules/data/diff.js';
29
+ * import {Diff} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/data/diff.js';
29
30
  * console.log(Diff(a, b))
30
31
  * </script>
31
32
  * ```
32
33
  *
33
34
  * @example
34
35
  *
35
- * import {Diff} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.5/dist/modules/data/diff.js';
36
+ * import {Diff} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/data/diff.js';
36
37
  *
37
38
  * // given are two objects x and y.
38
39
  *
@@ -77,7 +78,7 @@ import {isArray, isObject} from "../types/is.js";
77
78
  * @return {array}
78
79
  * @since 1.6.0
79
80
  * @copyright schukai GmbH
80
- * @memberOf Monster/Data
81
+ * @memberOf Monster.Data
81
82
  */
82
83
  function Diff(first, second) {
83
84
  return doDiff(first, second)
@@ -110,8 +111,8 @@ function getKeys(a, b, type) {
110
111
  */
111
112
  function doDiff(a, b, path, diff) {
112
113
 
113
- let typeA = typeof a
114
- let typeB = typeof b
114
+ let typeA = typeOf(a)
115
+ let typeB = typeOf(b)
115
116
 
116
117
  const currPath = path || [];
117
118
  const currDiff = diff || [];
@@ -15,7 +15,7 @@ import {typeOf} from "../types/typeof.js";
15
15
  *
16
16
  * ```
17
17
  * <script type="module">
18
- * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.5/dist/modules/data/extend.js';
18
+ * import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/data/extend.js';
19
19
  * console.log(Monster.Data.extend(a, b))
20
20
  * </script>
21
21
  * ```
@@ -24,7 +24,7 @@ import {typeOf} from "../types/typeof.js";
24
24
  *
25
25
  * ```
26
26
  * <script type="module">
27
- * import {extend} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.15.5/dist/modules/data/extend.js';
27
+ * import {extend} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.17.1/dist/modules/data/extend.js';
28
28
  * console.log(extend(a, b))
29
29
  * </script>
30
30
  * ```
@@ -34,7 +34,7 @@ import {typeOf} from "../types/typeof.js";
34
34
  * @return {object}
35
35
  * @since 1.10.0
36
36
  * @copyright schukai GmbH
37
- * @memberOf Monster/Data
37
+ * @memberOf Monster.Data
38
38
  * @throws {Error} unsuported argument
39
39
  * @throws {Error} type mismatch
40
40
  */