🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

seljs

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

seljs

Simple Expression Language for JavaScript

Source
npmnpm
Version
0.1.3
Version published
Weekly downloads
6
-14.29%
Maintainers
1
Weekly downloads
 
Created
Source

Simple Expression Language for JavaScript

Build Status

Requirements:

  • Nodejs 4+

Install

npm install seljs --save

Features

  • No side effects: only and expression language
  • Fast and simple: small memory footprint
  • No dependencies
  • Simplified property access

Language features

Very limited at the moment.

  • Basic arithmetic: Adding, subtraction, Multiplication and Division
  • Context and property access
  • Literals: Strings and integers
  • String concatenation

Work in progress

  • Boolean operators: And, or, equals, not equals, negate.
  • Grouping
  • null keyword
  • Functions
  • Global functions
  • Language documentation

Examples

const seljs = require("seljs"),
    assert = require("assert"),
    ctx = {
        int: 123,
        str: "123",
        obj: {
            int: 321,
            str: "321",
            obj: {
                deep: 333
            }
        }
    };

//Number literals
assert.strictEqual(seljs("123", ctx), 123);

//String literals
assert.strictEqual(seljs("'123'", ctx), "123");

//Basic arithmetic
assert.strictEqual(seljs("1 + 3 * 2 / 4 - 1 * 2", ctx), 1 + 3 * 2 / 4 - 1 * 2);

//String concatenation
assert.strictEqual(seljs("'123' + '123'", ctx), "123123");

//Context and property access
assert.strictEqual(seljs("int + obj.int + obj.obj.deep", ctx), 123 + 321 + 333);

License

MIT

FAQs

Package last updated on 25 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts