jtlt 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/CHANGES.md +27 -0
  2. package/README.md +61 -164
  3. package/demo/calltemplate-params-demo.js +138 -0
  4. package/demo/codemirror.esm.js +28242 -0
  5. package/demo/codemirror.js +94 -0
  6. package/demo/index.css +7 -0
  7. package/demo/index.html +28 -0
  8. package/demo/index.js +210 -0
  9. package/demo/vendor/jamilih/dist/jml.mjs +2341 -0
  10. package/demo/vendor/jhtml/src/SAJJ/SAJJ.ObjectArrayDelegator.js +356 -0
  11. package/demo/vendor/jhtml/src/SAJJ/SAJJ.Stringifier.js +186 -0
  12. package/demo/vendor/jhtml/src/SAJJ/SAJJ.js +746 -0
  13. package/demo/vendor/jhtml/src/SAJJ/testing/SAJJ.html +33 -0
  14. package/demo/vendor/jhtml/src/SAJJ/testing/SAJJ.testing.js +25 -0
  15. package/demo/vendor/jhtml/src/jhtml-browser.js +5 -0
  16. package/demo/vendor/jhtml/src/jhtml-node.cts +3 -0
  17. package/demo/vendor/jhtml/src/jhtml-node.js +8 -0
  18. package/demo/vendor/jhtml/src/jhtml-node.mts +1 -0
  19. package/demo/vendor/jhtml/src/jhtml.cts +3 -0
  20. package/demo/vendor/jhtml/src/jhtml.js +602 -0
  21. package/demo/vendor/jhtml/src/jhtml.mts +1 -0
  22. package/demo/vendor/jsonpath-plus/dist/index-browser-esm.js +2158 -0
  23. package/demo/vendor/simple-get-json/dist/index-es.js +151 -0
  24. package/demo/xpath2-placeholder.js +1 -0
  25. package/dist/AbstractJoiningTransformer.d.ts +83 -9
  26. package/dist/AbstractJoiningTransformer.d.ts.map +1 -1
  27. package/dist/DOMJoiningTransformer.d.ts +85 -25
  28. package/dist/DOMJoiningTransformer.d.ts.map +1 -1
  29. package/dist/JSONJoiningTransformer.d.ts +159 -51
  30. package/dist/JSONJoiningTransformer.d.ts.map +1 -1
  31. package/dist/JSONPathTransformer.d.ts +37 -38
  32. package/dist/JSONPathTransformer.d.ts.map +1 -1
  33. package/dist/JSONPathTransformerContext.d.ts +334 -124
  34. package/dist/JSONPathTransformerContext.d.ts.map +1 -1
  35. package/dist/StringJoiningTransformer.d.ts +132 -41
  36. package/dist/StringJoiningTransformer.d.ts.map +1 -1
  37. package/dist/XPathTransformer.d.ts +35 -20
  38. package/dist/XPathTransformer.d.ts.map +1 -1
  39. package/dist/XPathTransformerContext.d.ts +281 -105
  40. package/dist/XPathTransformerContext.d.ts.map +1 -1
  41. package/dist/index-browser.d.ts +4 -0
  42. package/dist/index-browser.d.ts.map +1 -0
  43. package/dist/index-node.d.ts +4 -0
  44. package/dist/index-node.d.ts.map +1 -0
  45. package/dist/index.d.ts +330 -57
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/types.d.ts +204 -0
  48. package/dist/types.d.ts.map +1 -0
  49. package/docs/API.expanded.md +172 -5
  50. package/docs/API.md +92 -2
  51. package/docs/TO-DO.md +168 -0
  52. package/docs/calltemplate-params.md +251 -0
  53. package/eslint.config.js +11 -5
  54. package/package.json +35 -9
  55. package/pnpm-workspace.yaml +1 -0
  56. package/rollup.config.js +13 -0
  57. package/src/AbstractJoiningTransformer.js +54 -15
  58. package/src/DOMJoiningTransformer.js +275 -28
  59. package/src/JSONJoiningTransformer.js +351 -70
  60. package/src/JSONPathTransformer.js +48 -30
  61. package/src/JSONPathTransformerContext.js +729 -107
  62. package/src/StringJoiningTransformer.js +311 -57
  63. package/src/XPathTransformer.js +27 -12
  64. package/src/XPathTransformerContext.js +928 -99
  65. package/src/index-browser.js +5 -0
  66. package/src/index-node.js +7 -0
  67. package/src/index.js +502 -98
  68. package/tsconfig.json +5 -2
  69. package/typings/xpath2-js.d.ts +40 -1
  70. package/src/types/xpath2-js.d.ts +0 -2
