GithubHelp home page GithubHelp logo

mrchenmo / dartfx Goto Github PK

View Code? Open in Web Editor NEW

This project forked from youngchan1988/dartfx

0.0 0.0 0.0 2.25 MB

A simple lightly function expression runner for dart and javascript

License: BSD 3-Clause "New" or "Revised" License

JavaScript 18.21% C++ 0.82% C 0.06% Objective-C 0.01% Kotlin 0.01% Dart 79.43% TypeScript 0.68% Swift 0.05% Makefile 0.01% HTML 0.15% CMake 0.62%

dartfx's Introduction

1642346505729.png

This project was developed on dart-analyzer

Features

Support dart and javascript both.

Operators

+, -, *, /, ~/, %, -(Negative), >, <, ==, >=, <=, !=, &&, ||, !, &, |,
~, ^, >>, <<, =, +=, -=, &=, |=, ^=, >>=, <<=, expr1 ? expr2 : expr3

The operator doc : Operators | Dart

Internal Functions

Function Comment
num ABS(num a) Return absolutely value of number.
num SUM(List list) Return sum value of a number set.
double AVERAGE(List list) Return average value of a number set.
num ROUND(num value, int digit) Return number value closest to this and limit digits after the decimal point.
String FIXED(num value, int digit) Return string value closest to this and limit digits after the decimal point.
int INTCEIL(num value) Return the least integer value no smaller than this.
int INTFLOOR(num value) Return the greatest integer value no greater than this.
num POW(num x, num exp) Returns x to the power of exp.
num SQRT(num x) Converts x to a double and returns the positive square root of the value.
bool CONTAIN(List list, List sub) Return list is contains all elements in sub.
bool ISEMPTY(dynamic value) Return value is empty or not. The value should be one of String, List or Map.
num MAX(num a, num b, [num c, ...]) Return the max value of number arguments.
num MIN(num a, num b, [num c, ...]) Return the min value of number arguments.
num VALUE(String a) Convert string to number.
bool REGMATCH(String source, r{String reg}) Return the string is match regular rule, true of false. The reg argument need a prefix char r. eg: r"1[0-9]\d{9}$" .
String SUBSTRING(String s, int start, [int length]) Return sub string.
String REPLACESTRING(String soruce, String old, String new) Replace sub string by a new one. And return the new string.
String TIMEFORMAT(int timestamp, String pattern) Return the formated timestamp. The pattern could be "yyyy-MM-dd HH:mm:ss".
int TIMESTAMP(String dateString, String pattern) Return the timestamp value that parse from a string.

Getting started

dependencies:
    dartfx: ^1.0.13

To build jsfx.

make buildjs

Usage

Dart:

import 'package:dartfx/dartfx.dart';

void main(){
  var result = fx("1+(2+3)*7-4");
  print('Fx output: $result');

  var envs = {
    "43858": {"message": "hello"},
    "43859": {"currency": "100", "unitName": "Yuan"}
  };

  result = fxWithEnvs('\$43859.currency\$+\$43859.unitName\$', envs);
  print('Fx output: $result');

  result = fxAssignment('\$43858.message\$=\$43859.currency\$+\$43859.unitName\$', envs);
  print('Fx output: ${envs["43858"]["message"]}');

  fxSetFunctionApply((name, arguments) {
    if (name == 'RMB') {
      return '¥${arguments.first}';
    }
  });
  result = fx('RMB(100)');
  print('Fx output: $result');
}

JS:

import { fx, fxWithEnvs, fxAssignment, fxSetFunctionApply } from './jsfx';

console.log(fx('1+(2+3)*7 - 4/2'));

var envs = {
    "43858": { "message": "hello" },
    "43859": { "currency": "100", "unitName": "Yuan" }
};
console.log(fxWithEnvs('\$43859.currency\$+\$43859.unitName\$', envs));

var result = fxAssignment('\$43858.message\$=\$43859.currency\$+\$43859.unitName\$', envs);
console.log(envs["43858"]["message"]);

fxSetFunctionApply((...args) => {
    var funcName = args[0];
    if (funcName == 'RMB') {
        var value = args[1];
        return ${value}`;
    }
});
console.log(fx('RMB(100)'));

More usage check the test case: test/dartfx_test.dart & js/jsfx.test.ts

License

See LICENSE

dartfx's People

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.