@types/ejs
- Version 3.1.5
- Published
- 16.9 kB
- No dependencies
- MIT license
Install
npm i @types/ejs
yarn add @types/ejs
pnpm add @types/ejs
Overview
TypeScript definitions for ejs
Index
Variables
Functions
Classes
Interfaces
Type Aliases
Namespaces
Variables
variable cache
let cache: Cache;
EJS template function cache. This can be a LRU object from lru-cache NPM module. By default, it is
utils.cache
, a simple in-process cache that grows continuously.
variable closeDelimiter
let closeDelimiter: string;
The closing delimiter for all statements. This allows to to clearly delinate the difference between template code and existing delimiters. (It is recommended to synchronize this with the openDelimiter property.)
'>'
variable delimiter
let delimiter: string;
The delimiter used in template compilation.
'%'
variable fileLoader
let fileLoader: fileLoader;
variable localsName
let localsName: string;
Name of the object containing the locals.
This variable is overridden by Options
.localsName
if it is notundefined
.'locals'
variable name
const name: string;
Name for detection of EJS.
variable openDelimiter
let openDelimiter: string;
The opening delimiter for all statements. This allows you to clearly delinate the difference between template code and existing delimiters. (It is recommended to synchronize this with the closeDelimiter property.)
'<'
variable promiseImpl
let promiseImpl: PromiseConstructorLike;
Promise implementation -- defaults to the native implementation if available This is mostly just for testability
Promise
variable VERSION
const VERSION: string;
Version of EJS.
Functions
function clearCache
clearCache: () => void;
Clear intermediate JavaScript cache. Calls Cache#reset.
function compile
compile: { ( template: string, opts: Options & { async: true; client?: false | undefined } ): AsyncTemplateFunction; ( template: string, opts: Options & { async: true; client: true } ): AsyncClientFunction; ( template: string, opts?: Options & { async?: false; client?: false } ): TemplateFunction; ( template: string, opts?: Options & { async?: false; client: true } ): ClientFunction; (template: string, opts?: Options): AsyncTemplateFunction | TemplateFunction;};
Compile the given
str
of ejs into a template function.
function escapeXML
escapeXML: (markup?: any) => string;
Escape characters reserved in XML.
This is simply an export of
utils.escapeXML
.If
markup
isundefined
ornull
, the empty string is returned.
function render
render: { (template: string, data?: Data, opts?: Options & { async: false }): string; (template: string, data: Data, opts: Options & { async: true }): Promise<string>; (template: string, data: Data, opts: Options & { async?: undefined }): string; (template: string, data?: Data, opts?: Options): string | Promise<string>;};
Render the given
template
of ejs.If you would like to include options but not data, you need to explicitly call this function with
data
being an empty object ornull
.
function renderFile
renderFile: { <T>(path: string, cb: RenderFileCallback<T>): T; <T>(path: string, data: Data, cb: RenderFileCallback<T>): T; <T>(path: string, data: Data, opts: Options, cb: RenderFileCallback<T>): T; (path: string, data?: Data, opts?: Options): Promise<string>;};
Render an EJS file at the given
path
and callbackcb(err, str)
.If you would like to include options but not data, you need to explicitly call this function with
data
being an empty object ornull
.
function resolveInclude
resolveInclude: (name: string, filename: string, isDir?: boolean) => string;
Get the path to the included file from the parent file path and the specified path.
Parameter name
specified path
Parameter filename
parent file path
Parameter isDir
whether the parent file path is a directory
Classes
class Template
class Template {}
constructor
constructor(text: string, opts?: Options);
property source
readonly source: string;
The compiled JavaScript function source, or the empty string if the template hasn't been compiled yet.
property templateText
readonly templateText: string;
The EJS template source text.
method compile
compile: () => | TemplateFunction | AsyncTemplateFunction | ClientFunction | AsyncClientFunction;
Compiles the EJS template.
Interfaces
interface Cache
interface Cache {}
method get
get: (key: string) => TemplateFunction | undefined;
Get the cached intermediate JavaScript function for a template.
Parameter key
key for caching
method reset
reset: () => void;
Clear the entire cache.
method set
set: (key: string, val: TemplateFunction) => void;
Cache the intermediate JavaScript function for a template.
Parameter key
key for caching
Parameter val
cached function
interface Data
interface Data {}
index signature
[name: string]: any;
interface Options
interface Options {}
property async
async?: boolean | undefined;
Whether or not to create an async function instead of a regular function. This requires language support.
false
property beautify
beautify?: boolean | undefined;
Make sure to set this to 'false' in order to skip UglifyJS parsing, when using ES6 features (
const
, etc) as UglifyJS doesn't understand them. true
property cache
cache?: boolean | undefined;
Whether or not to enable caching of template functions. Beware that the options of compilation are not checked as being the same, so special handling is required if, for example, you want to cache client and regular functions of the same file.
Requires
filename
to be set. Only works with rendering function.false
property client
client?: boolean | undefined;
Whether or not to compile a
ClientFunction
that can be rendered in the browser without depending on ejs.js. Otherwise, aTemplateFunction
will be compiled.false
property closeDelimiter
closeDelimiter?: string | undefined;
The closing delimiter for all statements. This allows to to clearly delinate the difference between template code and existing delimiters. (It is recommended to synchronize this with the openDelimiter property.)
ejs.closeDelimiter
property compileDebug
compileDebug?: boolean | undefined;
Include additional runtime debugging information in generated template functions.
true
property context
context?: any;
The Object to which
this
is set during rendering.this
property debug
debug?: boolean | undefined;
Log the generated JavaScript source for the EJS template to the console.
false
property delimiter
delimiter?: string | undefined;
Character to use with angle brackets for open/close '%'
property destructuredLocals
destructuredLocals?: string[] | undefined;
An array of local variables that are always destructured from
localsName
, available even in strict mode.[]
property escape
escape?: EscapeCallback | undefined;
The escaping function used with
<%=
construct. It is used in rendering and is.toString()
ed in the generation of client functions.ejs.escapeXML
property filename
filename?: string | undefined;
The filename of the template. Required for inclusion and caching unless you are using
renderFile
. Also used for error reporting.undefined
property includer
includer?: IncluderCallback;
Custom function to handle EJS includes
property localsName
localsName?: string | undefined;
Name to use for the object storing local variables when not using
with
or destructuring.ejs.localsName
property openDelimiter
openDelimiter?: string | undefined;
The opening delimiter for all statements. This allows you to clearly delinate the difference between template code and existing delimiters. (It is recommended to synchronize this with the closeDelimiter property.)
ejs.openDelimiter
property outputFunctionName
outputFunctionName?: string | undefined;
Set to a string (e.g., 'echo' or 'print') for a function to print output inside scriptlet tags.
property rmWhitespace
rmWhitespace?: boolean | undefined;
Remove all safe-to-remove whitespace, including leading and trailing whitespace. It also enables a safer version of
-%>
line slurping for all scriptlet tags (it does not strip new lines of tags in the middle of a line).false
property root
root?: string[] | string | undefined;
The path to templates root(s). When this is set, absolute paths for includes (/filename.ejs) will be relative to the templates root(s).
undefined
property strict
strict?: boolean | undefined;
Whether to run in strict mode or not. Enforces
_with=false
.false
property views
views?: string[] | undefined;
An array of paths to use when resolving includes with relative paths
Type Aliases
type AsyncClientFunction
type AsyncClientFunction = ( locals?: Data, escape?: EscapeCallback, include?: IncludeCallback, rethrow?: RethrowCallback) => Promise<string>;
This type of function is returned from
compile
, whenOptions.client
is true.This is also used internally to generate a
TemplateFunction
.Parameter locals
an object of data to be passed into the template. The name of this variable is adjustable through
localsName
.Parameter escape
callback used to escape variables
Parameter include
callback used to include files at runtime with
include()
Parameter rethrow
callback used to handle and rethrow errors
Return type depends on
Options.async
.
type AsyncTemplateFunction
type AsyncTemplateFunction = (data?: Data) => Promise<string>;
This type of function is returned from
compile
, whenOptions.client
is false.Parameter data
an object of data to be passed into the template. Return type depends on
Options.async
.
type ClientFunction
type ClientFunction = ( locals?: Data, escape?: EscapeCallback, include?: IncludeCallback, rethrow?: RethrowCallback) => string;
This type of function is returned from
compile
, whenOptions.client
is true.This is also used internally to generate a
TemplateFunction
.Parameter locals
an object of data to be passed into the template. The name of this variable is adjustable through
localsName
.Parameter escape
callback used to escape variables
Parameter include
callback used to include files at runtime with
include()
Parameter rethrow
callback used to handle and rethrow errors
Return type depends on
Options.async
.
type EscapeCallback
type EscapeCallback = (markup?: any) => string;
Escapes a string using HTML/XML escaping rules.
Returns the empty string for
null
orundefined
.Parameter markup
Input string Escaped string
type fileLoader
type fileLoader = (path: string) => string | { toString(): string };
Custom file loader. Useful for template preprocessing or restricting access to a certain part of the filesystem.
Parameter path
the path of the file to be read the contents of the file as a string or object that implements the toString() method
fs.readFileSync
type IncludeCallback
type IncludeCallback = (path: string, data?: Data) => string;
The callback called by
ClientFunction
to include files at runtime withinclude()
Parameter path
Path to be included
Parameter data
Data passed to the template Contents of the file requested
type IncluderCallback
type IncluderCallback = (originalPath: string, parsedPath: string) => IncluderResult;
Parameter originalPath
the path as it appears in the include statement
Parameter parsedPath
the previously resolved path
An IncluderResult object containing the filename or template data.
type IncluderResult
type IncluderResult = | { filename: string; template?: never } | { template: string; filename?: never };
type RenderFileCallback
type RenderFileCallback<T> = (err: Error | null, str: string) => T;
Callback for receiving data from
renderFile
.Parameter err
error, if any resulted from the rendering process
Parameter str
output string, is
undefined
if there is an error
type RethrowCallback
type RethrowCallback = ( err: Error, str: string, filename: string | null | undefined, lineno: number, esc: EscapeCallback) => never;
This type of callback is used when
Options.compileDebug
istrue
, and an error in the template is thrown.By default it is used to rethrow an error in a better-formatted way.
Parameter err
Error object
Parameter str
full EJS source
Parameter filename
file name of the EJS source
Parameter lineno
line number of the error
type TemplateFunction
type TemplateFunction = (data?: Data) => string;
This type of function is returned from
compile
, whenOptions.client
is false.Parameter data
an object of data to be passed into the template. Return type depends on
Options.async
.
Namespaces
Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (0)
No dev dependencies.
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/ejs
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/ejs)
- HTML<a href="https://www.jsdocs.io/package/@types/ejs"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 1892 ms. - Missing or incorrect documentation? Open an issue for this package.