Compiler
Stentor API Reference / stentor-utils/src / Compiler
Class: Compiler
Defined in: packages/stentor-utils/src/compilers/compiler.ts:56
Compiles the templated response based on the provided request and context with some configurability.
You can provide custom macros that can be used to modify the templated response and also additional context that will be used as possible replacements.
Implementsβ
Constructorsβ
Constructorβ
new Compiler(
props?):Compiler
Defined in: packages/stentor-utils/src/compilers/compiler.ts:64
Parametersβ
props?β
Returnsβ
Compiler
Propertiesβ
replaceWhenUndefined?β
readonlyoptionalreplaceWhenUndefined:boolean
Defined in: packages/stentor-utils/src/compilers/compiler.ts:58
When true, it will replace the ${foo} with undefined or null if the value for foo cannot be found. Default behavior will leave ${foo} if it does not have a value.
A caveat to this is when the foo is in a string such as "${foo}" then it will replace it with an empty string instead of undefined, thus "" instead of "undefined". The reason for this
is "" is falsey and "undefined" is not. If you are doing string comparisons then this will be a problem.
Implementation ofβ
CompilerProps.replaceWhenUndefined
macros?β
readonlyoptionalmacros:MacroMap
Defined in: packages/stentor-utils/src/compilers/compiler.ts:60
When provided it overrides the DEFAULT_MACROS and are used when compiling the templates.
You can include the DEFAULT_MACROS if you include them:
macros: {
...DEFAULT_MACROS,
...myMacros
}
Implementation ofβ
additionalContext?β
readonlyoptionaladditionalContext:Record\<string,unknown> ={}
Defined in: packages/stentor-utils/src/compilers/compiler.ts:62
When provided, the additional context will be used when compiling the templates. This is an opportunity to inject more information beyond the provided request and context objects.
Implementation ofβ
CompilerProps.additionalContext
Methodsβ
compile()β
Call Signatureβ
compile(
input,request,context):string
Defined in: packages/stentor-utils/src/compilers/compiler.ts:259
Compiles the provided response output or string based on the provided request and context.
It is used for compiling conditions on a response or injecting variables into responses.
Parametersβ
inputβ
string
Either a string or a set of responses.
requestβ
The request
contextβ
Context object
Returnsβ
string
Call Signatureβ
compile(
input,request,context):ResponseOutput
Defined in: packages/stentor-utils/src/compilers/compiler.ts:260
Compiles the provided response output or string based on the provided request and context.
It is used for compiling conditions on a response or injecting variables into responses.
Parametersβ
inputβ
Either a string or a set of responses.
requestβ
The request
contextβ
Context object