@@ -1,33 +1,43 @@
1
1
  import XPathTransformerContext from './XPathTransformerContext.js';
2
2
 
3
+ /**
4
+ * @template T
5
+ * @typedef {object} XPathTransformerConfig
6
+ * @property {boolean} [errorOnEqualPriority] Throw on equal priority
7
+ * @property {import('./index.js').
8
+ * XPathTemplateArray<T>} templates Template objects
9
+ * @property {number} [xpathVersion] XPath version (1|2|3.1)
10
+ */
11
+
3
12
  /**
4
13
  * Applies named XPath-driven templates to XML/HTML DOM data.
5
14
  *
6
15
  * Finds templates whose `path` XPath matches the current node (plus optional
7
16
  * `mode`), sorts by priority, and invokes the winning template.
8
17
  * Falls back to default rules when no template matches.
18
+ * @template T
9
19
  */
10
20
  class XPathTransformer {
11
21
  /**
12
- * @param {object} config Configuration
13
- * @param {boolean} [config.errorOnEqualPriority] Throw on equal priority
14
- * @param {any[]} config.templates Template objects
15
- * @param {number} [config.xpathVersion] XPath version (1|2)
22
+ * @param {XPathTransformerConfig<T> &
23
+ * import('./XPathTransformerContext.js').
24
+ * XPathTransformerContextConfig} config Configuration
16
25
  */
17
26
  constructor (config) {
18
27
  let map = /** @type {Record<string, boolean>} */ ({});
19
28
  this._config = config;
20
29
  /** @type {any[]} */
21
30
  this.rootTemplates = [];
22
- this.templates = config.templates;
23
- this.templates = this.templates.map(function (template) {
31
+
32
+ /** @type {import('./index.js').XPathTemplateObject<T>[]} */
33
+ this.templates = config.templates.map(function (template) {
24
34
  if (Array.isArray(template)) {
25
35
  return {path: template[0], template: template[1]};
26
36
  }
27
37
  return template;
28
38
  });
29
39
  this.templates.forEach((template) => {
30
- if (template.name && map[template.name]) {
40
+ if ('name' in template && template.name && map[template.name]) {
31
41
  /* c8 ignore next 6 -- c8/Istanbul known limitation: arrow function
32
42
  * predicates within filter assignments to instance properties are not
33
43
  * instrumented. Functionality fully tested via direct assertions on
@@ -35,9 +45,12 @@ class XPathTransformer {
35
45
  * test suite. */
36
46
  throw new Error('Templates must all have different names.');
37
47
  }
38
- map[template.name] = true;
48
+ if ('name' in template && template.name) {
49
+ map[template.name] = true;
50
+ }
39
51
  });
40
52
  // Collect root templates without mutating during iteration
53
+ // Only filter by path if path is defined
41
54
  this.rootTemplates = this.templates.filter((t) => t.path === '/');
42
55
  this.templates = this.templates.filter((t) => t.path !== '/');
43
56
  map = /** @type {any} */ (null);
@@ -56,8 +69,8 @@ class XPathTransformer {
56
69
  }
57
70
 
58
71
  /**
59
- * @param {string} mode Transformation mode
60
- * @returns {*} Result of transformation
72
+ * @param {string} [mode] Transformation mode
73
+ * @returns {import('./index.js').ResultType<T>} Result of transformation
61
74
  */
62
75
  transform (mode) {
63
76
  const xte = new XPathTransformerContext(
@@ -74,13 +87,15 @@ class XPathTransformer {
74
87
  if (typeof ret !== 'undefined') {
75
88
  /** @type {any} */ (xte)._getJoiningTransformer().append(ret);
76
89
  }
77
- return xte.getOutput();
90
+ return /** @type {import('./index.js').ResultType<T>} */ (
91
+ xte.getOutput()
92
+ );
78
93
  }
79
94
 
80
95
  static DefaultTemplateRules = {
81
96
  transformRoot: {
82
97
  /**
83
- * @param {*} node Node
98
+ * @param {any} node Node
84
99
  * @param {{mode:string}} cfg Config
85
100
  * @returns {void}
86
101
  */