iterable-string-interceptor
v3.0.0
Published
Intercept iterable string - backbone for template engines
Downloads
6,605
Readme
iterable-string-interceptor
Intercept Iterable string - backbone for template engines
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);
}
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
Type: Function
Parameters
expression
string detected expression without leadIn / leadOutremainder
string chunk after leadOutsource
Iterable<string> original sourcecb
EarlyConsumerCallback to be called if remainder has changedleadIn
string expression entry sequenceleadOut
string expression exit sequence
Returns AsyncIterable<string> transformed source
EarlyConsumerCallback
Will be called from the ExpressionTransformer if the given remainder needs to be altered.
Type: Function
Parameters
remainder
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>transform
ExpressionTransformerleadIn
string expression entry sequence (optional, default"{{"
)leadOut
string expression exit sequence (optional, default"}}"
)
Returns AsyncIterable<string> transformed source
install
With npm do:
npm install iterable-string-interceptor
license
BSD-2-Clause