Git Product home page Git Product logo

easeeval's Introduction

EaseEval

GitHub license GitHub go.mod Go version Go Report Card Build codecov

EaseEval is a simple text eval tool, built on DSL, written in Go.

Note: To not reinvent the wheel, please use https://github.com/Knetic/govaluate

Quick Start

Install

go get github.com/samanhappy/easeeval

Example

// use jq to extract value from json, v should be 7(int64)
v, err = easeeval.Eval(`1 + jq(".key") * 3`, `{"key":"2"}`)

// use time functions, v should be true(bool)
v, err = easeeval.Eval(`unixTime(jq(".time")) < now()`, `{"time":"2022-08-01T12:00:00"}`)

Overview

EaseEval is designed to extract values from text and evaluate expressions using a DSL, which contains Function, Typecast and Compute.

Function

Function is very useful in many scenarios, we plan to supply different kind of functions.

Extract Function

Extract functions extract target values from source text in many types: plain text, json, html, xml, etc.

Name Description Usage
jq extract values from json format text using https://github.com/savaki/jq jq(".key")
regex extract values from text using regex (to be implemented)

Time Function

Time functions supply ways to get unix time from string or for now.

Name Description Usage
unixTime return unix time seconds in int64 for any format string using https://github.com/araddon/dateparse unixTime("2022-08-01T12:00:00")
now return unix time seconds in int64 for now now()

Typecast

Typecast auto converts values on demand to specific types like string, number, date, etc. We support types below.

Name Description
bool bool type can be used in assertions
int64 int64 is the only int type supported, other int type like int8,int32 and int strings will auto be converted to int64
Time Time type will be converted to int64 for compute

Compute

Compute does the actual eval work for different kind of operators.

Kind Operators
logical && || !
arithmetic + - * /
relational > < == != >= <=

easeeval's People

Contributors

samanhappy avatar dependabot[bot] avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.