content-entry-transform 1.0.0 → 1.2.1
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 +16 -0
- package/package.json +1 -1
- package/src/expression-transformer.mjs +12 -3
- package/src/matcher.mjs +6 -0
- package/src/properties-transformer.mjs +13 -2
- package/src/transform.mjs +2 -1
package/README.md
CHANGED
|
@@ -8,5 +8,21 @@
|
|
|
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
|
|
12
13
|
transform content entries
|
|
14
|
+
|
|
15
|
+
# API
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# install
|
|
19
|
+
|
|
20
|
+
With [npm](http://npmjs.org) do:
|
|
21
|
+
|
|
22
|
+
```shell
|
|
23
|
+
npm install content-entry-transform
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
# license
|
|
27
|
+
|
|
28
|
+
BSD-2-Clause
|
package/package.json
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { nameExtensionMatcher } from "./matcher.mjs";
|
|
2
|
+
|
|
1
3
|
export function createPropertiesInterceptor(properties) {
|
|
2
4
|
return async function* transformer(expression, remainder, source, cb) {
|
|
3
5
|
const value = properties[expression];
|
|
@@ -6,12 +8,19 @@ export function createPropertiesInterceptor(properties) {
|
|
|
6
8
|
}
|
|
7
9
|
|
|
8
10
|
export function createExpressionTransformer(
|
|
11
|
+
match = nameExtensionMatcher([
|
|
12
|
+
".conf",
|
|
13
|
+
".json",
|
|
14
|
+
".html",
|
|
15
|
+
".txt",
|
|
16
|
+
".service",
|
|
17
|
+
".socket"
|
|
18
|
+
]),
|
|
9
19
|
properties,
|
|
10
|
-
|
|
11
|
-
entry.name.match(/\.(conf|json|html|txt|service|socket)$/) ? true : false
|
|
20
|
+
name = "expression"
|
|
12
21
|
) {
|
|
13
22
|
return {
|
|
14
|
-
name
|
|
23
|
+
name,
|
|
15
24
|
match,
|
|
16
25
|
transform: async entry => {
|
|
17
26
|
//console.log("TRANSFORM",entry.name);
|
package/src/matcher.mjs
ADDED
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new transformer.
|
|
3
|
+
* On match the enrtry will be assigned noe properties as given by propertyDefinitions.
|
|
4
|
+
* @param {Object} propertyDefinitions
|
|
5
|
+
* @param {Matcher} matcher
|
|
6
|
+
* @return {Transformer}
|
|
7
|
+
*/
|
|
8
|
+
export function createPropertiesTransformer(
|
|
9
|
+
match,
|
|
10
|
+
propertyDefinitions,
|
|
11
|
+
name = "property"
|
|
12
|
+
) {
|
|
2
13
|
return {
|
|
3
|
-
name
|
|
14
|
+
name,
|
|
4
15
|
match,
|
|
5
16
|
transform: async entry => Object.create(entry, propertyDefinitions)
|
|
6
17
|
};
|
package/src/transform.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from "./properties-transformer.mjs";
|
|
2
|
+
export * from "./matcher.mjs";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Apply transformers.
|
|
@@ -12,7 +13,7 @@ export async function* transform(source, transformers = [], onlyMatching) {
|
|
|
12
13
|
for await (let entry of source) {
|
|
13
14
|
let didMatch = false;
|
|
14
15
|
for (const t of transformers) {
|
|
15
|
-
//console.log(t.name,entry.name,t.match(entry));
|
|
16
|
+
//console.log(t.name, entry.name, t.match(entry));
|
|
16
17
|
if (t.match(entry)) {
|
|
17
18
|
didMatch = true;
|
|
18
19
|
entry = await t.transform(entry);
|