This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

2
node_modules/eta/dist/browser.min.umd.js generated vendored Normal file

File diff suppressed because one or more lines are too long

1
node_modules/eta/dist/browser.min.umd.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

889
node_modules/eta/dist/eta.module.mjs generated vendored Normal file
View File

@@ -0,0 +1,889 @@
import { existsSync, readFileSync } from 'fs';
import * as path from 'path';
function setPrototypeOf(obj, proto) {
// eslint-disable-line @typescript-eslint/no-explicit-any
if (Object.setPrototypeOf) {
Object.setPrototypeOf(obj, proto);
} else {
obj.__proto__ = proto;
}
}
// This is pretty much the only way to get nice, extended Errors
// without using ES6
/**
* This returns a new Error with a custom prototype. Note that it's _not_ a constructor
*
* @param message Error message
*
* **Example**
*
* ```js
* throw EtaErr("template not found")
* ```
*/
function EtaErr(message) {
const err = new Error(message);
setPrototypeOf(err, EtaErr.prototype);
return err;
}
EtaErr.prototype = Object.create(Error.prototype, {
name: {
value: "Eta Error",
enumerable: false
}
});
/**
* Throws an EtaErr with a nicely formatted error and message showing where in the template the error occurred.
*/
function ParseErr(message, str, indx) {
const whitespace = str.slice(0, indx).split(/\n/);
const lineNo = whitespace.length;
const colNo = whitespace[lineNo - 1].length + 1;
message += " at line " + lineNo + " col " + colNo + ":\n\n" + " " + str.split(/\n/)[lineNo - 1] + "\n" + " " + Array(colNo).join(" ") + "^";
throw EtaErr(message);
}
/**
* @returns The global Promise function
*/
const promiseImpl = new Function("return this")().Promise;
/**
* @returns A new AsyncFunction constuctor
*/
function getAsyncFunctionConstructor() {
try {
return new Function("return (async function(){}).constructor")();
} catch (e) {
if (e instanceof SyntaxError) {
throw EtaErr("This environment doesn't support async/await");
} else {
throw e;
}
}
}
/**
* str.trimLeft polyfill
*
* @param str - Input string
* @returns The string with left whitespace removed
*
*/
function trimLeft(str) {
// eslint-disable-next-line no-extra-boolean-cast
if (!!String.prototype.trimLeft) {
return str.trimLeft();
} else {
return str.replace(/^\s+/, "");
}
}
/**
* str.trimRight polyfill
*
* @param str - Input string
* @returns The string with right whitespace removed
*
*/
function trimRight(str) {
// eslint-disable-next-line no-extra-boolean-cast
if (!!String.prototype.trimRight) {
return str.trimRight();
} else {
return str.replace(/\s+$/, ""); // TODO: do we really need to replace BOM's?
}
}
// TODO: allow '-' to trim up until newline. Use [^\S\n\r] instead of \s
/* END TYPES */
function hasOwnProp(obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
}
function copyProps(toObj, fromObj) {
for (const key in fromObj) {
if (hasOwnProp(fromObj, key)) {
toObj[key] = fromObj[key];
}
}
return toObj;
}
/**
* Takes a string within a template and trims it, based on the preceding tag's whitespace control and `config.autoTrim`
*/
function trimWS(str, config, wsLeft, wsRight) {
let leftTrim;
let rightTrim;
if (Array.isArray(config.autoTrim)) {
// kinda confusing
// but _}} will trim the left side of the following string
leftTrim = config.autoTrim[1];
rightTrim = config.autoTrim[0];
} else {
leftTrim = rightTrim = config.autoTrim;
}
if (wsLeft || wsLeft === false) {
leftTrim = wsLeft;
}
if (wsRight || wsRight === false) {
rightTrim = wsRight;
}
if (!rightTrim && !leftTrim) {
return str;
}
if (leftTrim === "slurp" && rightTrim === "slurp") {
return str.trim();
}
if (leftTrim === "_" || leftTrim === "slurp") {
// console.log('trimming left' + leftTrim)
// full slurp
str = trimLeft(str);
} else if (leftTrim === "-" || leftTrim === "nl") {
// nl trim
str = str.replace(/^(?:\r\n|\n|\r)/, "");
}
if (rightTrim === "_" || rightTrim === "slurp") {
// full slurp
str = trimRight(str);
} else if (rightTrim === "-" || rightTrim === "nl") {
// nl trim
str = str.replace(/(?:\r\n|\n|\r)$/, ""); // TODO: make sure this gets \r\n
}
return str;
}
/**
* A map of special HTML characters to their XML-escaped equivalents
*/
const escMap = {
"&": "&",
"<": "&lt;",
">": "&gt;",
'"': "&quot;",
"'": "&#39;"
};
function replaceChar(s) {
return escMap[s];
}
/**
* XML-escapes an input value after converting it to a string
*
* @param str - Input value (usually a string)
* @returns XML-escaped string
*/
function XMLEscape(str) {
// eslint-disable-line @typescript-eslint/no-explicit-any
// To deal with XSS. Based on Escape implementations of Mustache.JS and Marko, then customized.
const newStr = String(str);
if (/[&<>"']/.test(newStr)) {
return newStr.replace(/[&<>"']/g, replaceChar);
} else {
return newStr;
}
}
/* END TYPES */
const templateLitReg = /`(?:\\[\s\S]|\${(?:[^{}]|{(?:[^{}]|{[^}]*})*})*}|(?!\${)[^\\`])*`/g;
const singleQuoteReg = /'(?:\\[\s\w"'\\`]|[^\n\r'\\])*?'/g;
const doubleQuoteReg = /"(?:\\[\s\w"'\\`]|[^\n\r"\\])*?"/g;
/** Escape special regular expression characters inside a string */
function escapeRegExp(string) {
// From MDN
return string.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
}
function parse(str, config) {
let buffer = [];
let trimLeftOfNextStr = false;
let lastIndex = 0;
const parseOptions = config.parse;
if (config.plugins) {
for (let i = 0; i < config.plugins.length; i++) {
const plugin = config.plugins[i];
if (plugin.processTemplate) {
str = plugin.processTemplate(str, config);
}
}
}
/* Adding for EJS compatibility */
if (config.rmWhitespace) {
// Code taken directly from EJS
// Have to use two separate replaces here as `^` and `$` operators don't
// work well with `\r` and empty lines don't work well with the `m` flag.
// Essentially, this replaces the whitespace at the beginning and end of
// each line and removes multiple newlines.
str = str.replace(/[\r\n]+/g, "\n").replace(/^\s+|\s+$/gm, "");
}
/* End rmWhitespace option */
templateLitReg.lastIndex = 0;
singleQuoteReg.lastIndex = 0;
doubleQuoteReg.lastIndex = 0;
function pushString(strng, shouldTrimRightOfString) {
if (strng) {
// if string is truthy it must be of type 'string'
strng = trimWS(strng, config, trimLeftOfNextStr,
// this will only be false on the first str, the next ones will be null or undefined
shouldTrimRightOfString);
if (strng) {
// replace \ with \\, ' with \'
// we're going to convert all CRLF to LF so it doesn't take more than one replace
strng = strng.replace(/\\|'/g, "\\$&").replace(/\r\n|\n|\r/g, "\\n");
buffer.push(strng);
}
}
}
const prefixes = [parseOptions.exec, parseOptions.interpolate, parseOptions.raw].reduce(function (accumulator, prefix) {
if (accumulator && prefix) {
return accumulator + "|" + escapeRegExp(prefix);
} else if (prefix) {
// accumulator is falsy
return escapeRegExp(prefix);
} else {
// prefix and accumulator are both falsy
return accumulator;
}
}, "");
const parseOpenReg = new RegExp(escapeRegExp(config.tags[0]) + "(-|_)?\\s*(" + prefixes + ")?\\s*", "g");
const parseCloseReg = new RegExp("'|\"|`|\\/\\*|(\\s*(-|_)?" + escapeRegExp(config.tags[1]) + ")", "g");
// TODO: benchmark having the \s* on either side vs using str.trim()
let m;
while (m = parseOpenReg.exec(str)) {
const precedingString = str.slice(lastIndex, m.index);
lastIndex = m[0].length + m.index;
const wsLeft = m[1];
const prefix = m[2] || ""; // by default either ~, =, or empty
pushString(precedingString, wsLeft);
parseCloseReg.lastIndex = lastIndex;
let closeTag;
let currentObj = false;
while (closeTag = parseCloseReg.exec(str)) {
if (closeTag[1]) {
const content = str.slice(lastIndex, closeTag.index);
parseOpenReg.lastIndex = lastIndex = parseCloseReg.lastIndex;
trimLeftOfNextStr = closeTag[2];
const currentType = prefix === parseOptions.exec ? "e" : prefix === parseOptions.raw ? "r" : prefix === parseOptions.interpolate ? "i" : "";
currentObj = {
t: currentType,
val: content
};
break;
} else {
const char = closeTag[0];
if (char === "/*") {
const commentCloseInd = str.indexOf("*/", parseCloseReg.lastIndex);
if (commentCloseInd === -1) {
ParseErr("unclosed comment", str, closeTag.index);
}
parseCloseReg.lastIndex = commentCloseInd;
} else if (char === "'") {
singleQuoteReg.lastIndex = closeTag.index;
const singleQuoteMatch = singleQuoteReg.exec(str);
if (singleQuoteMatch) {
parseCloseReg.lastIndex = singleQuoteReg.lastIndex;
} else {
ParseErr("unclosed string", str, closeTag.index);
}
} else if (char === '"') {
doubleQuoteReg.lastIndex = closeTag.index;
const doubleQuoteMatch = doubleQuoteReg.exec(str);
if (doubleQuoteMatch) {
parseCloseReg.lastIndex = doubleQuoteReg.lastIndex;
} else {
ParseErr("unclosed string", str, closeTag.index);
}
} else if (char === "`") {
templateLitReg.lastIndex = closeTag.index;
const templateLitMatch = templateLitReg.exec(str);
if (templateLitMatch) {
parseCloseReg.lastIndex = templateLitReg.lastIndex;
} else {
ParseErr("unclosed string", str, closeTag.index);
}
}
}
}
if (currentObj) {
buffer.push(currentObj);
} else {
ParseErr("unclosed tag", str, m.index + precedingString.length);
}
}
pushString(str.slice(lastIndex, str.length), false);
if (config.plugins) {
for (let i = 0; i < config.plugins.length; i++) {
const plugin = config.plugins[i];
if (plugin.processAST) {
buffer = plugin.processAST(buffer, config);
}
}
}
return buffer;
}
/* END TYPES */
/**
* Compiles a template string to a function string. Most often users just use `compile()`, which calls `compileToString` and creates a new function using the result
*
* **Example**
*
* ```js
* compileToString("Hi <%= it.user %>", eta.config)
* // "var tR='',include=E.include.bind(E),includeFile=E.includeFile.bind(E);tR+='Hi ';tR+=E.e(it.user);if(cb){cb(null,tR)} return tR"
* ```
*/
function compileToString(str, config) {
const buffer = parse(str, config);
let res = "var tR='',__l,__lP" + (config.include ? ",include=E.include.bind(E)" : "") + (config.includeFile ? ",includeFile=E.includeFile.bind(E)" : "") + "\nfunction layout(p,d){__l=p;__lP=d}\n" + (config.useWith ? "with(" + config.varName + "||{}){" : "") + compileScope(buffer, config) + (config.includeFile ? "if(__l)tR=" + (config.async ? "await " : "") + `includeFile(__l,Object.assign(${config.varName},{body:tR},__lP))\n` : config.include ? "if(__l)tR=" + (config.async ? "await " : "") + `include(__l,Object.assign(${config.varName},{body:tR},__lP))\n` : "") + "if(cb){cb(null,tR)} return tR" + (config.useWith ? "}" : "");
if (config.plugins) {
for (let i = 0; i < config.plugins.length; i++) {
const plugin = config.plugins[i];
if (plugin.processFnString) {
res = plugin.processFnString(res, config);
}
}
}
return res;
}
/**
* Loops through the AST generated by `parse` and transform each item into JS calls
*
* **Example**
*
* ```js
* // AST version of 'Hi <%= it.user %>'
* let templateAST = ['Hi ', { val: 'it.user', t: 'i' }]
* compileScope(templateAST, eta.config)
* // "tR+='Hi ';tR+=E.e(it.user);"
* ```
*/
function compileScope(buff, config) {
let i = 0;
const buffLength = buff.length;
let returnStr = "";
for (i; i < buffLength; i++) {
const currentBlock = buff[i];
if (typeof currentBlock === "string") {
const str = currentBlock;
// we know string exists
returnStr += "tR+='" + str + "'\n";
} else {
const type = currentBlock.t; // ~, s, !, ?, r
let content = currentBlock.val || "";
if (type === "r") {
// raw
if (config.filter) {
content = "E.filter(" + content + ")";
}
returnStr += "tR+=" + content + "\n";
} else if (type === "i") {
// interpolate
if (config.filter) {
content = "E.filter(" + content + ")";
}
if (config.autoEscape) {
content = "E.e(" + content + ")";
}
returnStr += "tR+=" + content + "\n";
// reference
} else if (type === "e") {
// execute
returnStr += content + "\n"; // you need a \n in case you have <% } %>
}
}
}
return returnStr;
}
/**
* Handles storage and accessing of values
*
* In this case, we use it to store compiled template functions
* Indexed by their `name` or `filename`
*/
class Cacher {
constructor(cache) {
this.cache = void 0;
this.cache = cache;
}
define(key, val) {
this.cache[key] = val;
}
get(key) {
// string | array.
// TODO: allow array of keys to look down
// TODO: create plugin to allow referencing helpers, filters with dot notation
return this.cache[key];
}
remove(key) {
delete this.cache[key];
}
reset() {
this.cache = {};
}
load(cacheObj) {
copyProps(this.cache, cacheObj);
}
}
/* END TYPES */
/**
* Eta's template storage
*
* Stores partials and cached templates
*/
const templates = new Cacher({});
/* END TYPES */
/**
* Include a template based on its name (or filepath, if it's already been cached).
*
* Called like `include(templateNameOrPath, data)`
*/
function includeHelper(templateNameOrPath, data) {
const template = this.templates.get(templateNameOrPath);
if (!template) {
throw EtaErr('Could not fetch template "' + templateNameOrPath + '"');
}
return template(data, this);
}
/** Eta's base (global) configuration */
const config = {
async: false,
autoEscape: true,
autoTrim: [false, "nl"],
cache: false,
e: XMLEscape,
include: includeHelper,
parse: {
exec: "",
interpolate: "=",
raw: "~"
},
plugins: [],
rmWhitespace: false,
tags: ["<%", "%>"],
templates: templates,
useWith: false,
varName: "it"
};
/**
* Takes one or two partial (not necessarily complete) configuration objects, merges them 1 layer deep into eta.config, and returns the result
*
* @param override Partial configuration object
* @param baseConfig Partial configuration object to merge before `override`
*
* **Example**
*
* ```js
* let customConfig = getConfig({tags: ['!#', '#!']})
* ```
*/
function getConfig(override, baseConfig) {
// TODO: run more tests on this
const res = {}; // Linked
copyProps(res, config); // Creates deep clone of eta.config, 1 layer deep
if (baseConfig) {
copyProps(res, baseConfig);
}
if (override) {
copyProps(res, override);
}
return res;
}
/** Update Eta's base config */
function configure(options) {
return copyProps(config, options);
}
/* END TYPES */
/**
* Takes a template string and returns a template function that can be called with (data, config, [cb])
*
* @param str - The template string
* @param config - A custom configuration object (optional)
*
* **Example**
*
* ```js
* let compiledFn = eta.compile("Hi <%= it.user %>")
* // function anonymous()
* let compiledFnStr = compiledFn.toString()
* // "function anonymous(it,E,cb\n) {\nvar tR='',include=E.include.bind(E),includeFile=E.includeFile.bind(E);tR+='Hi ';tR+=E.e(it.user);if(cb){cb(null,tR)} return tR\n}"
* ```
*/
function compile(str, config) {
const options = getConfig(config || {});
/* ASYNC HANDLING */
// The below code is modified from mde/ejs. All credit should go to them.
const ctor = options.async ? getAsyncFunctionConstructor() : Function;
/* END ASYNC HANDLING */
try {
return new ctor(options.varName, "E",
// EtaConfig
"cb",
// optional callback
compileToString(str, options)); // eslint-disable-line no-new-func
} catch (e) {
if (e instanceof SyntaxError) {
throw EtaErr("Bad template syntax\n\n" + e.message + "\n" + Array(e.message.length + 1).join("=") + "\n" + compileToString(str, options) + "\n" // This will put an extra newline before the callstack for extra readability
);
} else {
throw e;
}
}
}
const _BOM = /^\uFEFF/;
/* END TYPES */
/**
* Get the path to the included file from the parent file path and the
* specified path.
*
* If `name` does not have an extension, it will default to `.eta`
*
* @param name specified path
* @param parentfile parent file path
* @param isDirectory whether parentfile is a directory
* @return absolute path to template
*/
function getWholeFilePath(name, parentfile, isDirectory) {
const includePath = path.resolve(isDirectory ? parentfile : path.dirname(parentfile),
// returns directory the parent file is in
name // file
) + (path.extname(name) ? "" : ".eta");
return includePath;
}
/**
* Get the absolute path to an included template
*
* If this is called with an absolute path (for example, starting with '/' or 'C:\')
* then Eta will attempt to resolve the absolute path within options.views. If it cannot,
* Eta will fallback to options.root or '/'
*
* If this is called with a relative path, Eta will:
* - Look relative to the current template (if the current template has the `filename` property)
* - Look inside each directory in options.views
*
* Note: if Eta is unable to find a template using path and options, it will throw an error.
*
* @param path specified path
* @param options compilation options
* @return absolute path to template
*/
function getPath(path, options) {
let includePath = false;
const views = options.views;
const searchedPaths = [];
// If these four values are the same,
// getPath() will return the same result every time.
// We can cache the result to avoid expensive
// file operations.
const pathOptions = JSON.stringify({
filename: options.filename,
path: path,
root: options.root,
views: options.views
});
if (options.cache && options.filepathCache && options.filepathCache[pathOptions]) {
// Use the cached filepath
return options.filepathCache[pathOptions];
}
/** Add a filepath to the list of paths we've checked for a template */
function addPathToSearched(pathSearched) {
if (!searchedPaths.includes(pathSearched)) {
searchedPaths.push(pathSearched);
}
}
/**
* Take a filepath (like 'partials/mypartial.eta'). Attempt to find the template file inside `views`;
* return the resulting template file path, or `false` to indicate that the template was not found.
*
* @param views the filepath that holds templates, or an array of filepaths that hold templates
* @param path the path to the template
*/
function searchViews(views, path) {
let filePath;
// If views is an array, then loop through each directory
// And attempt to find the template
if (Array.isArray(views) && views.some(function (v) {
filePath = getWholeFilePath(path, v, true);
addPathToSearched(filePath);
return existsSync(filePath);
})) {
// If the above returned true, we know that the filePath was just set to a path
// That exists (Array.some() returns as soon as it finds a valid element)
return filePath;
} else if (typeof views === "string") {
// Search for the file if views is a single directory
filePath = getWholeFilePath(path, views, true);
addPathToSearched(filePath);
if (existsSync(filePath)) {
return filePath;
}
}
// Unable to find a file
return false;
}
// Path starts with '/', 'C:\', etc.
const match = /^[A-Za-z]+:\\|^\//.exec(path);
// Absolute path, like /partials/partial.eta
if (match && match.length) {
// We have to trim the beginning '/' off the path, or else
// path.resolve(dir, path) will always resolve to just path
const formattedPath = path.replace(/^\/*/, "");
// First, try to resolve the path within options.views
includePath = searchViews(views, formattedPath);
if (!includePath) {
// If that fails, searchViews will return false. Try to find the path
// inside options.root (by default '/', the base of the filesystem)
const pathFromRoot = getWholeFilePath(formattedPath, options.root || "/", true);
addPathToSearched(pathFromRoot);
includePath = pathFromRoot;
}
} else {
// Relative paths
// Look relative to a passed filename first
if (options.filename) {
const filePath = getWholeFilePath(path, options.filename);
addPathToSearched(filePath);
if (existsSync(filePath)) {
includePath = filePath;
}
}
// Then look for the template in options.views
if (!includePath) {
includePath = searchViews(views, path);
}
if (!includePath) {
throw EtaErr('Could not find the template "' + path + '". Paths tried: ' + searchedPaths);
}
}
// If caching and filepathCache are enabled,
// cache the input & output of this function.
if (options.cache && options.filepathCache) {
options.filepathCache[pathOptions] = includePath;
}
return includePath;
}
/**
* Reads a file synchronously
*/
function readFile(filePath) {
try {
return readFileSync(filePath).toString().replace(_BOM, ""); // TODO: is replacing BOM's necessary?
} catch {
throw EtaErr("Failed to read template at '" + filePath + "'");
}
}
// express is set like: app.engine('html', require('eta').renderFile)
/* END TYPES */
/**
* Reads a template, compiles it into a function, caches it if caching isn't disabled, returns the function
*
* @param filePath Absolute path to template file
* @param options Eta configuration overrides
* @param noCache Optionally, make Eta not cache the template
*/
function loadFile(filePath, options, noCache) {
const config = getConfig(options);
const template = readFile(filePath);
try {
const compiledTemplate = compile(template, config);
if (!noCache) {
config.templates.define(config.filename, compiledTemplate);
}
return compiledTemplate;
} catch (e) {
throw EtaErr("Loading file: " + filePath + " failed:\n\n" + e.message);
}
}
/**
* Get the template from a string or a file, either compiled on-the-fly or
* read from cache (if enabled), and cache the template if needed.
*
* If `options.cache` is true, this function reads the file from
* `options.filename` so it must be set prior to calling this function.
*
* @param options compilation options
* @return Eta template function
*/
function handleCache$1(options) {
const filename = options.filename;
if (options.cache) {
const func = options.templates.get(filename);
if (func) {
return func;
}
return loadFile(filename, options);
}
// Caching is disabled, so pass noCache = true
return loadFile(filename, options, true);
}
/**
* Try calling handleCache with the given options and data and call the
* callback with the result. If an error occurs, call the callback with
* the error. Used by renderFile().
*
* @param data template data
* @param options compilation options
* @param cb callback
*/
function tryHandleCache(data, options, cb) {
if (cb) {
try {
// Note: if there is an error while rendering the template,
// It will bubble up and be caught here
const templateFn = handleCache$1(options);
templateFn(data, options, cb);
} catch (err) {
return cb(err);
}
} else {
// No callback, try returning a promise
if (typeof promiseImpl === "function") {
return new promiseImpl(function (resolve, reject) {
try {
const templateFn = handleCache$1(options);
const result = templateFn(data, options);
resolve(result);
} catch (err) {
reject(err);
}
});
} else {
throw EtaErr("Please provide a callback function, this env doesn't support Promises");
}
}
}
/**
* Get the template function.
*
* If `options.cache` is `true`, then the template is cached.
*
* This returns a template function and the config object with which that template function should be called.
*
* @remarks
*
* It's important that this returns a config object with `filename` set.
* Otherwise, the included file would not be able to use relative paths
*
* @param path path for the specified file (if relative, specify `views` on `options`)
* @param options compilation options
* @return [Eta template function, new config object]
*/
function includeFile(path, options) {
// the below creates a new options object, using the parent filepath of the old options object and the path
const newFileOptions = getConfig({
filename: getPath(path, options)
}, options);
// TODO: make sure properties are currectly copied over
return [handleCache$1(newFileOptions), newFileOptions];
}
function renderFile(filename, data, config, cb) {
/*
Here we have some function overloading.
Essentially, the first 2 arguments to renderFile should always be the filename and data
Express will call renderFile with (filename, data, cb)
We also want to make (filename, data, options, cb) available
*/
let renderConfig;
let callback;
data = data || {};
// First, assign our callback function to `callback`
// We can leave it undefined if neither parameter is a function;
// Callbacks are optional
if (typeof cb === "function") {
// The 4th argument is the callback
callback = cb;
} else if (typeof config === "function") {
// The 3rd arg is the callback
callback = config;
}
// If there is a config object passed in explicitly, use it
if (typeof config === "object") {
renderConfig = getConfig(config || {});
} else {
// Otherwise, get the default config
renderConfig = getConfig({});
}
// Set the filename option on the template
// This will first try to resolve the file path (see getPath for details)
renderConfig.filename = getPath(filename, renderConfig);
return tryHandleCache(data, renderConfig, callback);
}
function renderFileAsync(filename, data, config, cb) {
return renderFile(filename, typeof config === "function" ? {
...data,
async: true
} : data, typeof config === "object" ? {
...config,
async: true
} : config, cb);
}
/* END TYPES */
/**
* Called with `includeFile(path, data)`
*/
function includeFileHelper(path, data) {
const templateAndConfig = includeFile(path, this);
return templateAndConfig[0](data, templateAndConfig[1]);
}
/* END TYPES */
function handleCache(template, options) {
if (options.cache && options.name && options.templates.get(options.name)) {
return options.templates.get(options.name);
}
const templateFunc = typeof template === "function" ? template : compile(template, options);
// Note that we don't have to check if it already exists in the cache;
// it would have returned earlier if it had
if (options.cache && options.name) {
options.templates.define(options.name, templateFunc);
}
return templateFunc;
}
function render(template, data, config, cb) {
const options = getConfig(config || {});
if (options.async) {
if (cb) {
// If user passes callback
try {
// Note: if there is an error while rendering the template,
// It will bubble up and be caught here
const templateFn = handleCache(template, options);
templateFn(data, options, cb);
} catch (err) {
return cb(err);
}
} else {
// No callback, try returning a promise
if (typeof promiseImpl === "function") {
return new promiseImpl(function (resolve, reject) {
try {
resolve(handleCache(template, options)(data, options));
} catch (err) {
reject(err);
}
});
} else {
throw EtaErr("Please provide a callback function, this env doesn't support Promises");
}
}
} else {
return handleCache(template, options)(data, options);
}
}
function renderAsync(template, data, config, cb) {
// Using Object.assign to lower bundle size, using spread operator makes it larger because of typescript injected polyfills
return render(template, data, Object.assign({}, config, {
async: true
}), cb);
}
// @denoify-ignore
config.includeFile = includeFileHelper;
config.filepathCache = {};
export { renderFile as __express, compile, compileToString, config, configure, config as defaultConfig, getConfig, loadFile, parse, render, renderAsync, renderFile, renderFileAsync, templates };
//# sourceMappingURL=eta.module.mjs.map

1
node_modules/eta/dist/eta.module.mjs.map generated vendored Normal file

File diff suppressed because one or more lines are too long

926
node_modules/eta/dist/eta.umd.js generated vendored Normal file
View File

@@ -0,0 +1,926 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('fs'), require('path')) :
typeof define === 'function' && define.amd ? define(['exports', 'fs', 'path'], factory) :
(global = global || self, factory(global.eta = {}, global.fs, global.path));
})(this, (function (exports, fs, path) {
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n["default"] = e;
return n;
}
var path__namespace = /*#__PURE__*/_interopNamespace(path);
function setPrototypeOf(obj, proto) {
// eslint-disable-line @typescript-eslint/no-explicit-any
if (Object.setPrototypeOf) {
Object.setPrototypeOf(obj, proto);
} else {
obj.__proto__ = proto;
}
}
// This is pretty much the only way to get nice, extended Errors
// without using ES6
/**
* This returns a new Error with a custom prototype. Note that it's _not_ a constructor
*
* @param message Error message
*
* **Example**
*
* ```js
* throw EtaErr("template not found")
* ```
*/
function EtaErr(message) {
const err = new Error(message);
setPrototypeOf(err, EtaErr.prototype);
return err;
}
EtaErr.prototype = Object.create(Error.prototype, {
name: {
value: "Eta Error",
enumerable: false
}
});
/**
* Throws an EtaErr with a nicely formatted error and message showing where in the template the error occurred.
*/
function ParseErr(message, str, indx) {
const whitespace = str.slice(0, indx).split(/\n/);
const lineNo = whitespace.length;
const colNo = whitespace[lineNo - 1].length + 1;
message += " at line " + lineNo + " col " + colNo + ":\n\n" + " " + str.split(/\n/)[lineNo - 1] + "\n" + " " + Array(colNo).join(" ") + "^";
throw EtaErr(message);
}
/**
* @returns The global Promise function
*/
const promiseImpl = new Function("return this")().Promise;
/**
* @returns A new AsyncFunction constuctor
*/
function getAsyncFunctionConstructor() {
try {
return new Function("return (async function(){}).constructor")();
} catch (e) {
if (e instanceof SyntaxError) {
throw EtaErr("This environment doesn't support async/await");
} else {
throw e;
}
}
}
/**
* str.trimLeft polyfill
*
* @param str - Input string
* @returns The string with left whitespace removed
*
*/
function trimLeft(str) {
// eslint-disable-next-line no-extra-boolean-cast
if (!!String.prototype.trimLeft) {
return str.trimLeft();
} else {
return str.replace(/^\s+/, "");
}
}
/**
* str.trimRight polyfill
*
* @param str - Input string
* @returns The string with right whitespace removed
*
*/
function trimRight(str) {
// eslint-disable-next-line no-extra-boolean-cast
if (!!String.prototype.trimRight) {
return str.trimRight();
} else {
return str.replace(/\s+$/, ""); // TODO: do we really need to replace BOM's?
}
}
// TODO: allow '-' to trim up until newline. Use [^\S\n\r] instead of \s
/* END TYPES */
function hasOwnProp(obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
}
function copyProps(toObj, fromObj) {
for (const key in fromObj) {
if (hasOwnProp(fromObj, key)) {
toObj[key] = fromObj[key];
}
}
return toObj;
}
/**
* Takes a string within a template and trims it, based on the preceding tag's whitespace control and `config.autoTrim`
*/
function trimWS(str, config, wsLeft, wsRight) {
let leftTrim;
let rightTrim;
if (Array.isArray(config.autoTrim)) {
// kinda confusing
// but _}} will trim the left side of the following string
leftTrim = config.autoTrim[1];
rightTrim = config.autoTrim[0];
} else {
leftTrim = rightTrim = config.autoTrim;
}
if (wsLeft || wsLeft === false) {
leftTrim = wsLeft;
}
if (wsRight || wsRight === false) {
rightTrim = wsRight;
}
if (!rightTrim && !leftTrim) {
return str;
}
if (leftTrim === "slurp" && rightTrim === "slurp") {
return str.trim();
}
if (leftTrim === "_" || leftTrim === "slurp") {
// console.log('trimming left' + leftTrim)
// full slurp
str = trimLeft(str);
} else if (leftTrim === "-" || leftTrim === "nl") {
// nl trim
str = str.replace(/^(?:\r\n|\n|\r)/, "");
}
if (rightTrim === "_" || rightTrim === "slurp") {
// full slurp
str = trimRight(str);
} else if (rightTrim === "-" || rightTrim === "nl") {
// nl trim
str = str.replace(/(?:\r\n|\n|\r)$/, ""); // TODO: make sure this gets \r\n
}
return str;
}
/**
* A map of special HTML characters to their XML-escaped equivalents
*/
const escMap = {
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
'"': "&quot;",
"'": "&#39;"
};
function replaceChar(s) {
return escMap[s];
}
/**
* XML-escapes an input value after converting it to a string
*
* @param str - Input value (usually a string)
* @returns XML-escaped string
*/
function XMLEscape(str) {
// eslint-disable-line @typescript-eslint/no-explicit-any
// To deal with XSS. Based on Escape implementations of Mustache.JS and Marko, then customized.
const newStr = String(str);
if (/[&<>"']/.test(newStr)) {
return newStr.replace(/[&<>"']/g, replaceChar);
} else {
return newStr;
}
}
/* END TYPES */
const templateLitReg = /`(?:\\[\s\S]|\${(?:[^{}]|{(?:[^{}]|{[^}]*})*})*}|(?!\${)[^\\`])*`/g;
const singleQuoteReg = /'(?:\\[\s\w"'\\`]|[^\n\r'\\])*?'/g;
const doubleQuoteReg = /"(?:\\[\s\w"'\\`]|[^\n\r"\\])*?"/g;
/** Escape special regular expression characters inside a string */
function escapeRegExp(string) {
// From MDN
return string.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
}
function parse(str, config) {
let buffer = [];
let trimLeftOfNextStr = false;
let lastIndex = 0;
const parseOptions = config.parse;
if (config.plugins) {
for (let i = 0; i < config.plugins.length; i++) {
const plugin = config.plugins[i];
if (plugin.processTemplate) {
str = plugin.processTemplate(str, config);
}
}
}
/* Adding for EJS compatibility */
if (config.rmWhitespace) {
// Code taken directly from EJS
// Have to use two separate replaces here as `^` and `$` operators don't
// work well with `\r` and empty lines don't work well with the `m` flag.
// Essentially, this replaces the whitespace at the beginning and end of
// each line and removes multiple newlines.
str = str.replace(/[\r\n]+/g, "\n").replace(/^\s+|\s+$/gm, "");
}
/* End rmWhitespace option */
templateLitReg.lastIndex = 0;
singleQuoteReg.lastIndex = 0;
doubleQuoteReg.lastIndex = 0;
function pushString(strng, shouldTrimRightOfString) {
if (strng) {
// if string is truthy it must be of type 'string'
strng = trimWS(strng, config, trimLeftOfNextStr,
// this will only be false on the first str, the next ones will be null or undefined
shouldTrimRightOfString);
if (strng) {
// replace \ with \\, ' with \'
// we're going to convert all CRLF to LF so it doesn't take more than one replace
strng = strng.replace(/\\|'/g, "\\$&").replace(/\r\n|\n|\r/g, "\\n");
buffer.push(strng);
}
}
}
const prefixes = [parseOptions.exec, parseOptions.interpolate, parseOptions.raw].reduce(function (accumulator, prefix) {
if (accumulator && prefix) {
return accumulator + "|" + escapeRegExp(prefix);
} else if (prefix) {
// accumulator is falsy
return escapeRegExp(prefix);
} else {
// prefix and accumulator are both falsy
return accumulator;
}
}, "");
const parseOpenReg = new RegExp(escapeRegExp(config.tags[0]) + "(-|_)?\\s*(" + prefixes + ")?\\s*", "g");
const parseCloseReg = new RegExp("'|\"|`|\\/\\*|(\\s*(-|_)?" + escapeRegExp(config.tags[1]) + ")", "g");
// TODO: benchmark having the \s* on either side vs using str.trim()
let m;
while (m = parseOpenReg.exec(str)) {
const precedingString = str.slice(lastIndex, m.index);
lastIndex = m[0].length + m.index;
const wsLeft = m[1];
const prefix = m[2] || ""; // by default either ~, =, or empty
pushString(precedingString, wsLeft);
parseCloseReg.lastIndex = lastIndex;
let closeTag;
let currentObj = false;
while (closeTag = parseCloseReg.exec(str)) {
if (closeTag[1]) {
const content = str.slice(lastIndex, closeTag.index);
parseOpenReg.lastIndex = lastIndex = parseCloseReg.lastIndex;
trimLeftOfNextStr = closeTag[2];
const currentType = prefix === parseOptions.exec ? "e" : prefix === parseOptions.raw ? "r" : prefix === parseOptions.interpolate ? "i" : "";
currentObj = {
t: currentType,
val: content
};
break;
} else {
const char = closeTag[0];
if (char === "/*") {
const commentCloseInd = str.indexOf("*/", parseCloseReg.lastIndex);
if (commentCloseInd === -1) {
ParseErr("unclosed comment", str, closeTag.index);
}
parseCloseReg.lastIndex = commentCloseInd;
} else if (char === "'") {
singleQuoteReg.lastIndex = closeTag.index;
const singleQuoteMatch = singleQuoteReg.exec(str);
if (singleQuoteMatch) {
parseCloseReg.lastIndex = singleQuoteReg.lastIndex;
} else {
ParseErr("unclosed string", str, closeTag.index);
}
} else if (char === '"') {
doubleQuoteReg.lastIndex = closeTag.index;
const doubleQuoteMatch = doubleQuoteReg.exec(str);
if (doubleQuoteMatch) {
parseCloseReg.lastIndex = doubleQuoteReg.lastIndex;
} else {
ParseErr("unclosed string", str, closeTag.index);
}
} else if (char === "`") {
templateLitReg.lastIndex = closeTag.index;
const templateLitMatch = templateLitReg.exec(str);
if (templateLitMatch) {
parseCloseReg.lastIndex = templateLitReg.lastIndex;
} else {
ParseErr("unclosed string", str, closeTag.index);
}
}
}
}
if (currentObj) {
buffer.push(currentObj);
} else {
ParseErr("unclosed tag", str, m.index + precedingString.length);
}
}
pushString(str.slice(lastIndex, str.length), false);
if (config.plugins) {
for (let i = 0; i < config.plugins.length; i++) {
const plugin = config.plugins[i];
if (plugin.processAST) {
buffer = plugin.processAST(buffer, config);
}
}
}
return buffer;
}
/* END TYPES */
/**
* Compiles a template string to a function string. Most often users just use `compile()`, which calls `compileToString` and creates a new function using the result
*
* **Example**
*
* ```js
* compileToString("Hi <%= it.user %>", eta.config)
* // "var tR='',include=E.include.bind(E),includeFile=E.includeFile.bind(E);tR+='Hi ';tR+=E.e(it.user);if(cb){cb(null,tR)} return tR"
* ```
*/
function compileToString(str, config) {
const buffer = parse(str, config);
let res = "var tR='',__l,__lP" + (config.include ? ",include=E.include.bind(E)" : "") + (config.includeFile ? ",includeFile=E.includeFile.bind(E)" : "") + "\nfunction layout(p,d){__l=p;__lP=d}\n" + (config.useWith ? "with(" + config.varName + "||{}){" : "") + compileScope(buffer, config) + (config.includeFile ? "if(__l)tR=" + (config.async ? "await " : "") + `includeFile(__l,Object.assign(${config.varName},{body:tR},__lP))\n` : config.include ? "if(__l)tR=" + (config.async ? "await " : "") + `include(__l,Object.assign(${config.varName},{body:tR},__lP))\n` : "") + "if(cb){cb(null,tR)} return tR" + (config.useWith ? "}" : "");
if (config.plugins) {
for (let i = 0; i < config.plugins.length; i++) {
const plugin = config.plugins[i];
if (plugin.processFnString) {
res = plugin.processFnString(res, config);
}
}
}
return res;
}
/**
* Loops through the AST generated by `parse` and transform each item into JS calls
*
* **Example**
*
* ```js
* // AST version of 'Hi <%= it.user %>'
* let templateAST = ['Hi ', { val: 'it.user', t: 'i' }]
* compileScope(templateAST, eta.config)
* // "tR+='Hi ';tR+=E.e(it.user);"
* ```
*/
function compileScope(buff, config) {
let i = 0;
const buffLength = buff.length;
let returnStr = "";
for (i; i < buffLength; i++) {
const currentBlock = buff[i];
if (typeof currentBlock === "string") {
const str = currentBlock;
// we know string exists
returnStr += "tR+='" + str + "'\n";
} else {
const type = currentBlock.t; // ~, s, !, ?, r
let content = currentBlock.val || "";
if (type === "r") {
// raw
if (config.filter) {
content = "E.filter(" + content + ")";
}
returnStr += "tR+=" + content + "\n";
} else if (type === "i") {
// interpolate
if (config.filter) {
content = "E.filter(" + content + ")";
}
if (config.autoEscape) {
content = "E.e(" + content + ")";
}
returnStr += "tR+=" + content + "\n";
// reference
} else if (type === "e") {
// execute
returnStr += content + "\n"; // you need a \n in case you have <% } %>
}
}
}
return returnStr;
}
/**
* Handles storage and accessing of values
*
* In this case, we use it to store compiled template functions
* Indexed by their `name` or `filename`
*/
class Cacher {
constructor(cache) {
this.cache = void 0;
this.cache = cache;
}
define(key, val) {
this.cache[key] = val;
}
get(key) {
// string | array.
// TODO: allow array of keys to look down
// TODO: create plugin to allow referencing helpers, filters with dot notation
return this.cache[key];
}
remove(key) {
delete this.cache[key];
}
reset() {
this.cache = {};
}
load(cacheObj) {
copyProps(this.cache, cacheObj);
}
}
/* END TYPES */
/**
* Eta's template storage
*
* Stores partials and cached templates
*/
const templates = new Cacher({});
/* END TYPES */
/**
* Include a template based on its name (or filepath, if it's already been cached).
*
* Called like `include(templateNameOrPath, data)`
*/
function includeHelper(templateNameOrPath, data) {
const template = this.templates.get(templateNameOrPath);
if (!template) {
throw EtaErr('Could not fetch template "' + templateNameOrPath + '"');
}
return template(data, this);
}
/** Eta's base (global) configuration */
const config = {
async: false,
autoEscape: true,
autoTrim: [false, "nl"],
cache: false,
e: XMLEscape,
include: includeHelper,
parse: {
exec: "",
interpolate: "=",
raw: "~"
},
plugins: [],
rmWhitespace: false,
tags: ["<%", "%>"],
templates: templates,
useWith: false,
varName: "it"
};
/**
* Takes one or two partial (not necessarily complete) configuration objects, merges them 1 layer deep into eta.config, and returns the result
*
* @param override Partial configuration object
* @param baseConfig Partial configuration object to merge before `override`
*
* **Example**
*
* ```js
* let customConfig = getConfig({tags: ['!#', '#!']})
* ```
*/
function getConfig(override, baseConfig) {
// TODO: run more tests on this
const res = {}; // Linked
copyProps(res, config); // Creates deep clone of eta.config, 1 layer deep
if (baseConfig) {
copyProps(res, baseConfig);
}
if (override) {
copyProps(res, override);
}
return res;
}
/** Update Eta's base config */
function configure(options) {
return copyProps(config, options);
}
/* END TYPES */
/**
* Takes a template string and returns a template function that can be called with (data, config, [cb])
*
* @param str - The template string
* @param config - A custom configuration object (optional)
*
* **Example**
*
* ```js
* let compiledFn = eta.compile("Hi <%= it.user %>")
* // function anonymous()
* let compiledFnStr = compiledFn.toString()
* // "function anonymous(it,E,cb\n) {\nvar tR='',include=E.include.bind(E),includeFile=E.includeFile.bind(E);tR+='Hi ';tR+=E.e(it.user);if(cb){cb(null,tR)} return tR\n}"
* ```
*/
function compile(str, config) {
const options = getConfig(config || {});
/* ASYNC HANDLING */
// The below code is modified from mde/ejs. All credit should go to them.
const ctor = options.async ? getAsyncFunctionConstructor() : Function;
/* END ASYNC HANDLING */
try {
return new ctor(options.varName, "E",
// EtaConfig
"cb",
// optional callback
compileToString(str, options)); // eslint-disable-line no-new-func
} catch (e) {
if (e instanceof SyntaxError) {
throw EtaErr("Bad template syntax\n\n" + e.message + "\n" + Array(e.message.length + 1).join("=") + "\n" + compileToString(str, options) + "\n" // This will put an extra newline before the callstack for extra readability
);
} else {
throw e;
}
}
}
const _BOM = /^\uFEFF/;
/* END TYPES */
/**
* Get the path to the included file from the parent file path and the
* specified path.
*
* If `name` does not have an extension, it will default to `.eta`
*
* @param name specified path
* @param parentfile parent file path
* @param isDirectory whether parentfile is a directory
* @return absolute path to template
*/
function getWholeFilePath(name, parentfile, isDirectory) {
const includePath = path__namespace.resolve(isDirectory ? parentfile : path__namespace.dirname(parentfile),
// returns directory the parent file is in
name // file
) + (path__namespace.extname(name) ? "" : ".eta");
return includePath;
}
/**
* Get the absolute path to an included template
*
* If this is called with an absolute path (for example, starting with '/' or 'C:\')
* then Eta will attempt to resolve the absolute path within options.views. If it cannot,
* Eta will fallback to options.root or '/'
*
* If this is called with a relative path, Eta will:
* - Look relative to the current template (if the current template has the `filename` property)
* - Look inside each directory in options.views
*
* Note: if Eta is unable to find a template using path and options, it will throw an error.
*
* @param path specified path
* @param options compilation options
* @return absolute path to template
*/
function getPath(path, options) {
let includePath = false;
const views = options.views;
const searchedPaths = [];
// If these four values are the same,
// getPath() will return the same result every time.
// We can cache the result to avoid expensive
// file operations.
const pathOptions = JSON.stringify({
filename: options.filename,
path: path,
root: options.root,
views: options.views
});
if (options.cache && options.filepathCache && options.filepathCache[pathOptions]) {
// Use the cached filepath
return options.filepathCache[pathOptions];
}
/** Add a filepath to the list of paths we've checked for a template */
function addPathToSearched(pathSearched) {
if (!searchedPaths.includes(pathSearched)) {
searchedPaths.push(pathSearched);
}
}
/**
* Take a filepath (like 'partials/mypartial.eta'). Attempt to find the template file inside `views`;
* return the resulting template file path, or `false` to indicate that the template was not found.
*
* @param views the filepath that holds templates, or an array of filepaths that hold templates
* @param path the path to the template
*/
function searchViews(views, path) {
let filePath;
// If views is an array, then loop through each directory
// And attempt to find the template
if (Array.isArray(views) && views.some(function (v) {
filePath = getWholeFilePath(path, v, true);
addPathToSearched(filePath);
return fs.existsSync(filePath);
})) {
// If the above returned true, we know that the filePath was just set to a path
// That exists (Array.some() returns as soon as it finds a valid element)
return filePath;
} else if (typeof views === "string") {
// Search for the file if views is a single directory
filePath = getWholeFilePath(path, views, true);
addPathToSearched(filePath);
if (fs.existsSync(filePath)) {
return filePath;
}
}
// Unable to find a file
return false;
}
// Path starts with '/', 'C:\', etc.
const match = /^[A-Za-z]+:\\|^\//.exec(path);
// Absolute path, like /partials/partial.eta
if (match && match.length) {
// We have to trim the beginning '/' off the path, or else
// path.resolve(dir, path) will always resolve to just path
const formattedPath = path.replace(/^\/*/, "");
// First, try to resolve the path within options.views
includePath = searchViews(views, formattedPath);
if (!includePath) {
// If that fails, searchViews will return false. Try to find the path
// inside options.root (by default '/', the base of the filesystem)
const pathFromRoot = getWholeFilePath(formattedPath, options.root || "/", true);
addPathToSearched(pathFromRoot);
includePath = pathFromRoot;
}
} else {
// Relative paths
// Look relative to a passed filename first
if (options.filename) {
const filePath = getWholeFilePath(path, options.filename);
addPathToSearched(filePath);
if (fs.existsSync(filePath)) {
includePath = filePath;
}
}
// Then look for the template in options.views
if (!includePath) {
includePath = searchViews(views, path);
}
if (!includePath) {
throw EtaErr('Could not find the template "' + path + '". Paths tried: ' + searchedPaths);
}
}
// If caching and filepathCache are enabled,
// cache the input & output of this function.
if (options.cache && options.filepathCache) {
options.filepathCache[pathOptions] = includePath;
}
return includePath;
}
/**
* Reads a file synchronously
*/
function readFile(filePath) {
try {
return fs.readFileSync(filePath).toString().replace(_BOM, ""); // TODO: is replacing BOM's necessary?
} catch {
throw EtaErr("Failed to read template at '" + filePath + "'");
}
}
// express is set like: app.engine('html', require('eta').renderFile)
/* END TYPES */
/**
* Reads a template, compiles it into a function, caches it if caching isn't disabled, returns the function
*
* @param filePath Absolute path to template file
* @param options Eta configuration overrides
* @param noCache Optionally, make Eta not cache the template
*/
function loadFile(filePath, options, noCache) {
const config = getConfig(options);
const template = readFile(filePath);
try {
const compiledTemplate = compile(template, config);
if (!noCache) {
config.templates.define(config.filename, compiledTemplate);
}
return compiledTemplate;
} catch (e) {
throw EtaErr("Loading file: " + filePath + " failed:\n\n" + e.message);
}
}
/**
* Get the template from a string or a file, either compiled on-the-fly or
* read from cache (if enabled), and cache the template if needed.
*
* If `options.cache` is true, this function reads the file from
* `options.filename` so it must be set prior to calling this function.
*
* @param options compilation options
* @return Eta template function
*/
function handleCache$1(options) {
const filename = options.filename;
if (options.cache) {
const func = options.templates.get(filename);
if (func) {
return func;
}
return loadFile(filename, options);
}
// Caching is disabled, so pass noCache = true
return loadFile(filename, options, true);
}
/**
* Try calling handleCache with the given options and data and call the
* callback with the result. If an error occurs, call the callback with
* the error. Used by renderFile().
*
* @param data template data
* @param options compilation options
* @param cb callback
*/
function tryHandleCache(data, options, cb) {
if (cb) {
try {
// Note: if there is an error while rendering the template,
// It will bubble up and be caught here
const templateFn = handleCache$1(options);
templateFn(data, options, cb);
} catch (err) {
return cb(err);
}
} else {
// No callback, try returning a promise
if (typeof promiseImpl === "function") {
return new promiseImpl(function (resolve, reject) {
try {
const templateFn = handleCache$1(options);
const result = templateFn(data, options);
resolve(result);
} catch (err) {
reject(err);
}
});
} else {
throw EtaErr("Please provide a callback function, this env doesn't support Promises");
}
}
}
/**
* Get the template function.
*
* If `options.cache` is `true`, then the template is cached.
*
* This returns a template function and the config object with which that template function should be called.
*
* @remarks
*
* It's important that this returns a config object with `filename` set.
* Otherwise, the included file would not be able to use relative paths
*
* @param path path for the specified file (if relative, specify `views` on `options`)
* @param options compilation options
* @return [Eta template function, new config object]
*/
function includeFile(path, options) {
// the below creates a new options object, using the parent filepath of the old options object and the path
const newFileOptions = getConfig({
filename: getPath(path, options)
}, options);
// TODO: make sure properties are currectly copied over
return [handleCache$1(newFileOptions), newFileOptions];
}
function renderFile(filename, data, config, cb) {
/*
Here we have some function overloading.
Essentially, the first 2 arguments to renderFile should always be the filename and data
Express will call renderFile with (filename, data, cb)
We also want to make (filename, data, options, cb) available
*/
let renderConfig;
let callback;
data = data || {};
// First, assign our callback function to `callback`
// We can leave it undefined if neither parameter is a function;
// Callbacks are optional
if (typeof cb === "function") {
// The 4th argument is the callback
callback = cb;
} else if (typeof config === "function") {
// The 3rd arg is the callback
callback = config;
}
// If there is a config object passed in explicitly, use it
if (typeof config === "object") {
renderConfig = getConfig(config || {});
} else {
// Otherwise, get the default config
renderConfig = getConfig({});
}
// Set the filename option on the template
// This will first try to resolve the file path (see getPath for details)
renderConfig.filename = getPath(filename, renderConfig);
return tryHandleCache(data, renderConfig, callback);
}
function renderFileAsync(filename, data, config, cb) {
return renderFile(filename, typeof config === "function" ? {
...data,
async: true
} : data, typeof config === "object" ? {
...config,
async: true
} : config, cb);
}
/* END TYPES */
/**
* Called with `includeFile(path, data)`
*/
function includeFileHelper(path, data) {
const templateAndConfig = includeFile(path, this);
return templateAndConfig[0](data, templateAndConfig[1]);
}
/* END TYPES */
function handleCache(template, options) {
if (options.cache && options.name && options.templates.get(options.name)) {
return options.templates.get(options.name);
}
const templateFunc = typeof template === "function" ? template : compile(template, options);
// Note that we don't have to check if it already exists in the cache;
// it would have returned earlier if it had
if (options.cache && options.name) {
options.templates.define(options.name, templateFunc);
}
return templateFunc;
}
function render(template, data, config, cb) {
const options = getConfig(config || {});
if (options.async) {
if (cb) {
// If user passes callback
try {
// Note: if there is an error while rendering the template,
// It will bubble up and be caught here
const templateFn = handleCache(template, options);
templateFn(data, options, cb);
} catch (err) {
return cb(err);
}
} else {
// No callback, try returning a promise
if (typeof promiseImpl === "function") {
return new promiseImpl(function (resolve, reject) {
try {
resolve(handleCache(template, options)(data, options));
} catch (err) {
reject(err);
}
});
} else {
throw EtaErr("Please provide a callback function, this env doesn't support Promises");
}
}
} else {
return handleCache(template, options)(data, options);
}
}
function renderAsync(template, data, config, cb) {
// Using Object.assign to lower bundle size, using spread operator makes it larger because of typescript injected polyfills
return render(template, data, Object.assign({}, config, {
async: true
}), cb);
}
// @denoify-ignore
config.includeFile = includeFileHelper;
config.filepathCache = {};
exports.__express = renderFile;
exports.compile = compile;
exports.compileToString = compileToString;
exports.config = config;
exports.configure = configure;
exports.defaultConfig = config;
exports.getConfig = getConfig;
exports.loadFile = loadFile;
exports.parse = parse;
exports.render = render;
exports.renderAsync = renderAsync;
exports.renderFile = renderFile;
exports.renderFileAsync = renderFileAsync;
exports.templates = templates;
}));
//# sourceMappingURL=eta.umd.js.map

1
node_modules/eta/dist/eta.umd.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

7
node_modules/eta/dist/types/browser.d.ts generated vendored Normal file
View File

@@ -0,0 +1,7 @@
export { default as compileToString } from "./compile-string.js";
export { default as compile } from "./compile.js";
export { default as parse } from "./parse.js";
export { default as render, renderAsync } from "./render.js";
export { templates } from "./containers.js";
export { config, config as defaultConfig, getConfig, configure } from "./config.js";
//# sourceMappingURL=browser.d.ts.map

1
node_modules/eta/dist/types/browser.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,aAAa,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}

13
node_modules/eta/dist/types/compile-string.d.ts generated vendored Normal file
View File

@@ -0,0 +1,13 @@
import type { EtaConfig } from "./config.js";
/**
* Compiles a template string to a function string. Most often users just use `compile()`, which calls `compileToString` and creates a new function using the result
*
* **Example**
*
* ```js
* compileToString("Hi <%= it.user %>", eta.config)
* // "var tR='',include=E.include.bind(E),includeFile=E.includeFile.bind(E);tR+='Hi ';tR+=E.e(it.user);if(cb){cb(null,tR)} return tR"
* ```
*/
export default function compileToString(str: string, config: EtaConfig): string;
//# sourceMappingURL=compile-string.d.ts.map

1
node_modules/eta/dist/types/compile-string.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"compile-string.d.ts","sourceRoot":"","sources":["../../src/compile-string.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAK7C;;;;;;;;;GASG;AAEH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,MAAM,CAgC9E"}

20
node_modules/eta/dist/types/compile.d.ts generated vendored Normal file
View File

@@ -0,0 +1,20 @@
import type { EtaConfig, PartialConfig } from "./config.js";
import type { CallbackFn } from "./file-handlers.js";
export type TemplateFunction = (data: object, config: EtaConfig, cb?: CallbackFn) => string;
/**
* Takes a template string and returns a template function that can be called with (data, config, [cb])
*
* @param str - The template string
* @param config - A custom configuration object (optional)
*
* **Example**
*
* ```js
* let compiledFn = eta.compile("Hi <%= it.user %>")
* // function anonymous()
* let compiledFnStr = compiledFn.toString()
* // "function anonymous(it,E,cb\n) {\nvar tR='',include=E.include.bind(E),includeFile=E.includeFile.bind(E);tR+='Hi ';tR+=E.e(it.user);if(cb){cb(null,tR)} return tR\n}"
* ```
*/
export default function compile(str: string, config?: PartialConfig): TemplateFunction;
//# sourceMappingURL=compile.d.ts.map

1
node_modules/eta/dist/types/compile.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/compile.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,MAAM,MAAM,gBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,CAAC,EAAE,UAAU,KAAK,MAAM,CAAC;AAI5F;;;;;;;;;;;;;;GAcG;AAEH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,aAAa,GAAG,gBAAgB,CA8BrF"}

85
node_modules/eta/dist/types/config.d.ts generated vendored Normal file
View File

@@ -0,0 +1,85 @@
import type { TemplateFunction } from "./compile.js";
import type { Cacher } from "./storage.js";
type trimConfig = "nl" | "slurp" | false;
export interface EtaConfig {
/** Whether or not to automatically XML-escape interpolations. Default true */
autoEscape: boolean;
/** Configure automatic whitespace trimming. Default `[false, 'nl']` */
autoTrim: trimConfig | [trimConfig, trimConfig];
/** Compile to async function */
async: boolean;
/** Whether or not to cache templates if `name` or `filename` is passed */
cache: boolean;
/** XML-escaping function */
e: (str: string) => string;
/** Parsing options. NOTE: "-" and "_" may not be used, since they are reserved for whitespace trimming. */
parse: {
/** Which prefix to use for evaluation. Default `""` */
exec: string;
/** Which prefix to use for interpolation. Default `"="` */
interpolate: string;
/** Which prefix to use for raw interpolation. Default `"~"` */
raw: string;
};
/** Array of plugins */
plugins: Array<{
processFnString?: Function;
processAST?: Function;
processTemplate?: Function;
}>;
/** Remove all safe-to-remove whitespace */
rmWhitespace: boolean;
/** Delimiters: by default `['<%', '%>']` */
tags: [string, string];
/** Holds template cache */
templates: Cacher<TemplateFunction>;
/** Name of the data object. Default `it` */
varName: string;
/** Absolute path to template file */
filename?: string;
/** Holds cache of resolved filepaths. Set to `false` to disable */
filepathCache?: Record<string, string> | false;
/** A filter function applied to every interpolation or raw interpolation */
filter?: Function;
/** Function to include templates by name */
include?: Function;
/** Function to include templates by filepath */
includeFile?: Function;
/** Name of template */
name?: string;
/** Where should absolute paths begin? Default '/' */
root?: string;
/** Make data available on the global object instead of varName */
useWith?: boolean;
/** Whether or not to cache templates if `name` or `filename` is passed: duplicate of `cache` */
"view cache"?: boolean;
/** Directory or directories that contain templates */
views?: string | Array<string>;
[index: string]: any;
}
export interface EtaConfigWithFilename extends EtaConfig {
filename: string;
}
export type PartialConfig = Partial<EtaConfig>;
export type PartialAsyncConfig = PartialConfig & {
async: true;
};
/** Eta's base (global) configuration */
declare const config: EtaConfig;
/**
* Takes one or two partial (not necessarily complete) configuration objects, merges them 1 layer deep into eta.config, and returns the result
*
* @param override Partial configuration object
* @param baseConfig Partial configuration object to merge before `override`
*
* **Example**
*
* ```js
* let customConfig = getConfig({tags: ['!#', '#!']})
* ```
*/
declare function getConfig(override: PartialConfig, baseConfig?: EtaConfig): EtaConfig;
/** Update Eta's base config */
declare function configure(options: PartialConfig): Partial<EtaConfig>;
export { config, getConfig, configure };
//# sourceMappingURL=config.d.ts.map

1
node_modules/eta/dist/types/config.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C,KAAK,UAAU,GAAG,IAAI,GAAG,OAAO,GAAG,KAAK,CAAC;AAEzC,MAAM,WAAW,SAAS;IACxB,8EAA8E;IAC9E,UAAU,EAAE,OAAO,CAAC;IAEpB,uEAAuE;IACvE,QAAQ,EAAE,UAAU,GAAG,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAEhD,gCAAgC;IAChC,KAAK,EAAE,OAAO,CAAC;IAEf,0EAA0E;IAC1E,KAAK,EAAE,OAAO,CAAC;IAEf,4BAA4B;IAC5B,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;IAE3B,2GAA2G;IAC3G,KAAK,EAAE;QACL,uDAAuD;QACvD,IAAI,EAAE,MAAM,CAAC;QAEb,2DAA2D;QAC3D,WAAW,EAAE,MAAM,CAAC;QAEpB,+DAA+D;QAC/D,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;IAEF,uBAAuB;IACvB,OAAO,EAAE,KAAK,CAAC;QAAE,eAAe,CAAC,EAAE,QAAQ,CAAC;QAAC,UAAU,CAAC,EAAE,QAAQ,CAAC;QAAC,eAAe,CAAC,EAAE,QAAQ,CAAA;KAAE,CAAC,CAAC;IAElG,2CAA2C;IAC3C,YAAY,EAAE,OAAO,CAAC;IAEtB,4CAA4C;IAC5C,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEvB,2BAA2B;IAC3B,SAAS,EAAE,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAEpC,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC;IAEhB,qCAAqC;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,mEAAmE;IACnE,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC;IAE/C,4EAA4E;IAC5E,MAAM,CAAC,EAAE,QAAQ,CAAC;IAElB,4CAA4C;IAC5C,OAAO,CAAC,EAAE,QAAQ,CAAC;IAEnB,gDAAgD;IAChD,WAAW,CAAC,EAAE,QAAQ,CAAC;IAEvB,uBAAuB;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,qDAAqD;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,kEAAkE;IAClE,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,gGAAgG;IAChG,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB,sDAAsD;IACtD,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;IAE/B,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB;AAED,MAAM,WAAW,qBAAsB,SAAQ,SAAS;IACtD,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AAC/C,MAAM,MAAM,kBAAkB,GAAG,aAAa,GAAG;IAAE,KAAK,EAAE,IAAI,CAAA;CAAE,CAAC;AAkBjE,wCAAwC;AACxC,QAAA,MAAM,MAAM,EAAE,SAkBb,CAAC;AAEF;;;;;;;;;;;GAWG;AAEH,iBAAS,SAAS,CAAC,QAAQ,EAAE,aAAa,EAAE,UAAU,CAAC,EAAE,SAAS,GAAG,SAAS,CAe7E;AAED,+BAA+B;AAE/B,iBAAS,SAAS,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,SAAS,CAAC,CAE7D;AAED,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC"}

10
node_modules/eta/dist/types/containers.d.ts generated vendored Normal file
View File

@@ -0,0 +1,10 @@
import { Cacher } from "./storage.js";
import type { TemplateFunction } from "./compile.js";
/**
* Eta's template storage
*
* Stores partials and cached templates
*/
declare const templates: Cacher<TemplateFunction>;
export { templates };
//# sourceMappingURL=containers.d.ts.map

1
node_modules/eta/dist/types/containers.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"containers.d.ts","sourceRoot":"","sources":["../../src/containers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAItC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAIrD;;;;GAIG;AAEH,QAAA,MAAM,SAAS,0BAAmC,CAAC;AAEnD,OAAO,EAAE,SAAS,EAAE,CAAC"}

21
node_modules/eta/dist/types/err.d.ts generated vendored Normal file
View File

@@ -0,0 +1,21 @@
/**
* This returns a new Error with a custom prototype. Note that it's _not_ a constructor
*
* @param message Error message
*
* **Example**
*
* ```js
* throw EtaErr("template not found")
* ```
*/
declare function EtaErr(message: string): Error;
declare namespace EtaErr {
var prototype: any;
}
export default EtaErr;
/**
* Throws an EtaErr with a nicely formatted error and message showing where in the template the error occurred.
*/
export declare function ParseErr(message: string, str: string, indx: number): void;
//# sourceMappingURL=err.d.ts.map

1
node_modules/eta/dist/types/err.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"err.d.ts","sourceRoot":"","sources":["../../src/err.ts"],"names":[],"mappings":"AAYA;;;;;;;;;;GAUG;AAEH,iBAAwB,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAIrD;kBAJuB,MAAM;;;eAAN,MAAM;AAU9B;;GAEG;AAEH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAkBzE"}

92
node_modules/eta/dist/types/file-handlers.d.ts generated vendored Normal file
View File

@@ -0,0 +1,92 @@
import type { EtaConfig, PartialConfig } from "./config.js";
import type { TemplateFunction } from "./compile.js";
export type CallbackFn = (err: Error | null, str?: string) => void;
interface DataObj {
[key: string]: any;
}
interface PartialConfigWithFilename extends Partial<EtaConfig> {
filename: string;
}
/**
* Reads a template, compiles it into a function, caches it if caching isn't disabled, returns the function
*
* @param filePath Absolute path to template file
* @param options Eta configuration overrides
* @param noCache Optionally, make Eta not cache the template
*/
export declare function loadFile(filePath: string, options: PartialConfigWithFilename, noCache?: boolean): TemplateFunction;
/**
* Get the template function.
*
* If `options.cache` is `true`, then the template is cached.
*
* This returns a template function and the config object with which that template function should be called.
*
* @remarks
*
* It's important that this returns a config object with `filename` set.
* Otherwise, the included file would not be able to use relative paths
*
* @param path path for the specified file (if relative, specify `views` on `options`)
* @param options compilation options
* @return [Eta template function, new config object]
*/
declare function includeFile(path: string, options: EtaConfig): [TemplateFunction, EtaConfig];
/**
* Render a template from a filepath.
*
* @param filepath Path to template file. If relative, specify `views` on the config object
*
* This can take two different function signatures:
*
* - `renderFile(filename, data, [cb])`
* - `renderFile(filename, data, [config], [cb])`
*
* Note that renderFile does not immediately return the rendered result. If you pass in a callback function, it will be called with `(err, res)`. Otherwise, `renderFile` will return a `Promise` that resolves to the render result.
*
* **Examples**
*
* ```js
* eta.renderFile("./template.eta", data, {cache: true}, function (err, rendered) {
* if (err) console.log(err)
* console.log(rendered)
* })
*
* let rendered = await eta.renderFile("./template.eta", data, {cache: true})
*
* ```
*/
declare function renderFile(filename: string, data: DataObj, config?: PartialConfig): Promise<string>;
declare function renderFile(filename: string, data: DataObj, config: PartialConfig, cb: CallbackFn): void;
declare function renderFile(filename: string, data: DataObj, config?: PartialConfig, cb?: CallbackFn): Promise<string> | void;
declare function renderFile(filename: string, data: DataObj, cb: CallbackFn): void;
/**
* Render a template from a filepath asynchronously.
*
* @param filepath Path to template file. If relative, specify `views` on the config object
*
* This can take two different function signatures:
*
* - `renderFile(filename, data, [cb])`
* - `renderFile(filename, data, [config], [cb])`
*
* Note that renderFile does not immediately return the rendered result. If you pass in a callback function, it will be called with `(err, res)`. Otherwise, `renderFile` will return a `Promise` that resolves to the render result.
*
* **Examples**
*
* ```js
* eta.renderFile("./template.eta", data, {cache: true}, function (err, rendered) {
* if (err) console.log(err)
* console.log(rendered)
* })
*
* let rendered = await eta.renderFile("./template.eta", data, {cache: true})
*
* ```
*/
declare function renderFileAsync(filename: string, data: DataObj, config?: PartialConfig): Promise<string>;
declare function renderFileAsync(filename: string, data: DataObj, config: PartialConfig, cb: CallbackFn): void;
declare function renderFileAsync(filename: string, data: DataObj, config?: PartialConfig, cb?: CallbackFn): Promise<string> | void;
declare function renderFileAsync(filename: string, data: DataObj, cb: CallbackFn): void;
export { includeFile, renderFile, renderFileAsync };
//# sourceMappingURL=file-handlers.d.ts.map

1
node_modules/eta/dist/types/file-handlers.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"file-handlers.d.ts","sourceRoot":"","sources":["../../src/file-handlers.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAyB,MAAM,aAAa,CAAC;AACnF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,MAAM,MAAM,UAAU,GAAG,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;AAEnE,UAAU,OAAO;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,UAAU,yBAA0B,SAAQ,OAAO,CAAC,SAAS,CAAC;IAC5D,QAAQ,EAAE,MAAM,CAAC;CAClB;AAID;;;;;;GAMG;AAEH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,yBAAyB,EAClC,OAAO,CAAC,EAAE,OAAO,GAChB,gBAAgB,CAYlB;AAmED;;;;;;;;;;;;;;;GAeG;AAEH,iBAAS,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,GAAG,CAAC,gBAAgB,EAAE,SAAS,CAAC,CAKpF;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,iBAAS,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAE9F,iBAAS,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,EAAE,EAAE,UAAU,GAAG,IAAI,CAAC;AAElG,iBAAS,UAAU,CACjB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,OAAO,EACb,MAAM,CAAC,EAAE,aAAa,EACtB,EAAE,CAAC,EAAE,UAAU,GACd,OAAO,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;AAE1B,iBAAS,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,UAAU,GAAG,IAAI,CAAC;AA6C3E;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,iBAAS,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAEnG,iBAAS,eAAe,CACtB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,UAAU,GACb,IAAI,CAAC;AAER,iBAAS,eAAe,CACtB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,OAAO,EACb,MAAM,CAAC,EAAE,aAAa,EACtB,EAAE,CAAC,EAAE,UAAU,GACd,OAAO,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;AAE1B,iBAAS,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,UAAU,GAAG,IAAI,CAAC;AAgBhF,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,eAAe,EAAE,CAAC"}

10
node_modules/eta/dist/types/file-helpers.d.ts generated vendored Normal file
View File

@@ -0,0 +1,10 @@
import type { EtaConfig } from "./config.js";
interface GenericData {
[index: string]: any;
}
/**
* Called with `includeFile(path, data)`
*/
export declare function includeFileHelper(this: EtaConfig, path: string, data: GenericData): string;
export {};
//# sourceMappingURL=file-helpers.d.ts.map

1
node_modules/eta/dist/types/file-helpers.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"file-helpers.d.ts","sourceRoot":"","sources":["../../src/file-helpers.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,UAAU,WAAW;IACnB,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB;AAID;;GAEG;AAEH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,MAAM,CAG1F"}

4
node_modules/eta/dist/types/file-methods.d.ts generated vendored Normal file
View File

@@ -0,0 +1,4 @@
export { readFileSync, existsSync } from "fs";
import * as path from "path";
export { path };
//# sourceMappingURL=file-methods.d.ts.map

1
node_modules/eta/dist/types/file-methods.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"file-methods.d.ts","sourceRoot":"","sources":["../../src/file-methods.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAE9C,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,IAAI,EAAE,CAAC"}

25
node_modules/eta/dist/types/file-utils.d.ts generated vendored Normal file
View File

@@ -0,0 +1,25 @@
import type { EtaConfig } from "./config.js";
/**
* Get the absolute path to an included template
*
* If this is called with an absolute path (for example, starting with '/' or 'C:\')
* then Eta will attempt to resolve the absolute path within options.views. If it cannot,
* Eta will fallback to options.root or '/'
*
* If this is called with a relative path, Eta will:
* - Look relative to the current template (if the current template has the `filename` property)
* - Look inside each directory in options.views
*
* Note: if Eta is unable to find a template using path and options, it will throw an error.
*
* @param path specified path
* @param options compilation options
* @return absolute path to template
*/
declare function getPath(path: string, options: EtaConfig): string;
/**
* Reads a file synchronously
*/
declare function readFile(filePath: string): string;
export { getPath, readFile };
//# sourceMappingURL=file-utils.d.ts.map

1
node_modules/eta/dist/types/file-utils.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"file-utils.d.ts","sourceRoot":"","sources":["../../src/file-utils.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAyB7C;;;;;;;;;;;;;;;;GAgBG;AAEH,iBAAS,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,GAAG,MAAM,CAqHzD;AAED;;GAEG;AAEH,iBAAS,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAM1C;AAED,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC"}

10
node_modules/eta/dist/types/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,10 @@
import { config } from "./config.js";
export { loadFile, renderFile, renderFileAsync, renderFile as __express } from "./file-handlers.js";
export { default as compileToString } from "./compile-string.js";
export { default as compile } from "./compile.js";
export { default as parse } from "./parse.js";
export { default as render, renderAsync } from "./render.js";
export { templates } from "./containers.js";
export { config, config as defaultConfig, getConfig, configure } from "./config.js";
export type EtaConfig = typeof config;
//# sourceMappingURL=index.d.ts.map

1
node_modules/eta/dist/types/index.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAKrC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,IAAI,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAIpG,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,aAAa,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACpF,MAAM,MAAM,SAAS,GAAG,OAAO,MAAM,CAAC"}

9
node_modules/eta/dist/types/parse.d.ts generated vendored Normal file
View File

@@ -0,0 +1,9 @@
import type { EtaConfig } from "./config.js";
export type TagType = "r" | "e" | "i" | "";
export interface TemplateObject {
t: TagType;
val: string;
}
export type AstObject = string | TemplateObject;
export default function parse(str: string, config: EtaConfig): Array<AstObject>;
//# sourceMappingURL=parse.d.ts.map

1
node_modules/eta/dist/types/parse.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/parse.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,MAAM,OAAO,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,EAAE,CAAC;AAE3C,MAAM,WAAW,cAAc;IAC7B,CAAC,EAAE,OAAO,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,cAAc,CAAC;AAiBhD,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC,CA2K9E"}

25
node_modules/eta/dist/types/polyfills.d.ts generated vendored Normal file
View File

@@ -0,0 +1,25 @@
/**
* @returns The global Promise function
*/
export declare const promiseImpl: PromiseConstructor;
/**
* @returns A new AsyncFunction constuctor
*/
export declare function getAsyncFunctionConstructor(): Function;
/**
* str.trimLeft polyfill
*
* @param str - Input string
* @returns The string with left whitespace removed
*
*/
export declare function trimLeft(str: string): string;
/**
* str.trimRight polyfill
*
* @param str - Input string
* @returns The string with right whitespace removed
*
*/
export declare function trimRight(str: string): string;
//# sourceMappingURL=polyfills.d.ts.map

1
node_modules/eta/dist/types/polyfills.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"polyfills.d.ts","sourceRoot":"","sources":["../../src/polyfills.ts"],"names":[],"mappings":"AAEA;;GAEG;AAEH,eAAO,MAAM,WAAW,EAAE,kBAA0D,CAAC;AAErF;;GAEG;AAEH,wBAAgB,2BAA2B,IAAI,QAAQ,CAUtD;AAED;;;;;;GAMG;AAEH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAO5C;AAED;;;;;;GAMG;AAEH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAO7C"}

122
node_modules/eta/dist/types/render.d.ts generated vendored Normal file
View File

@@ -0,0 +1,122 @@
import type { PartialConfig, PartialAsyncConfig } from "./config.js";
import type { TemplateFunction } from "./compile.js";
import type { CallbackFn } from "./file-handlers.js";
/**
* Render a template
*
* If `template` is a string, Eta will compile it to a function and then call it with the provided data.
* If `template` is a template function, Eta will call it with the provided data.
*
* If `config.async` is `false`, Eta will return the rendered template.
*
* If `config.async` is `true` and there's a callback function, Eta will call the callback with `(err, renderedTemplate)`.
* If `config.async` is `true` and there's not a callback function, Eta will return a Promise that resolves to the rendered template.
*
* If `config.cache` is `true` and `config` has a `name` or `filename` property, Eta will cache the template on the first render and use the cached template for all subsequent renders.
*
* @param template Template string or template function
* @param data Data to render the template with
* @param config Optional config options
* @param cb Callback function
*/
export default function render(template: string | TemplateFunction, data: object, config: PartialAsyncConfig, cb: CallbackFn): void;
/**
* Render a template
*
* If `template` is a string, Eta will compile it to a function and then call it with the provided data.
* If `template` is a template function, Eta will call it with the provided data.
*
* If `config.async` is `false`, Eta will return the rendered template.
*
* If `config.async` is `true` and there's a callback function, Eta will call the callback with `(err, renderedTemplate)`.
* If `config.async` is `true` and there's not a callback function, Eta will return a Promise that resolves to the rendered template.
*
* If `config.cache` is `true` and `config` has a `name` or `filename` property, Eta will cache the template on the first render and use the cached template for all subsequent renders.
*
* @param template Template string or template function
* @param data Data to render the template with
* @param config Optional config options
*/
export default function render(template: string | TemplateFunction, data: object, config: PartialAsyncConfig): Promise<string>;
/**
* Render a template
*
* If `template` is a string, Eta will compile it to a function and then call it with the provided data.
* If `template` is a template function, Eta will call it with the provided data.
*
* If `config.async` is `false`, Eta will return the rendered template.
*
* If `config.async` is `true` and there's a callback function, Eta will call the callback with `(err, renderedTemplate)`.
* If `config.async` is `true` and there's not a callback function, Eta will return a Promise that resolves to the rendered template.
*
* If `config.cache` is `true` and `config` has a `name` or `filename` property, Eta will cache the template on the first render and use the cached template for all subsequent renders.
*
* @param template Template string or template function
* @param data Data to render the template with
* @param config Optional config options
*/
export default function render(template: string | TemplateFunction, data: object, config?: PartialConfig): string;
/**
* Render a template
*
* If `template` is a string, Eta will compile it to a function and then call it with the provided data.
* If `template` is a template function, Eta will call it with the provided data.
*
* If `config.async` is `false`, Eta will return the rendered template.
*
* If `config.async` is `true` and there's a callback function, Eta will call the callback with `(err, renderedTemplate)`.
* If `config.async` is `true` and there's not a callback function, Eta will return a Promise that resolves to the rendered template.
*
* If `config.cache` is `true` and `config` has a `name` or `filename` property, Eta will cache the template on the first render and use the cached template for all subsequent renders.
*
* @param template Template string or template function
* @param data Data to render the template with
* @param config Optional config options
* @param cb Callback function
*/
export default function render(template: string | TemplateFunction, data: object, config?: PartialConfig, cb?: CallbackFn): string | Promise<string> | void;
/**
* Render a template asynchronously
*
* If `template` is a string, Eta will compile it to a function and call it with the provided data.
* If `template` is a function, Eta will call it with the provided data.
*
* If there is a callback function, Eta will call it with `(err, renderedTemplate)`.
* If there is not a callback function, Eta will return a Promise that resolves to the rendered template
*
* @param template Template string or template function
* @param data Data to render the template with
* @param config Optional config options
*/
export declare function renderAsync(template: string | TemplateFunction, data: object, config?: PartialConfig): Promise<string>;
/**
* Render a template asynchronously
*
* If `template` is a string, Eta will compile it to a function and call it with the provided data.
* If `template` is a function, Eta will call it with the provided data.
*
* If there is a callback function, Eta will call it with `(err, renderedTemplate)`.
* If there is not a callback function, Eta will return a Promise that resolves to the rendered template
*
* @param template Template string or template function
* @param data Data to render the template with
* @param config Optional config options
* @param cb Callback function
*/
export declare function renderAsync(template: string | TemplateFunction, data: object, config: PartialConfig, cb: CallbackFn): void;
/**
* Render a template asynchronously
*
* If `template` is a string, Eta will compile it to a function and call it with the provided data.
* If `template` is a function, Eta will call it with the provided data.
*
* If there is a callback function, Eta will call it with `(err, renderedTemplate)`.
* If there is not a callback function, Eta will return a Promise that resolves to the rendered template
*
* @param template Template string or template function
* @param data Data to render the template with
* @param config Optional config options
* @param cb Callback function
*/
export declare function renderAsync(template: string | TemplateFunction, data: object, config?: PartialConfig, cb?: CallbackFn): string | Promise<string> | void;
//# sourceMappingURL=render.d.ts.map

1
node_modules/eta/dist/types/render.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/render.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAa,aAAa,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAChF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAoBrD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,OAAO,UAAU,MAAM,CAC5B,QAAQ,EAAE,MAAM,GAAG,gBAAgB,EACnC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,kBAAkB,EAC1B,EAAE,EAAE,UAAU,GACb,IAAI,CAAC;AAER;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,OAAO,UAAU,MAAM,CAC5B,QAAQ,EAAE,MAAM,GAAG,gBAAgB,EACnC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,MAAM,CAAC,CAAC;AAEnB;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,OAAO,UAAU,MAAM,CAC5B,QAAQ,EAAE,MAAM,GAAG,gBAAgB,EACnC,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,aAAa,GACrB,MAAM,CAAC;AAEV;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,OAAO,UAAU,MAAM,CAC5B,QAAQ,EAAE,MAAM,GAAG,gBAAgB,EACnC,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,aAAa,EACtB,EAAE,CAAC,EAAE,UAAU,GACd,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;AAwCnC;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,GAAG,gBAAgB,EACnC,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,aAAa,GACrB,OAAO,CAAC,MAAM,CAAC,CAAC;AAEnB;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,GAAG,gBAAgB,EACnC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,UAAU,GACb,IAAI,CAAC;AAER;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,GAAG,gBAAgB,EACnC,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,aAAa,EACtB,EAAE,CAAC,EAAE,UAAU,GACd,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC"}

17
node_modules/eta/dist/types/storage.d.ts generated vendored Normal file
View File

@@ -0,0 +1,17 @@
/**
* Handles storage and accessing of values
*
* In this case, we use it to store compiled template functions
* Indexed by their `name` or `filename`
*/
declare class Cacher<T> {
private cache;
constructor(cache: Record<string, T>);
define(key: string, val: T): void;
get(key: string): T;
remove(key: string): void;
reset(): void;
load(cacheObj: Record<string, T>): void;
}
export { Cacher };
//# sourceMappingURL=storage.d.ts.map

1
node_modules/eta/dist/types/storage.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/storage.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,cAAM,MAAM,CAAC,CAAC;IACA,OAAO,CAAC,KAAK;gBAAL,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IAC5C,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,IAAI;IAGjC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC;IAMnB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAGzB,KAAK,IAAI,IAAI;IAGb,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,IAAI;CAGxC;AAED,OAAO,EAAE,MAAM,EAAE,CAAC"}

16
node_modules/eta/dist/types/utils.d.ts generated vendored Normal file
View File

@@ -0,0 +1,16 @@
import type { EtaConfig } from "./config.js";
export declare function hasOwnProp(obj: object, prop: string): boolean;
export declare function copyProps<T>(toObj: T, fromObj: T): T;
/**
* Takes a string within a template and trims it, based on the preceding tag's whitespace control and `config.autoTrim`
*/
declare function trimWS(str: string, config: EtaConfig, wsLeft: string | false, wsRight?: string | false): string;
/**
* XML-escapes an input value after converting it to a string
*
* @param str - Input value (usually a string)
* @returns XML-escaped string
*/
declare function XMLEscape(str: any): string;
export { trimWS, XMLEscape };
//# sourceMappingURL=utils.d.ts.map

1
node_modules/eta/dist/types/utils.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAa7C,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAE7D;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,CAOpD;AAED;;GAEG;AAEH,iBAAS,MAAM,CACb,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,MAAM,GAAG,KAAK,EACtB,OAAO,CAAC,EAAE,MAAM,GAAG,KAAK,GACvB,MAAM,CAgDR;AAkBD;;;;;GAKG;AAEH,iBAAS,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CASnC;AAED,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC"}