Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
return undefined;
}
/**
* Custom Mustache Context capable to collect message property and node
* flow and global context
*/
function NodeContext(msg, parent, nodeContext, serverName) {
this.msgContext = new mustache.Context(msg, parent);
this.nodeContext = nodeContext;
this.serverName = serverName;
}
NodeContext.prototype = new mustache.Context();
NodeContext.prototype.lookup = function(name) {
// try message first:
const value = this.msgContext.lookup(name);
if (value !== undefined) {
return value;
}
// try flow/global context:
const context = parseContext(name);
if (context) {
const type = context.type;
const store = context.store;
const field = context.field;
const target = this.nodeContext[type];
if (target) {
return undefined;
}
/**
* Custom Mustache Context capable to collect message property and node
* flow and global context
*/
function NodeContext(msg, nodeContext, parent, escapeStrings, cachedContextTokens) {
this.msgContext = new mustache.Context(msg,parent);
this.nodeContext = nodeContext;
this.escapeStrings = escapeStrings;
this.cachedContextTokens = cachedContextTokens;
}
NodeContext.prototype = new mustache.Context();
NodeContext.prototype.lookup = function (name) {
// try message first:
try {
var value = this.msgContext.lookup(name);
if (value !== undefined) {
if (this.escapeStrings && typeof value === "string") {
value = value.replace(/\\/g, "\\\\");
value = value.replace(/\n/g, "\\n");
value = value.replace(/\t/g, "\\t");
value = value.replace(/\r/g, "\\r");
value = value.replace(/\f/g, "\\f");
value = value.replace(/[\b]/g, "\\b");
}
return value;
}
import Mustache from 'mustache'
import Json from './Json'
import { log } from 'ern-core'
import { MustacheWriter } from './MustacheWriter'
import { isIterable } from './isIterable'
function truthy(val) {
if (val == null || val.length === 0 || val === false) {
return false
}
return true
}
function isInt(val) {
return /^\d+?$/.test(val)
}
class MyContext extends Mustache.Context {
protected _first: any
protected _last: any
constructor(value, parent?: any, first?: any, last?: any) {
super(value, parent)
this._first = first
this._last = last
}
public lookup(name) {
if (/-?last/.test(name)) {
return this._last
}
if (/-?first/.test(name)) {
return this._first
}
const render = (template, dict, tags=['<%', '%>']) => {
const tokens = mustacheWriter.parse(template, tags);
const context = new mustache.Context(dict);
let result = '';
for (let token of tokens) {
const symbol = token[0];
let tokenStr = token[1];
if (symbol === 'text') {
result += tokenStr;
} else if (symbol === 'name') {
tokenStr = tokenStr.replace(/\[(\d+)\]/g, '.$1');
const value = context.lookup(tokenStr);
if (value != null) {
result += value;
}
}
}
return result.trim();
};
function compiled(obj) {
return writer.renderTokens(mustacheCompileTokens, new mustache.Context(obj))
}
function mustache_compile(obj) {
return mustache_writer.renderTokens(mustache_compile_tokens, new mustache.Context(obj))
}
function NodeContext(msg, parent, nodeContext, serverName) {
this.msgContext = new mustache.Context(msg, parent);
this.nodeContext = nodeContext;
this.serverName = serverName;
}
function NodeContext(msg, nodeContext, parent, escapeStrings, cachedContextTokens) {
this.msgContext = new mustache.Context(msg,parent);
this.nodeContext = nodeContext;
this.escapeStrings = escapeStrings;
this.cachedContextTokens = cachedContextTokens;
}