GithubHelp home page GithubHelp logo

Pip.Services Logo
Tokenizers, parsers and expression calculators in Node.js

This module is a part of the Pip.Services polyglot microservices toolkit. It provides syntax and lexical analyzers and expression calculator optimized for repeated calculations.

The module contains the following packages:

  • Calculator - Expression calculator
  • CSV - CSV tokenizer
  • IO - input/output utility classes to support lexical analysis
  • Mustache - Mustache templating engine
  • Tokenizers - lexical analyzers to break incoming character streams into tokens
  • Variants - dynamic objects that can hold any values and operators for them

Quick links:

Use

Install the NPM package as

npm install pip-services3-expressions-node --save

The example below shows how to use expression calculator to dynamically calculate user-defined expressions.

import { IConfigurable } from 'pip-services3-commons-node';
import { ConfigParams } from 'pip-services3-commons-node';
import { IReferenceable } from 'pip-services3-commons-node';
import { IReferences } from 'pip-services3-commons-node';
import { Descriptor } from 'pip-services3-commons-node';
import { IOpenable } from 'pip-services3-commons-node';

...
let calculator = new ExpressionCalculator();

calculator.expression = "A + b / (3 - Max(-123, 1)*2)";

let vars = new VariableCollection();
vars.add(new Variable("A", new Variant(1)));
vars.add(new Variable("B", new Variant("3")));

calculator.evaluateWithVariables(vars, (err, result) => {
    console.log("The result of the expression is " + result.asString);
    ...
});
...

This is an example to process mustache templates.

let mustache = new MustacheTemplate();
mustache.template = "Hello, {{{NAME}}}{{#ESCLAMATION}}!{{/ESCLAMATION}}{{#unless ESCLAMATION}}.{{/unless}}";
let result = mustache.evaluateWithVariables({ NAME: 'Mike', ESCLAMATION: true });
console log("The result of template evaluation is '" + result + "'");

Develop

For development you shall install the following prerequisites:

  • Node.js 8+
  • Visual Studio Code or another IDE of your choice
  • Docker
  • Typescript

Install dependencies:

npm install

Compile the code:

tsc

Run automated tests:

npm test

Generate API documentation:

./docgen.ps1

Before committing changes run dockerized build and test as:

./build.ps1
./test.ps1
./clear.ps1

Contacts

The module is created and maintained by Sergey Seroukhov.

pip-services3-node's Projects

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.