iterable-string-interceptor 1.0.8 → 1.0.12
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 +28 -26
- package/package.json +6 -6
- package/src/iterable-string-interceptor.mjs +3 -3
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://bundlephobia.com/result?p=iterable-string-interceptor)
|
|
4
4
|
[](https://npmjs.org/package/iterable-string-interceptor)
|
|
5
5
|
[](https://github.com/arlac77/iterable-string-interceptor/issues)
|
|
6
|
-
[](https://actions-badge.atrox.dev/arlac77/iterable-string-interceptor/goto)
|
|
7
7
|
[](https://github.com/prettier/prettier)
|
|
8
8
|
[](http://commitizen.github.io/cz-cli/)
|
|
9
9
|
[](https://snyk.io/test/github/arlac77/iterable-string-interceptor)
|
|
@@ -18,11 +18,12 @@ Intercept Iterable string - backbone for templates
|
|
|
18
18
|
```javascript
|
|
19
19
|
import { iterableStringInterceptor } from "iterable-string-interceptor";
|
|
20
20
|
import { createReadStream } from "fs";
|
|
21
|
+
import { readFile } from "fs/promises";
|
|
21
22
|
|
|
22
23
|
// double values inside {{}}
|
|
23
24
|
// {{7}} -> 14
|
|
24
25
|
for await (const chunk of iterableStringInterceptor(createReadStream('aFile', { encoding: "utf8" }),
|
|
25
|
-
|
|
26
|
+
expression => expression * 2
|
|
26
27
|
)) {
|
|
27
28
|
process.stdout.write(chunk);
|
|
28
29
|
}
|
|
@@ -30,11 +31,12 @@ async * (expression) => { yield expression * 2; }
|
|
|
30
31
|
|
|
31
32
|
```javascript
|
|
32
33
|
import { iterableStringInterceptor } from "iterable-string-interceptor";
|
|
33
|
-
import
|
|
34
|
+
import { createReadStream } from "fs";
|
|
35
|
+
import { readFile } from "fs/promises";
|
|
34
36
|
|
|
35
37
|
// handle expression as to be included content {{filename}}
|
|
36
38
|
for await (const chunk of iterableStringInterceptor(createReadStream('aFile', { encoding: "utf8" }),
|
|
37
|
-
async * (expression) => { yield
|
|
39
|
+
async * (expression) => { yield readFile(expression, { encoding: "utf8" }); }
|
|
38
40
|
)) {
|
|
39
41
|
process.stdout.write(chunk);
|
|
40
42
|
}
|
|
@@ -46,12 +48,12 @@ async * (expression) => { yield fs.promises.readFile(expression,{encoding: "utf8
|
|
|
46
48
|
|
|
47
49
|
### Table of Contents
|
|
48
50
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
* [ExpressionTransformer](#expressiontransformer)
|
|
52
|
+
* [Parameters](#parameters)
|
|
53
|
+
* [EarlyConsumerCallback](#earlyconsumercallback)
|
|
54
|
+
* [Parameters](#parameters-1)
|
|
55
|
+
* [iterableStringInterceptor](#iterablestringinterceptor)
|
|
56
|
+
* [Parameters](#parameters-2)
|
|
55
57
|
|
|
56
58
|
## ExpressionTransformer
|
|
57
59
|
|
|
@@ -59,38 +61,38 @@ Type: ()
|
|
|
59
61
|
|
|
60
62
|
### Parameters
|
|
61
63
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
* `expression` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** detected expression without leadIn / leadOut
|
|
65
|
+
* `remainder` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** chunk after leadOut
|
|
66
|
+
* `source` **Iterable<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** original source
|
|
67
|
+
* `cb` **[EarlyConsumerCallback](#earlyconsumercallback)** to be called if remainder has changed
|
|
68
|
+
* `leadIn` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** expression entry sequence
|
|
69
|
+
* `leadOut` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** expression exit sequence
|
|
68
70
|
|
|
69
|
-
Returns **Iterable
|
|
71
|
+
Returns **Iterable<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** transformed source
|
|
70
72
|
|
|
71
73
|
## EarlyConsumerCallback
|
|
72
74
|
|
|
73
|
-
|
|
75
|
+
Will be called from the ExpressionTransformer if the given remainder needs to be altered.
|
|
74
76
|
|
|
75
77
|
Type: ()
|
|
76
78
|
|
|
77
79
|
### Parameters
|
|
78
80
|
|
|
79
|
-
|
|
81
|
+
* `remainder` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** new remainder to be used by iterableStringInterceptor
|
|
80
82
|
|
|
81
83
|
## iterableStringInterceptor
|
|
82
84
|
|
|
83
|
-
|
|
84
|
-
and asking a transformer for a replacement iterable string
|
|
85
|
+
Intercept into a async iterable string source, detecting lead in/outs like '{{' and '}}'
|
|
86
|
+
and asking a transformer for a replacement iterable string.
|
|
85
87
|
|
|
86
88
|
### Parameters
|
|
87
89
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
* `source` **Iterable<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>**
|
|
91
|
+
* `transform` **[ExpressionTransformer](#expressiontransformer)**
|
|
92
|
+
* `leadIn` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** expression entry sequence (optional, default `"{{"`)
|
|
93
|
+
* `leadOut` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** expression exit sequence (optional, default `"}}"`)
|
|
92
94
|
|
|
93
|
-
Returns **Iterable
|
|
95
|
+
Returns **Iterable<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** transformed source
|
|
94
96
|
|
|
95
97
|
# install
|
|
96
98
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iterable-string-interceptor",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -29,13 +29,13 @@
|
|
|
29
29
|
"lint:docs": "documentation lint ./src/**/*.mjs"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"ava": "^
|
|
33
|
-
"c8": "^7.
|
|
34
|
-
"documentation": "
|
|
35
|
-
"semantic-release": "^
|
|
32
|
+
"ava": "^4.0.1",
|
|
33
|
+
"c8": "^7.11.0",
|
|
34
|
+
"documentation": "^13.2.5",
|
|
35
|
+
"semantic-release": "^19.0.2"
|
|
36
36
|
},
|
|
37
37
|
"engines": {
|
|
38
|
-
"node": ">=
|
|
38
|
+
"node": ">=14.18.3"
|
|
39
39
|
},
|
|
40
40
|
"repository": {
|
|
41
41
|
"type": "git",
|
|
@@ -10,14 +10,14 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Will be called from the ExpressionTransformer if the given remainder needs to be altered.
|
|
14
14
|
* @typedef {()} EarlyConsumerCallback
|
|
15
15
|
* @param {string} remainder new remainder to be used by iterableStringInterceptor
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
20
|
-
* and asking a transformer for a replacement iterable string
|
|
19
|
+
* Intercept into a async iterable string source, detecting lead in/outs like '{{' and '}}'
|
|
20
|
+
* and asking a transformer for a replacement iterable string.
|
|
21
21
|
* @param {Iterable<string>} source
|
|
22
22
|
* @param {ExpressionTransformer} transform
|
|
23
23
|
* @param {string} leadIn expression entry sequence
|