@nexssp/expression-parser
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

@nexssp/expression-parser

Lightweight JavaScript expression parser with error diagnostics and object interpolation.

Features

  • Safe evaluation of embedded JavaScript expressions
  • Intelligent variable name suggestions for undefined variables
  • Recursive object parsing
  • Clear error reporting with ANSI formatting

Installation

npm install @nexssp/expression-parser

Usage

Basic Expression Parsing

const { expressionParser } = require("@nexssp/expression-parser");

const data = { a: 5, b: 10 };
console.log(expressionParser("Sum: ${a + b}", data));
// Output: "Sum: 15"

Object Data Parsing

const { parseData } = require("@nexssp/expression-parser");

const template = {
  greeting: "Hello ${name}!",
  calculation: "${x * y}",
  nested: {
    value: "${Math.PI.toFixed(2)}"
  },
  omitted: "Will not parse: ${undefined}"
};

const result = parseData(template, ["omitted"]);
console.log(result);
/* Output:
{
  greeting: "Hello John!",
  calculation: 50,
  nested: { value: "3.14" },
  omitted: "Will not parse: ${undefined}"
}
*/

Error Handling

Error Example

API

expressionParser(exp, data)

Evaluates expressions in strings while handling errors gracefully.

parseData(object, omittedKeys)

Recursively processes object values, skipping specified keys.

Security

Important: Uses JavaScript evaluation - only use with trusted input sources.

Readme

Keywords

Package Sidebar

Install

npm i @nexssp/expression-parser

Homepage

nexss.com

Weekly Downloads

4

Version

1.0.5

License

MIT

Unpacked Size

15 kB

Total Files

10

Last publish

Collaborators

  • nexss