Skip to content

Repository files navigation

expression-utils-java

Java utility library (with static methods) to parse array-based nested expressions.

GitHub release (latest SemVer)GitHub Workflow Status (with branch)GitHub issuesEko.inTwitterTwitter FollowDiscord Chat


Installation

  • In the Packages section, select the package expression-utils-java.lib
  • Follow the installation instructions
  • Or, download the library jar file and include in your Java project

Usage

  • See the Javadoc for detailed documentation.
  • See the test cases for detailed usage examples.

Example

importin.eko.exprutils.ExpressionParser;
// Single expression example: 2 + 3
(int)ExpressionParser.parseExpression("['+', 2, 3]"); // returns 5// Nested expression example: 2 + (3 * 4)
(int)ExpressionParser.parseExpression("['+', 2, ['*', 3, 4]]"); // returns 14

Available functions:

ClassMethodInputsOutputDesc
ExpressionParserparseExpression()expression (string encoded Json array)parsed value (Object)returns parses an expression
isValidOperator()String operatorbooleanChecks if the provided operator is supported by the expressionParser
interpolate()String expr, Map<String, String> datainterpolated stringInterpolate/replace values of dollar-curly-brace-wrapped variables into a string
HashgetHash()String input, String typehashGenerate hash of a string using the type algorithm (MD5, SHA-256, etc)
sha256()String inputsha-256 hashGenerate SHA-256 hash of a string
sha512()String inputsha-512 hashGenerate SHA-512 hash of a string
md5()String inputmd5 hashGenerate md5 hash of a string
JsonObjget()String/JSONObject obj, String key, String default_valuevalue (Object)Retrieve deep/nested value from a JSON Object
set()String obj, String key, Object valueobject (String)Set a key-value pair deep within a JSON Object
JWTgenerate()...generated tokenGenerate JWT (token) with the given configuration
parse()...claim mapValidates & parses a JWT (token)

Operators supported by the parseExpression() function:

OperatorPurposeExpression ExampleResult
+Add['+', 2, 3]5
-Subtract['-', 3, 2]1
*Multiply['*', 2, 3]6
/Divide['/', 4, 2]2
CONCATConcatenate string['CONCAT', 'Hello', 'World']HelloWorld
GETGet nested-value from object['GET', {'b':{'d':{'e':3}}}, 'b.d.e']3
SETSet nested-value into object['SET', {'b':{'d':{}}}, 'b.d.e', 4]{'b':{'d':{'e':4}}}
SHA256Get sha-256 hash['SHA256', 'hello world']b94d27...cde9
SHA512Get sha-512 hash['SHA512', 'hello world']309ecc48...cd76f
MD5Get MD5 hash['MD5', 'hello world']5eb63...5acdc3
JWTGenerate JWT['JWT', '<secret-key>', 'HS256', '{"issuer":...}']generated token

Contribution Guide

Local Test

  • ./gradlew test --info

Local Build

  • ./gradlew build

Publish New Release

  • Make sure to update the version number in the lib/build.gradle file
  • Merge changes into the main branch
  • Goto the Releases section and create a new release
  • A new build will automatically be created and published to Github Packages

About

Java utility library to parse array-based nested expressions.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages