https://github.com/arlac77/iterable-string-interceptor
Intercept Iterable string - backbone for templates
https://github.com/arlac77/iterable-string-interceptor
Last synced: 3 months ago
JSON representation
Intercept Iterable string - backbone for templates
- Host: GitHub
- URL: https://github.com/arlac77/iterable-string-interceptor
- Owner: arlac77
- License: 0bsd
- Created: 2018-12-31T10:39:55.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2026-03-04T20:10:36.000Z (3 months ago)
- Last Synced: 2026-03-05T01:41:57.229Z (3 months ago)
- Language: JavaScript
- Size: 2.39 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.npmjs.com/package/iterable-string-interceptor)
[](https://spdx.org/licenses/0BSD.html)
[](https://typescriptlang.org)
[](https://bundlejs.com/?q=iterable-string-interceptor)
[](https://npmjs.org/package/iterable-string-interceptor)
[](https://github.com/arlac77/iterable-string-interceptor/issues)
[](https://actions-badge.atrox.dev/arlac77/iterable-string-interceptor/goto)
[](https://github.com/prettier/prettier)
[](http://commitizen.github.io/cz-cli/)
[](https://snyk.io/test/github/arlac77/iterable-string-interceptor)
# iterable-string-interceptor
Intercept Iterable string - backbone for template engines
```javascript
import { iterableStringInterceptor } from "iterable-string-interceptor";
import { createReadStream } from "fs";
import { readFile } from "fs/promises";
// double values inside {{}}
// {{7}} -> 14
for await (const chunk of iterableStringInterceptor(createReadStream('aFile', { encoding: "utf8" }),
expression => expression * 2
)) {
process.stdout.write(chunk);
}
```
```javascript
import { iterableStringInterceptor } from "iterable-string-interceptor";
import { createReadStream } from "fs";
import { readFile } from "fs/promises";
// handle expression as to be included content {{filename}}
for await (const chunk of iterableStringInterceptor(createReadStream('aFile', { encoding: "utf8" }),
async * (expression) => { yield readFile(expression, { encoding: "utf8" }); }
)) {
process.stdout.write(chunk);
}
```
# API
### Table of Contents
* [ExpressionTransformer](#expressiontransformer)
* [Parameters](#parameters)
* [EarlyConsumerCallback](#earlyconsumercallback)
* [Parameters](#parameters-1)
* [iterableStringInterceptor](#iterablestringinterceptor)
* [Parameters](#parameters-2)
## ExpressionTransformer
Type: function ([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), Iterable<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>, [EarlyConsumerCallback](#earlyconsumercallback), [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)): AsyncIterable<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>
### Parameters
* `expression` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** detected expression without leadIn / leadOut
* `remainder` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** chunk after leadOut
* `source` **Iterable<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** original source
* `cb` **[EarlyConsumerCallback](#earlyconsumercallback)** to be called if remainder has changed
* `leadIn` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** expression entry sequence
* `leadOut` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** expression exit sequence
Returns **AsyncIterable<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** transformed source
## EarlyConsumerCallback
Will be called from the ExpressionTransformer if the given remainder needs to be altered.
Type: function ([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)): void
### Parameters
* `remainder` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** new remainder to be used by iterableStringInterceptor
## iterableStringInterceptor
Intercept into a async iterable string source, detecting lead in/outs like '{{' and '}}'
and asking a transformer for a replacement iterable string.
### Parameters
* `source` **Iterable<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>**
* `transform` **[ExpressionTransformer](#expressiontransformer)**
* `leadIn` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** expression entry sequence (optional, default `"{{"`)
* `leadOut` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** expression exit sequence (optional, default `"}}"`)
Returns **AsyncIterable<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** transformed source
# install
With [npm](http://npmjs.org) do:
```shell
npm install iterable-string-interceptor
```
# license
BSD-2-Clause