content-entry-transform 1.1.0 → 1.3.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 +49 -0
- package/package.json +3 -2
- package/src/expression-transformer.mjs +16 -3
- package/src/matcher.mjs +6 -0
- package/src/properties-transformer.mjs +5 -2
- package/src/transform.mjs +3 -1
package/README.md
CHANGED
|
@@ -8,5 +8,54 @@
|
|
|
8
8
|
[](http://commitizen.github.io/cz-cli/)
|
|
9
9
|
[](https://snyk.io/test/github/arlac77/content-entry-transform)
|
|
10
10
|
[](https://coveralls.io/github/arlac77/content-entry-transform)
|
|
11
|
+
|
|
11
12
|
# content-entry-transform
|
|
13
|
+
|
|
12
14
|
transform content entries
|
|
15
|
+
|
|
16
|
+
# API
|
|
17
|
+
|
|
18
|
+
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
|
19
|
+
|
|
20
|
+
### Table of Contents
|
|
21
|
+
|
|
22
|
+
* [createPropertiesTransformer](#createpropertiestransformer)
|
|
23
|
+
* [Parameters](#parameters)
|
|
24
|
+
* [transform](#transform)
|
|
25
|
+
* [Parameters](#parameters-1)
|
|
26
|
+
|
|
27
|
+
## createPropertiesTransformer
|
|
28
|
+
|
|
29
|
+
Creates a new transformer.
|
|
30
|
+
On match the enrtry will be assigned noe properties as given by propertyDefinitions.
|
|
31
|
+
|
|
32
|
+
### Parameters
|
|
33
|
+
|
|
34
|
+
* `match`
|
|
35
|
+
* `propertyDefinitions` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
|
|
36
|
+
* `name` (optional, default `"property"`)
|
|
37
|
+
* `matcher` **Matcher**
|
|
38
|
+
|
|
39
|
+
Returns **Transformer**
|
|
40
|
+
|
|
41
|
+
## transform
|
|
42
|
+
|
|
43
|
+
Apply transformers.
|
|
44
|
+
|
|
45
|
+
### Parameters
|
|
46
|
+
|
|
47
|
+
* `source` **AsyncIterator\<ContentEntry>**
|
|
48
|
+
* `transformers` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\<Transformer>** (optional, default `[]`)
|
|
49
|
+
* `onlyMatching`
|
|
50
|
+
|
|
51
|
+
# install
|
|
52
|
+
|
|
53
|
+
With [npm](http://npmjs.org) do:
|
|
54
|
+
|
|
55
|
+
```shell
|
|
56
|
+
npm install content-entry-transform
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
# license
|
|
60
|
+
|
|
61
|
+
BSD-2-Clause
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "content-entry-transform",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"lint:docs": "documentation lint ./src/**/*.mjs"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"content-entry": "^4.0.0"
|
|
28
|
+
"content-entry": "^4.0.0",
|
|
29
|
+
"iterable-string-interceptor": "^1.0.11"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"ava": "^4.0.1",
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import { ReadableStreamContentEntry } from "content-entry";
|
|
2
|
+
import { iterableStringInterceptor } from "iterable-string-interceptor";
|
|
3
|
+
import { nameExtensionMatcher } from "./matcher.mjs";
|
|
4
|
+
|
|
5
|
+
export const utf8StreamOptions = { encoding: "utf8" };
|
|
6
|
+
|
|
1
7
|
export function createPropertiesInterceptor(properties) {
|
|
2
8
|
return async function* transformer(expression, remainder, source, cb) {
|
|
3
9
|
const value = properties[expression];
|
|
@@ -6,12 +12,19 @@ export function createPropertiesInterceptor(properties) {
|
|
|
6
12
|
}
|
|
7
13
|
|
|
8
14
|
export function createExpressionTransformer(
|
|
15
|
+
match = nameExtensionMatcher([
|
|
16
|
+
".conf",
|
|
17
|
+
".json",
|
|
18
|
+
".html",
|
|
19
|
+
".txt",
|
|
20
|
+
".service",
|
|
21
|
+
".socket"
|
|
22
|
+
]),
|
|
9
23
|
properties,
|
|
10
|
-
|
|
11
|
-
entry.name.match(/\.(conf|json|html|txt|service|socket)$/) ? true : false
|
|
24
|
+
name = "expression"
|
|
12
25
|
) {
|
|
13
26
|
return {
|
|
14
|
-
name
|
|
27
|
+
name,
|
|
15
28
|
match,
|
|
16
29
|
transform: async entry => {
|
|
17
30
|
//console.log("TRANSFORM",entry.name);
|
package/src/matcher.mjs
ADDED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
/**
|
|
3
2
|
* Creates a new transformer.
|
|
4
3
|
* On match the enrtry will be assigned noe properties as given by propertyDefinitions.
|
|
@@ -6,7 +5,11 @@
|
|
|
6
5
|
* @param {Matcher} matcher
|
|
7
6
|
* @return {Transformer}
|
|
8
7
|
*/
|
|
9
|
-
export function createPropertiesTransformer(
|
|
8
|
+
export function createPropertiesTransformer(
|
|
9
|
+
match,
|
|
10
|
+
propertyDefinitions,
|
|
11
|
+
name = "property"
|
|
12
|
+
) {
|
|
10
13
|
return {
|
|
11
14
|
name,
|
|
12
15
|
match,
|
package/src/transform.mjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export * from "./properties-transformer.mjs";
|
|
2
|
+
export * from "./expression-transformer.mjs";
|
|
3
|
+
export * from "./matcher.mjs";
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Apply transformers.
|
|
@@ -12,7 +14,7 @@ export async function* transform(source, transformers = [], onlyMatching) {
|
|
|
12
14
|
for await (let entry of source) {
|
|
13
15
|
let didMatch = false;
|
|
14
16
|
for (const t of transformers) {
|
|
15
|
-
//console.log(t.name,entry.name,t.match(entry));
|
|
17
|
+
//console.log(t.name, entry.name, t.match(entry));
|
|
16
18
|
if (t.match(entry)) {
|
|
17
19
|
didMatch = true;
|
|
18
20
|
entry = await t.transform(entry);
|