Getting started

Introduction

Take a look at this introduction to have a better idea of what Expry is about.


Overview

Expressions are fundamental in coding, as they combine operations and variables to produce specific outcomes. Defined using our programming language syntax, expressions are the cornerstone of coding endeavors.

However, using these expressions beyond language constraints, such as for storage or network transmission, can be challenging. This is where Expry steps in, offering a solution to create expressions with JSON, for greater flexibility and ease of use.

Installation

To install this package you have to run the following command.

npm install expry

Usage

The core of this package is the expry function, and it is the one responsible to evaluate the expressions we define. It receives the following arguments:

  • expression: The expression we want to evaluate.

  • variables: The variables we want to use in the expression.

import { expry, Value, Variables } from "expry";

const expression: Value = {
  name: { $concat: ["$name", " ", "$surname"] },
  adult: { $gte: ["$age", 18] },
};

const variables: Variables = {
  name: "John",
  surname: "Doe",
  age: 21,
};

/**
 * {
 *   "name": "John Doe",
 *   "adult": true
 * }
 */
console.log(expry(expression, variables));

As you may have noticed, there are some properties that start with $. These are operators, and there are a lot of them available to be used.