content-entry-transform 1.5.17 → 1.6.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.
package/README.md CHANGED
@@ -57,7 +57,7 @@ Apply transformers.
57
57
 
58
58
  * `source` **AsyncIterable\<ContentEntry>**&#x20;
59
59
  * `transformers` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\<Transformer>** (optional, default `[]`)
60
- * `onlyMatching` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** filter out all none matching entries
60
+ * `onlyMatching` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** filter out all none matching entries (optional, default `false`)
61
61
 
62
62
  # install
63
63
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "content-entry-transform",
3
- "version": "1.5.17",
3
+ "version": "1.6.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
@@ -1,7 +1,7 @@
1
1
  import { IteratorContentEntry } from "content-entry";
2
2
  import { iterableStringInterceptor } from "iterable-string-interceptor";
3
3
 
4
- export function createPropertiesInterceptor(properties) {
4
+ export function createPropertiesInterceptor(evaluate) {
5
5
  return async function* transformer(
6
6
  expression,
7
7
  remainder,
@@ -10,13 +10,13 @@ export function createPropertiesInterceptor(properties) {
10
10
  leadIn,
11
11
  leadOut
12
12
  ) {
13
- function ev(e, deepth) {
14
- if (deepth > 9) {
15
- throw new Error(
16
- `Probably circular reference evaluating: ${expression}`
17
- );
13
+ function ev(e, depth) {
14
+ if (depth > 9) {
15
+ throw new Error(`Circular reference evaluating: ${expression}`, {
16
+ cause: expression
17
+ });
18
18
  }
19
- let value = properties[e];
19
+ let value = evaluate(e);
20
20
  if (value !== undefined) {
21
21
  if (typeof value === "string") {
22
22
  while (true) {
@@ -25,7 +25,7 @@ export function createPropertiesInterceptor(properties) {
25
25
  const lo = value.indexOf(leadOut, li + leadIn.length);
26
26
  value =
27
27
  value.substring(0, li) +
28
- ev(value.substring(li + leadIn.length, lo), deepth + 1) +
28
+ ev(value.substring(li + leadIn.length, lo), depth + 1) +
29
29
  value.substring(lo + leadOut.length);
30
30
  } else {
31
31
  break;
@@ -46,7 +46,7 @@ export function createPropertiesInterceptor(properties) {
46
46
  /**
47
47
  * Transformer expanding '{{}}' expressions
48
48
  * @param {string} match
49
- * @param {Object} properties
49
+ * @param {Object|Function} properties
50
50
  * @param {string} name
51
51
  * @returns
52
52
  */
@@ -63,19 +63,23 @@ export function createExpressionTransformer(
63
63
  }
64
64
  }
65
65
 
66
+ const interceptor = createPropertiesInterceptor(
67
+ typeof properties === "function" ? properties : name => properties[name]
68
+ );
69
+
66
70
  return {
67
71
  name,
68
72
  match,
69
73
  transform: async entry => {
74
+ if (entry.isCollection) {
75
+ return entry;
76
+ }
77
+
70
78
  const stream = await entry.stream;
71
79
  const ne = new IteratorContentEntry(
72
80
  entry.name,
73
81
  { destination: entry.destination },
74
- () =>
75
- iterableStringInterceptor(
76
- streamToText(stream),
77
- createPropertiesInterceptor(properties)
78
- )
82
+ () => iterableStringInterceptor(streamToText(stream), interceptor)
79
83
  );
80
84
  return ne;
81
85
  }
package/src/transform.mjs CHANGED
@@ -10,7 +10,7 @@ import { ContentEntry } from "content-entry";
10
10
  * @param {Transformer[]} transformers
11
11
  * @param {boolean} onlyMatching filter out all none matching entries
12
12
  */
13
- export async function* transform(source, transformers = [], onlyMatching) {
13
+ export async function* transform(source, transformers = [], onlyMatching=false) {
14
14
  const usedTransformers = new Set();
15
15
 
16
16
  for await (let entry of source) {