content-entry-transform 1.4.28 → 1.4.30
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/LICENSE +1 -1
- package/README.md +18 -6
- package/package.json +14 -13
- package/src/expression-transformer.mjs +22 -4
- package/src/properties-transformer.mjs +1 -0
- package/src/transform.mjs +5 -4
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[](https://www.npmjs.com/package/content-entry-transform)
|
|
2
2
|
[](https://opensource.org/licenses/BSD-3-Clause)
|
|
3
|
-
[](https://bundlejs.com/?q=content-entry-transform)
|
|
4
4
|
[](https://npmjs.org/package/content-entry-transform)
|
|
5
5
|
[](https://github.com/arlac77/content-entry-transform/issues)
|
|
6
6
|
[](https://actions-badge.atrox.dev/arlac77/content-entry-transform/goto)
|
|
@@ -19,10 +19,22 @@ transform content entries
|
|
|
19
19
|
|
|
20
20
|
### Table of Contents
|
|
21
21
|
|
|
22
|
-
* [
|
|
22
|
+
* [createExpressionTransformer](#createexpressiontransformer)
|
|
23
23
|
* [Parameters](#parameters)
|
|
24
|
-
* [
|
|
24
|
+
* [createPropertiesTransformer](#createpropertiestransformer)
|
|
25
25
|
* [Parameters](#parameters-1)
|
|
26
|
+
* [transform](#transform)
|
|
27
|
+
* [Parameters](#parameters-2)
|
|
28
|
+
|
|
29
|
+
## createExpressionTransformer
|
|
30
|
+
|
|
31
|
+
Transformer expanding '{{}}' expressions
|
|
32
|
+
|
|
33
|
+
### Parameters
|
|
34
|
+
|
|
35
|
+
* `match` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 
|
|
36
|
+
* `properties` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
|
|
37
|
+
* `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** (optional, default `"expression"`)
|
|
26
38
|
|
|
27
39
|
## createPropertiesTransformer
|
|
28
40
|
|
|
@@ -33,7 +45,7 @@ On match the entry will be assigned new properties as given by propertyDefinitio
|
|
|
33
45
|
|
|
34
46
|
* `match`  
|
|
35
47
|
* `propertyDefinitions` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
|
|
36
|
-
* `name`
|
|
48
|
+
* `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** (optional, default `"property"`)
|
|
37
49
|
* `matcher` **Matcher** 
|
|
38
50
|
|
|
39
51
|
Returns **Transformer** 
|
|
@@ -44,9 +56,9 @@ Apply transformers.
|
|
|
44
56
|
|
|
45
57
|
### Parameters
|
|
46
58
|
|
|
47
|
-
* `source` **
|
|
59
|
+
* `source` **AsyncIterable\<ContentEntry>** 
|
|
48
60
|
* `transformers` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\<Transformer>** (optional, default `[]`)
|
|
49
|
-
* `onlyMatching`
|
|
61
|
+
* `onlyMatching` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** filter out all none matching entries
|
|
50
62
|
|
|
51
63
|
# install
|
|
52
64
|
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "content-entry-transform",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.30",
|
|
4
4
|
"publishConfig": {
|
|
5
|
-
"access": "public"
|
|
5
|
+
"access": "public",
|
|
6
|
+
"provenance": true
|
|
6
7
|
},
|
|
7
8
|
"exports": {
|
|
8
9
|
".": "./src/transform.mjs"
|
|
@@ -17,27 +18,27 @@
|
|
|
17
18
|
"license": "BSD-2-Clause",
|
|
18
19
|
"scripts": {
|
|
19
20
|
"test": "npm run test:browser-ava && npm run test:ava",
|
|
20
|
-
"test:ava": "ava --timeout
|
|
21
|
+
"test:ava": "ava --timeout 4m tests/*-ava.mjs tests/*-ava-node.mjs",
|
|
21
22
|
"test:browser-ava": "browser-ava --headless --no-keep-open tests/*-ava.mjs tests/*-ava-browser.mjs",
|
|
22
|
-
"cover": "c8 -x 'tests/**/*' --temp-directory build/tmp ava --timeout
|
|
23
|
+
"cover": "c8 -x 'tests/**/*' --temp-directory build/tmp ava --timeout 4m tests/*-ava.mjs tests/*-ava-node.mjs && c8 report -r lcov -o build/coverage --temp-directory build/tmp",
|
|
23
24
|
"docs": "documentation readme --section=API ./src/**/*.mjs",
|
|
24
25
|
"lint": "npm run lint:docs",
|
|
25
26
|
"lint:docs": "documentation lint ./src/**/*.mjs"
|
|
26
27
|
},
|
|
27
28
|
"dependencies": {
|
|
28
|
-
"content-entry": "^
|
|
29
|
-
"iterable-string-interceptor": "^
|
|
29
|
+
"content-entry": "^11.0.0",
|
|
30
|
+
"iterable-string-interceptor": "^3.0.0"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
|
-
"ava": "^
|
|
33
|
-
"browser-ava": "^
|
|
34
|
-
"c8": "^
|
|
35
|
-
"documentation": "^14.0.
|
|
36
|
-
"semantic-release": "^
|
|
33
|
+
"ava": "^6.1.3",
|
|
34
|
+
"browser-ava": "^2.2.14",
|
|
35
|
+
"c8": "^9.1.0",
|
|
36
|
+
"documentation": "^14.0.3",
|
|
37
|
+
"semantic-release": "^23.1.1"
|
|
37
38
|
},
|
|
38
39
|
"repository": {
|
|
39
40
|
"type": "git",
|
|
40
|
-
"url": "https://github.com/arlac77/content-entry-transform"
|
|
41
|
+
"url": "git+https://github.com/arlac77/content-entry-transform.git"
|
|
41
42
|
},
|
|
42
43
|
"bugs": {
|
|
43
44
|
"url": "https://github.com/arlac77/content-entry-transform/issues"
|
|
@@ -47,7 +48,7 @@
|
|
|
47
48
|
"inheritFrom": [
|
|
48
49
|
"arlac77/template-arlac77-github",
|
|
49
50
|
"arlac77/template-browser-ava",
|
|
50
|
-
"arlac77/template-
|
|
51
|
+
"arlac77/template-javascript-component"
|
|
51
52
|
]
|
|
52
53
|
}
|
|
53
54
|
}
|
|
@@ -36,33 +36,51 @@ export function createPropertiesInterceptor(properties) {
|
|
|
36
36
|
}
|
|
37
37
|
return value;
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
else {
|
|
40
|
+
return leadIn + e + leadOut;
|
|
41
|
+
}
|
|
42
|
+
// return "";
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
yield ev(expression, 0);
|
|
43
46
|
};
|
|
44
47
|
}
|
|
45
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Transformer expanding '{{}}' expressions
|
|
51
|
+
* @param {string} match
|
|
52
|
+
* @param {Object} properties
|
|
53
|
+
* @param {string} name
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
46
56
|
export function createExpressionTransformer(
|
|
47
57
|
match,
|
|
48
58
|
properties,
|
|
49
59
|
name = "expression"
|
|
50
60
|
) {
|
|
61
|
+
|
|
62
|
+
const decoder = new TextDecoder();
|
|
63
|
+
|
|
64
|
+
async function * streamToText(stream)
|
|
65
|
+
{
|
|
66
|
+
for await (const chunk of stream) {
|
|
67
|
+
yield decoder.decode(chunk);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
51
71
|
return {
|
|
52
72
|
name,
|
|
53
73
|
match,
|
|
54
74
|
transform: async entry => {
|
|
55
|
-
//console.log("TRANSFORM",entry.name);
|
|
56
75
|
const ne = new ReadableStreamContentEntry(
|
|
57
76
|
entry.name,
|
|
58
77
|
iterableStringInterceptor(
|
|
59
|
-
await entry.getReadStream(
|
|
78
|
+
streamToText(await entry.getReadStream()),
|
|
60
79
|
createPropertiesInterceptor(properties)
|
|
61
80
|
)
|
|
62
81
|
);
|
|
63
82
|
ne.destination = entry.destination; // TODO all the other attributes ?
|
|
64
83
|
return ne;
|
|
65
|
-
//return Object.assign(entry,ne);
|
|
66
84
|
}
|
|
67
85
|
};
|
|
68
86
|
}
|
package/src/transform.mjs
CHANGED
|
@@ -2,11 +2,13 @@ export * from "./properties-transformer.mjs";
|
|
|
2
2
|
export * from "./expression-transformer.mjs";
|
|
3
3
|
export * from "./matcher.mjs";
|
|
4
4
|
|
|
5
|
+
import { ContentEntry} from "content-entry";
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* Apply transformers.
|
|
7
|
-
* @param {
|
|
9
|
+
* @param {AsyncIterable<ContentEntry>} source
|
|
8
10
|
* @param {Transformer[]} transformers
|
|
9
|
-
* @param {
|
|
11
|
+
* @param {boolean} onlyMatching filter out all none matching entries
|
|
10
12
|
*/
|
|
11
13
|
export async function* transform(source, transformers = [], onlyMatching) {
|
|
12
14
|
const usedTransformers = new Set();
|
|
@@ -14,7 +16,6 @@ export async function* transform(source, transformers = [], onlyMatching) {
|
|
|
14
16
|
for await (let entry of source) {
|
|
15
17
|
let didMatch = false;
|
|
16
18
|
for (const t of transformers) {
|
|
17
|
-
//console.log(t.name, entry.name, t.match(entry));
|
|
18
19
|
if (t.match(entry)) {
|
|
19
20
|
didMatch = true;
|
|
20
21
|
entry = await t.transform(entry);
|
|
@@ -22,7 +23,7 @@ export async function* transform(source, transformers = [], onlyMatching) {
|
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
if (
|
|
26
|
+
if (didMatch || !onlyMatching) {
|
|
26
27
|
yield entry;
|
|
27
28
|
}
|
|
28
29
|
}
|