Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private registerSplit() {
Handlebars.registerHelper('split', function (...args: any[]) {
if(args.length === 3)
return args[0].split(args[1]);
if(args.length === 4)
return args[0].split(args[1])[args[2]];
});
}
private registerI18n() {
Handlebars.registerHelper('i18n', (...fctArgs) => {
let args = [],
options = fctArgs[fctArgs.length - 1];
for (let i = 0; i < fctArgs.length - 1; i++) {
args.push(fctArgs[i]);
}
let i18nKey: string, i18nParams: string[];
if (typeof args[0] == 'object') {
i18nKey = args[0].key;
i18nParams = args[0].parameters;
} else {
i18nKey = "";
for (let i = 0; i < args.length; i++) {
if (i18nKey)
i18nKey += "."
i18nKey += args[i];
private registerMath(){
Handlebars.registerHelper("math", function(lvalue, operator, rvalue, options) {
let result;
switch(operator) {
case "+": result = lvalue + rvalue; break;
case "-": result = lvalue - rvalue; break;
case "*": result = lvalue * rvalue; break;
case "/": result = lvalue / rvalue; break;
case "%": result = lvalue % rvalue; break;
}
return result;
});
}
private registerPreserveSpace() {
Handlebars.registerHelper("preserveSpace", function (value, options) {
return value.replace(/ /g, '\u00A0')
});
}
}
private registerNow() {
const that = this;
Handlebars.registerHelper('now', function (options) {
return that.time.currentTime().valueOf();
})
}
private registerSort() {
Handlebars.registerHelper('sort', function () {
let args = [];
for (let index = 0; index < arguments.length - 1; index++) {
args.push(arguments[index]);
}
const context: any | any[] = args[0];
const sortKey = args[1];
let arrayToSort: any[];
let isObject:boolean;
if (typeof context == 'object') {
if (context.length !== undefined && context.length !== null) {
arrayToSort = context;
isObject = (typeof arrayToSort[0] == 'object')
} else {
isObject = true;
arrayToSort = [];
for (let property in context) {
private registerJson() {
Handlebars.registerHelper('json', function (obj) {
return new Handlebars.SafeString(JSON.stringify(obj))
});
}
private registerArrayAtIndexLength() {
Handlebars.registerHelper('arrayAtIndexLength', function (value, index, options) {
return value[index].length;
});
}