jexl-extended
Version:
Extended grammar for Javascript Expression Language (JEXL)
330 lines (329 loc) • 19.3 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GrammarType = exports.JexlExtended = void 0;
const jexl_1 = require("jexl");
const extended_grammar_1 = require("./extended-grammar");
class JexlExtended extends jexl_1.Jexl {
constructor() {
super();
// String
this.addFunction('string', extended_grammar_1.toString);
this.addFunction('$string', extended_grammar_1.toString);
this.addTransform('string', extended_grammar_1.toString);
// toString causes issues in javascript
// this.addTransform('toString', toString);
//Json
this.addFunction('json', extended_grammar_1.toJson);
this.addFunction('$json', extended_grammar_1.toJson);
this.addTransform('toJson', extended_grammar_1.toJson);
this.addFunction('parseJson', extended_grammar_1.toJson);
this.addFunction('$parseJson', extended_grammar_1.toJson);
this.addTransform('parseJson', extended_grammar_1.toJson);
// Length
this.addFunction('length', extended_grammar_1.length);
this.addFunction('$length', extended_grammar_1.length);
this.addTransform('length', extended_grammar_1.length);
this.addFunction('count', extended_grammar_1.length);
this.addFunction('$count', extended_grammar_1.length);
this.addTransform('count', extended_grammar_1.length);
this.addFunction('size', extended_grammar_1.length);
this.addFunction('$size', extended_grammar_1.length);
this.addTransform('size', extended_grammar_1.length);
// Substring
this.addFunction('substring', extended_grammar_1.substring);
this.addFunction('$substring', extended_grammar_1.substring);
this.addTransform('substring', extended_grammar_1.substring);
// SubstringBefore
this.addFunction('substringBefore', extended_grammar_1.substringBefore);
this.addFunction('$substringBefore', extended_grammar_1.substringBefore);
this.addTransform('substringBefore', extended_grammar_1.substringBefore);
// SubstringAfter
this.addFunction('substringAfter', extended_grammar_1.substringAfter);
this.addFunction('$substringAfter', extended_grammar_1.substringAfter);
this.addTransform('substringAfter', extended_grammar_1.substringAfter);
// Uppercase
this.addFunction('uppercase', extended_grammar_1.uppercase);
this.addFunction('$uppercase', extended_grammar_1.uppercase);
this.addTransform('uppercase', extended_grammar_1.uppercase);
this.addFunction('upper', extended_grammar_1.uppercase);
this.addFunction('$upper', extended_grammar_1.uppercase);
this.addTransform('upper', extended_grammar_1.uppercase);
// Lowercase
this.addFunction('lowercase', extended_grammar_1.lowercase);
this.addFunction('$lowercase', extended_grammar_1.lowercase);
this.addTransform('lowercase', extended_grammar_1.lowercase);
this.addFunction('lower', extended_grammar_1.lowercase);
this.addFunction('$lower', extended_grammar_1.lowercase);
this.addTransform('lower', extended_grammar_1.lowercase);
// CamelCase
this.addFunction('camelCase', extended_grammar_1.camelCase);
this.addFunction('$camelCase', extended_grammar_1.camelCase);
this.addTransform('camelcase', extended_grammar_1.camelCase);
this.addTransform('camelCase', extended_grammar_1.camelCase);
this.addTransform('toCamelCase', extended_grammar_1.camelCase);
// PascalCase
this.addFunction('pascalCase', extended_grammar_1.pascalCase);
this.addFunction('$pascalCase', extended_grammar_1.pascalCase);
this.addTransform('pascalcase', extended_grammar_1.pascalCase);
this.addTransform('pascalCase', extended_grammar_1.pascalCase);
this.addTransform('toPascalCase', extended_grammar_1.pascalCase);
// Trim
this.addFunction('trim', extended_grammar_1.trim);
this.addFunction('$trim', extended_grammar_1.trim);
this.addTransform('trim', extended_grammar_1.trim);
// Pad
this.addFunction('pad', extended_grammar_1.pad);
this.addFunction('$pad', extended_grammar_1.pad);
this.addTransform('pad', extended_grammar_1.pad);
// Contains
this.addFunction('contains', extended_grammar_1.contains);
this.addFunction('$contains', extended_grammar_1.contains);
this.addTransform('contains', extended_grammar_1.contains);
this.addFunction('includes', extended_grammar_1.contains);
this.addFunction('$includes', extended_grammar_1.contains);
this.addTransform('includes', extended_grammar_1.contains);
// StartsWith
this.addFunction('startsWith', extended_grammar_1.startsWith);
this.addFunction('$startsWith', extended_grammar_1.startsWith);
this.addTransform('startsWith', extended_grammar_1.startsWith);
// EndsWith
this.addFunction('endsWith', extended_grammar_1.endsWith);
this.addFunction('$endsWith', extended_grammar_1.endsWith);
this.addTransform('endsWith', extended_grammar_1.endsWith);
// Split
this.addFunction('split', extended_grammar_1.split);
this.addFunction('$split', extended_grammar_1.split);
this.addTransform('split', extended_grammar_1.split);
// Join
this.addFunction('join', extended_grammar_1.arrayJoin);
this.addFunction('$join', extended_grammar_1.arrayJoin);
this.addTransform('join', extended_grammar_1.arrayJoin);
// Replace
this.addFunction('replace', extended_grammar_1.replace);
this.addFunction('$replace', extended_grammar_1.replace);
this.addTransform('replace', extended_grammar_1.replace);
// Base64Encode
this.addFunction('base64Encode', extended_grammar_1.base64Encode);
this.addFunction('$base64Encode', extended_grammar_1.base64Encode);
this.addTransform('base64Encode', extended_grammar_1.base64Encode);
// Base64Decode
this.addFunction('base64Decode', extended_grammar_1.base64Decode);
this.addFunction('$base64Decode', extended_grammar_1.base64Decode);
this.addTransform('base64Decode', extended_grammar_1.base64Decode);
// Form URL Encoded
this.addFunction('formUrlEncoded', extended_grammar_1.formUrlEncoded);
this.addFunction('$formUrlEncoded', extended_grammar_1.formUrlEncoded);
this.addTransform('formUrlEncoded', extended_grammar_1.formUrlEncoded);
// Number
this.addFunction('number', extended_grammar_1.toNumber);
this.addFunction('$number', extended_grammar_1.toNumber);
this.addTransform('number', extended_grammar_1.toNumber);
this.addTransform('toNumber', extended_grammar_1.toNumber);
this.addFunction('parseFloat', extended_grammar_1.toNumber);
this.addFunction('$parseFloat', extended_grammar_1.toNumber);
this.addTransform('float', extended_grammar_1.toNumber);
this.addTransform('toFloat', extended_grammar_1.toNumber);
// AbsoluteValue
this.addFunction('abs', extended_grammar_1.absoluteValue);
this.addFunction('$abs', extended_grammar_1.absoluteValue);
this.addTransform('abs', extended_grammar_1.absoluteValue);
// Floor
this.addFunction('floor', extended_grammar_1.floor);
this.addFunction('$floor', extended_grammar_1.floor);
this.addTransform('floor', extended_grammar_1.floor);
// Ceil
this.addFunction('ceil', extended_grammar_1.ceil);
this.addFunction('$ceil', extended_grammar_1.ceil);
this.addTransform('ceil', extended_grammar_1.ceil);
// Round
this.addFunction('round', extended_grammar_1.round);
this.addFunction('$round', extended_grammar_1.round);
this.addTransform('round', extended_grammar_1.round);
// Power
this.addFunction('power', extended_grammar_1.power);
this.addFunction('$power', extended_grammar_1.power);
this.addTransform('power', extended_grammar_1.power);
// Sqrt
this.addFunction('sqrt', extended_grammar_1.sqrt);
this.addFunction('$sqrt', extended_grammar_1.sqrt);
this.addTransform('sqrt', extended_grammar_1.sqrt);
// Random
this.addFunction('random', extended_grammar_1.randomNumber);
this.addFunction('$random', extended_grammar_1.randomNumber);
// FormatNumber
this.addFunction('formatNumber', extended_grammar_1.formatNumber);
this.addFunction('$formatNumber', extended_grammar_1.formatNumber);
this.addTransform('formatNumber', extended_grammar_1.formatNumber);
// FormatBase
this.addFunction('formatBase', extended_grammar_1.formatBase);
this.addFunction('$formatBase', extended_grammar_1.formatBase);
this.addTransform('formatBase', extended_grammar_1.formatBase);
// FormatInteger
this.addFunction('formatInteger', extended_grammar_1.formatInteger);
this.addFunction('$formatInteger', extended_grammar_1.formatInteger);
this.addTransform('formatInteger', extended_grammar_1.formatInteger);
// ParseInteger
this.addFunction('parseInteger', extended_grammar_1.parseInteger);
this.addFunction('parseInt', extended_grammar_1.parseInteger);
this.addFunction('$parseInteger', extended_grammar_1.parseInteger);
this.addTransform('parseInteger', extended_grammar_1.parseInteger);
this.addTransform('parseInt', extended_grammar_1.parseInteger);
this.addTransform('toInt', extended_grammar_1.parseInteger);
this.addTransform('integer', extended_grammar_1.parseInteger);
// Sum
this.addFunction('sum', extended_grammar_1.sum);
this.addFunction('$sum', extended_grammar_1.sum);
this.addTransform('sum', extended_grammar_1.sum);
// Max
this.addFunction('max', extended_grammar_1.max);
this.addFunction('$max', extended_grammar_1.max);
this.addTransform('max', extended_grammar_1.max);
// Min
this.addFunction('min', extended_grammar_1.min);
this.addFunction('$min', extended_grammar_1.min);
this.addTransform('min', extended_grammar_1.min);
// Average
this.addFunction('average', extended_grammar_1.average);
this.addFunction('avg', extended_grammar_1.average);
this.addFunction('$average', extended_grammar_1.average);
this.addTransform('average', extended_grammar_1.average);
this.addTransform('avg', extended_grammar_1.average);
// Boolean
this.addFunction('boolean', extended_grammar_1.toBoolean);
this.addFunction('$boolean', extended_grammar_1.toBoolean);
this.addTransform('boolean', extended_grammar_1.toBoolean);
this.addFunction('bool', extended_grammar_1.toBoolean);
this.addFunction('$bool', extended_grammar_1.toBoolean);
this.addTransform('bool', extended_grammar_1.toBoolean);
this.addTransform('toBoolean', extended_grammar_1.toBoolean);
this.addTransform('toBool', extended_grammar_1.toBoolean);
// Not
this.addFunction('not', extended_grammar_1.not);
this.addFunction('$not', extended_grammar_1.not);
this.addTransform('not', extended_grammar_1.not);
// SwitchCase
this.addFunction('case', extended_grammar_1.switchCase);
this.addFunction('$case', extended_grammar_1.switchCase);
this.addTransform('case', extended_grammar_1.switchCase);
this.addFunction('switch', extended_grammar_1.switchCase);
this.addFunction('$switch', extended_grammar_1.switchCase);
this.addTransform('switch', extended_grammar_1.switchCase);
// Array operations
this.addFunction('append', extended_grammar_1.arrayAppend);
this.addFunction('$append', extended_grammar_1.arrayAppend);
this.addTransform('append', extended_grammar_1.arrayAppend);
this.addFunction('concat', extended_grammar_1.arrayAppend);
this.addFunction('$concat', extended_grammar_1.arrayAppend);
this.addTransform('concat', extended_grammar_1.arrayAppend);
this.addFunction('reverse', extended_grammar_1.arrayReverse);
this.addFunction('$reverse', extended_grammar_1.arrayReverse);
this.addTransform('reverse', extended_grammar_1.arrayReverse);
this.addFunction('shuffle', extended_grammar_1.arrayShuffle);
this.addFunction('$shuffle', extended_grammar_1.arrayShuffle);
this.addTransform('shuffle', extended_grammar_1.arrayShuffle);
this.addFunction('sort', extended_grammar_1.arraySort);
this.addFunction('$sort', extended_grammar_1.arraySort);
this.addTransform('sort', extended_grammar_1.arraySort);
this.addFunction('order', extended_grammar_1.arraySort);
this.addFunction('$order', extended_grammar_1.arraySort);
this.addTransform('order', extended_grammar_1.arraySort);
this.addFunction('distinct', extended_grammar_1.arrayDistinct);
this.addFunction('$distinct', extended_grammar_1.arrayDistinct);
this.addTransform('distinct', extended_grammar_1.arrayDistinct);
this.addFunction('toObject', extended_grammar_1.arrayToObject);
this.addFunction('$toObject', extended_grammar_1.arrayToObject);
this.addTransform('toObject', extended_grammar_1.arrayToObject);
this.addFunction('fromEntries', extended_grammar_1.arrayToObject);
this.addFunction('$fromEntries', extended_grammar_1.arrayToObject);
this.addTransform('fromEntries', extended_grammar_1.arrayToObject);
// Map and filter operations
this.addFunction('mapField', extended_grammar_1.mapField);
this.addFunction('$mapField', extended_grammar_1.mapField);
this.addTransform('mapField', extended_grammar_1.mapField);
this.addFunction('map', extended_grammar_1.arrayMap);
this.addFunction('$map', extended_grammar_1.arrayMap);
this.addTransform('map', extended_grammar_1.arrayMap);
this.addFunction('any', extended_grammar_1.arrayAny);
this.addFunction('$any', extended_grammar_1.arrayAny);
this.addTransform('any', extended_grammar_1.arrayAny);
this.addFunction('some', extended_grammar_1.arrayAny);
this.addFunction('$some', extended_grammar_1.arrayAny);
this.addTransform('some', extended_grammar_1.arrayAny);
this.addFunction('all', extended_grammar_1.arrayEvery);
this.addFunction('$all', extended_grammar_1.arrayEvery);
this.addTransform('all', extended_grammar_1.arrayEvery);
this.addFunction('every', extended_grammar_1.arrayEvery);
this.addFunction('$every', extended_grammar_1.arrayEvery);
this.addTransform('every', extended_grammar_1.arrayEvery);
this.addFunction('filter', extended_grammar_1.arrayFilter);
this.addFunction('$filter', extended_grammar_1.arrayFilter);
this.addTransform('filter', extended_grammar_1.arrayFilter);
this.addFunction('find', extended_grammar_1.arrayFind);
this.addFunction('$find', extended_grammar_1.arrayFind);
this.addTransform('find', extended_grammar_1.arrayFind);
this.addFunction('reduce', extended_grammar_1.arrayReduce);
this.addFunction('$reduce', extended_grammar_1.arrayReduce);
this.addTransform('reduce', extended_grammar_1.arrayReduce);
// Object operations
this.addFunction('keys', extended_grammar_1.objectKeys);
this.addFunction('$keys', extended_grammar_1.objectKeys);
this.addTransform('keys', extended_grammar_1.objectKeys);
this.addFunction('values', extended_grammar_1.objectValues);
this.addFunction('$values', extended_grammar_1.objectValues);
this.addTransform('values', extended_grammar_1.objectValues);
this.addFunction('entries', extended_grammar_1.objectEntries);
this.addFunction('$entries', extended_grammar_1.objectEntries);
this.addTransform('entries', extended_grammar_1.objectEntries);
this.addFunction('merge', extended_grammar_1.objectMerge);
this.addFunction('$merge', extended_grammar_1.objectMerge);
this.addTransform('merge', extended_grammar_1.objectMerge);
// Now
this.addFunction('now', extended_grammar_1.now);
this.addFunction('$now', extended_grammar_1.now);
// Millis
this.addFunction('millis', extended_grammar_1.millis);
this.addFunction('$millis', extended_grammar_1.millis);
// ToDateTime
this.addFunction('millisToDateTime', extended_grammar_1.toDateTime);
this.addFunction('$millisToDateTime', extended_grammar_1.toDateTime);
this.addTransform('millisToDateTime', extended_grammar_1.toDateTime);
this.addFunction('fromMillis', extended_grammar_1.toDateTime);
this.addFunction('$fromMillis', extended_grammar_1.toDateTime);
this.addTransform('fromMillis', extended_grammar_1.toDateTime);
this.addFunction('toDateTime', extended_grammar_1.toDateTime);
this.addFunction('$toDateTime', extended_grammar_1.toDateTime);
this.addTransform('toDateTime', extended_grammar_1.toDateTime);
this.addFunction('dateTimeString', extended_grammar_1.toDateTime);
// DateTimeToMillis
this.addFunction('dateTimeToMillis', extended_grammar_1.dateTimeToMillis);
this.addFunction('$dateTimeToMillis', extended_grammar_1.dateTimeToMillis);
this.addTransform('dateTimeToMillis', extended_grammar_1.dateTimeToMillis);
this.addFunction('toMillis', extended_grammar_1.dateTimeToMillis);
this.addFunction('$toMillis', extended_grammar_1.dateTimeToMillis);
this.addTransform('toMillis', extended_grammar_1.dateTimeToMillis);
// DateTimeFormat
this.addFunction('dateTimeFormat', extended_grammar_1.dateTimeFormat);
this.addFunction('$dateTimeFormat', extended_grammar_1.dateTimeFormat);
this.addTransform('dateTimeFormat', extended_grammar_1.dateTimeFormat);
// DateTimeAdd
this.addFunction('dateTimeAdd', extended_grammar_1.dateTimeAdd);
this.addFunction('$dateTimeAdd', extended_grammar_1.dateTimeAdd);
this.addTransform('dateTimeAdd', extended_grammar_1.dateTimeAdd);
// Eval
this.addFunction('eval', extended_grammar_1._eval);
this.addFunction('$eval', extended_grammar_1._eval);
this.addTransform('eval', extended_grammar_1._eval);
// Uuid
this.addFunction('uuid', extended_grammar_1.uuid);
this.addFunction('$uuid', extended_grammar_1.uuid);
this.addFunction('uid', extended_grammar_1.uuid);
this.addFunction('$uid', extended_grammar_1.uuid);
}
}
exports.JexlExtended = JexlExtended;
var GrammarType;
(function (GrammarType) {
GrammarType["Function"] = "Function";
GrammarType["Transform"] = "Transform";
})(GrammarType || (exports.GrammarType = GrammarType = {}));
exports.default = new JexlExtended();