UNPKG

zpt

Version:

Zenon Page Templates - JS (ZPT-JS)

51 lines (37 loc) 1.24 kB
/* ExistsExpression class */ import { context } from '../context.js'; import { expressionsUtils } from './expressionsUtils.js'; import { expressionBuilder } from './expressionBuilder.js'; export const ExistsExpression = function( stringToApply, expressionToApply ) { var string = stringToApply; var expression = expressionToApply; var evaluate = function( scope ){ try { return undefined !== expression.evaluate( scope ); } catch ( e ){ return false; } }; var dependsOn = function( depsDataItem, scope ){ return expressionsUtils.buildDependsOnList( depsDataItem, scope, expression ); }; var toString = function(){ return string; }; return { evaluate: evaluate, dependsOn: dependsOn, toString: toString }; }; ExistsExpression.removePrefix = true; ExistsExpression.getPrefix = function() { return context.getConf().existsExpression; }; ExistsExpression.getId = ExistsExpression.getPrefix; ExistsExpression.build = function( string ) { var expression = expressionBuilder.build( string ); return new ExistsExpression( string, expression ); };