npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

expr-manager

v0.2.4

Published

Parse, validate, calc, and manage expression

Downloads

35

Readme

ExprManager

NPM version NPM downloads MIT License Travis Status Appveyor status Circleci status Coverage Status

Installation

npm install expr-manager

Usage

Simple calculation

var exprManager = new ExprManager();

var expr = "0.1 + 0.2";
var v = exprManager.calc(expr);
if (!v.errorMsg) {
    console.log(v.toValue());
    // => 0.3
} else {
    console.log(v.errorMsg);
}

var calcData = {v1: "hello", v2: "world"};
expr = "v1 + ' ' + v2 + '!'";
v = exprManager.calc(expr, calcData);
console.log(v.toValue());
// => "hello world!"

expr = "IIf(1 > 2, 'a', 'b')";
v = exprManager.calc(expr);
console.log(v.toValue());
// => "b"

expr = "123.ToString()"
v = exprManager.calc(expr);
console.log(v.toValue());
// => "123"

Advanced calculation

var dataContext = {
    "Table": {
        fields: {
            "Field0": { type: "number", primaryKey: true },
            "Field1": { type: "string" },
            "Field2": { type: "object" },
            "Field3": { type: "array" },
            "Field4": { type: "date" },
            "Field5": { type: "boolean" },
            "CalcField0": { type: "string" },
            "CalcField1": { type: "string" }
        },
        childs: {
            "SubTable": {
                fields: {
                    "Field0": { type: "number", primaryKey: true },
                    "Field1": { type: "string" },
                    "Field2": { type: "object" },
                    "Field3": { type: "array" },
                    "Field4": { type: "date" },
                    "Field5": { type: "boolean" }
                }
            }
        }
    }
};
var data = {
    Table: [{
        Field0: 0,
        Field1: "Hello",
        Field2: {key: "i", value: 0},
        Field3: [0, 1],
        Field4: new Date(),
        Field5: false,
        SubTable: [{
            Field0: 0,
            Field1: "Wrold",
            Field2: {key: "j", value: 10},
            Field3: [2, 3],
            Field4: new Date(),
            Field5: true
        }]
    }]
};
var context = {
    Field0: "!"
};

exprManager.init(data, dataContext, context);

var tableName = "Table";
var dataCursor = {
    "Table": 0,
    "Table.SubTable": 0
};
expr = "Field1 + ' ' + SubTable[0].Field1 + $C.Field0";
v = exprManager.calcExpr(expr, tableName, dataCursor);
console.log(v.toValue());
// => "Hello World!"

var t = exprManager.calcDependencies(expr, tableName);
console.log(t.dependencies);
// => ["Table.Field1", "Table.SubTable", "Table.SubTable.Field1"]

Advanced dependent calculation

exprManager.resetExpression();

var doCalc = function(type, info) {
    console.log(type);
};

exprManager.addExpression("Field1 + ' ' + SubTable[0].Field1",
    "Table", "CalcField0", ["load", "add", "update", "remove"],
    doCalc, null);
exprManager.addExpression("CalcField0 + SubTable.Count().ToString()",
    "Table", "CalcField1", ["load", "add", "update", "remove"],
    doCalc, null);

var errorMsg = exprManager.checkAndSort();
if (!errorMsg) {
    exprManager.calcExpression("load", {
        entityName: "Table"
    });
    // doCalc => "load"

    exprManager.calcExpression("add", {
        entityName: "Table"
    });
    // doCalc => "add"
    
    exprManager.calcExpression("update", {
        entityName: "Table",
        propertyName: "Field1"
    });
    // doCalc => "update"

    exprManager.calcExpression("remove", {
        entityName: "Table.SubTable"
    });
    // doCalc => "remove"
} else {
    console.log(errorMsg)
}

Value type

| Type | Value | | ----------- | ----------------------------------------- | | string | "value1" 'value2' | | number | 1 -1 1.23 -1.23 | | boolean | true false | | date | Now() "2017-10-24T10:10:10.037Z".ToDate() | | object | {a: 1, b: 2} {a: "1", b: "2"} | | array | [1,2] ["1","2"] | | null | null |

Operator precedence

| Operator | Description | | --------------- | ------------------------------------------------------------------ | | . [] () {} | Member access, array, grouping, object | | + - ! | Unary operators, logical NOT | | * / % | Multiplication, division, modulo division | | + - | Addition, subtraction | | < <= > >= | Less than, less than or equal, greater than, greater than or equal | | == != | Equality, inequality | | && | Logical AND | | || | Logical OR | | : | Colon operator | | , | Multiple evaluation |

System functions

| Owner | Functions | | ------- | --------------------------------------------------------------------------- | | | FieldDisplayName FieldName FieldValue IIf IfNull Now Parent PropValue Random RecNo Root | | array | Average Count Distinct Max Min Sum Where | | boolean | ToString | | date | DateOf DayOf DayOfWeek DaysBetween HourOf HoursBetween IncDay IncHour IncMinute IncMonth IncSecond IncWeek IncYear MilliSecondOf MilliSecondsBetween MinuteOf MinutesBetween MonthOf MonthsBetween SecondOf SecondsBetween ToString WeekOf WeeksBetween YearOf YearsBetween | | number | Abs Ceil Cos Exp Floor Ln Log Power Round Sin Sqrt Tan ToRMB ToString Trunc | | object | Parent RecNo | | string | LeftString Length Lower Pos Replace ReplaceReg RightString SubString ToDate ToNumber ToString Trim TrimLeft TrimRight Upper |

Example

npm install
npm start
open example/index.html

License

expr-manager.js is freely distributable under the terms of the MIT license.