UNPKG

som-exp-sdk

Version:

Evaluate the User Expression

147 lines (146 loc) 4.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Constants = void 0; class Constants { constructor() { this.POINT = "point"; this.MAX_LOOP_COUNT = 1000; this.TOLERANCE_LEVEL = 0.00000005; this.INVALID_EXPRESSION = "Invalid Expression!"; this.INVALID_INPUT_VALUE = "0"; this.WHILE = "while"; this.UNTIL = "until"; this.TYPE_BOOLEAN = "boolean"; this.LITERAL_SLASH = "/"; this.REGEX_EXP1 = "EXP1"; this.REGEX_EXP2 = "EXP2"; this.REGEX_LOOP_TYPE = "LOOPTYPE"; this.REGEX_CONDITION = "CONDITION"; this.REGEX_COUNT = "COUNT"; this.TIME_FORMAT = "HH:mm"; this.MILLISECONDS = 60000; this.AM_PM_TIME_FORMAT = "hh:mm A"; this.TIME_FORMAT_24_HOUR = "24h"; this.TIME_FORMAT_12_HOUR = "12h"; this.DIGITS_IN_WORDS = [ "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" ]; this.WEEK_DAYS = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ]; this.MONTH_NAMES = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]; // file names this.FILE_NAME_BASE_EXPRESSION = "base-expression"; this.FILE_NAME_CONDITIONAL_EXPRESSION = "conditional-expression"; this.FILE_NAME_FINANCIAL_EXPRESSION = "financial-expression"; this.FILE_NAME_NUMERICAL_EXPRESSION = "numerical-expression"; this.FILE_NAME_SENTENCE_EXPRESSION = "sentence-expression"; this.FILE_NAME_LOOP_EXPRESSION = "loop-expression"; this.FILE_NAME_DATE_EXPRESSION = "date-expression"; this.FILE_NAME_TIME_EXPRESSION = "time-expression"; // all methods this.BASE_EXPRESSIONS = [ "evaluateExpression", "removeSpaces", "wrapInSpace" ]; this.CONDITIONAL_EXPRESSIONS = [ "ifElse" ]; this.DATE_EXPRESSIONS = [ "day", "dayName", "dayShortName", "month", "monthName", "monthShortName", "year", "yearShort", "words", "duration", "durationYearMonth", "durationOnlyYear", "durationMonths", "durationDays", "zonedDateTime", "addMinutes", "getEpochMillis", "getDateFromEpoch", "addDays", "addBusinessDays", "getFormattedTime" ]; this.FINANCIAL_EXPRESSIONS = [ "pv", "fv", "pmt", "rate" ]; this.LOOP_EXPRESSIONS = [ "forLoop", "loopCount" ]; this.NUMERICAL_EXPRESSIONS = [ "round", "roundUp", "roundDown", "power", "spellout" ]; this.SENTENCE_EXPRESSIONS = [ "charCount", "wordCount", "word", "upper", "lower", "extractFirstName", "extractMiddleName", "extractLastName", "left", "right", "concatenate", "getSpecificToken", "retrieveSubstring" ]; this.TIME_EXPRESSIONS = [ "hour", "minute" ]; // regex expressions this.DATE_REGEX = /^(0[1-9]|[1-2]\d|3[0-1])\/(0[1-9]|1[0-2])\/\d{4}$/; this.TIME_REGEX = /^(\d{1,2}):(\d{2})(?::(\d{2}))?$/; this.LOOP_COUNT_REGEX = /\s*(?<variable>[\w]+)\s*=\s*(?<EXP1>[0-9.+/*%()\s]*)\s?\k<variable>\s*(?<EXP2>[0-9.+/*%()\s]*)\s*(?<LOOPTYPE>UNTIL|WHILE){1}\s*\k<variable>\s*(?<CONDITION>[0-9.+/*%><=!gteqnl\s]*)\s*/; this.FOR_LOOP_REGEX = /\s*(?<COUNT>[0-9]+)\s*,\s*(?<variable>[\w]+)\s*=\s*(?<EXP1>[0-9.+/*%()\s]*)\s*\k<variable>\s*(?<EXP2>[0-9.+/*%()\s]*)\s*/; this.IF_ELSE_REGEX = /^\s*IF\s*([a-zA-Z0-9@,_$.:#&'\-+/*%><=!gteqnlandor\s]*)\s*((\([^)]+\))\s*([+\-/*%><=!gteqnlandor\s]*)\s*)*\s*ELSE\s*((\([^)]+\))\s*([+\-/*%><=!gteqnlandor\s]*)\s*)*\s*/i; this.DATE_FORMAT_REGEX = /^(?:\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d{3})?)?|\d{8}(?:\d{6})?|(?:\d{2}[-/]\d{2}[-/]\d{4}|\d{2} [A-Za-z]{3} \d{4}|\d{4}\/\d{2}\/\d{2})(?: (?:T)?\d{2}:\d{2}:\d{2}(?:\.\d{3})?)?|(?:\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(?:\.\d{3})?))$/; } } exports.Constants = Constants;