Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

easy-path-expressions

Package Overview
Dependencies
Maintainers
3
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

easy-path-expressions

Easy-path-expressions is a syntax parser that converts basic mathematical expressions into FHIRPath notation.

latest
npmnpm
Version
3.1.0
Version published
Maintainers
3
Created
Source

Easy Path Expressions

Easy-path-expressions is a syntax parser that converts basic mathematical expressions into FHIRPath notation.

Local Installation

npm install

To test that easy-path-expressions is working correctly:

npm test

Usage

import * as easyPathExpressions from 'easy-path-expressions';
easyPathExpressions.fhirConvert("(a+b)^2", ["a", "b"]); // returns ($a+$b).power(2)
easyPathExpressions.fhirConvert("CEILING(a*b)", ["a", "b"]); // returns ($a*$b).ceiling()

fhirConvert is the main function of easy-path-expressions, which validates and converts an inputted expression to fhirpath. fhirConvert will also return null if the expression fails validation.

fhirConvert takes in two inputs: the mathematical expression for conversion and an array of usable variables. The format is as follows:

fhirConvert([expression], [vars])

Basic syntax expressions utilize traditional operators and function statements. Expressions can be written using variable names, mathematical operators, and various functions. The syntax guide is bellow.

Syntax Guide

USABLE OPERATORS: +, -, *, /, ^, **, !=, !~, >=, <=, =, &&, ||, xor, and, or, implies

USABLE FUNCTIONS: CEILING(), FLOOR(), ABS(), LOG(), TRUNCATE(), EXP(), SQRT(), LN(), NOT(), LENGTH()

  • Usage: CEILING([expression]), FLOOR([expression]), etc.

LOG()

  • Usage: LOG([Base], [Value])

USABLE VARIABLES: Any string of letters and numbers differing from the aforementioned functions.

EXAMPLE EXPRESSIONS (vars: [a, b, c]): 2+2 (a+b)^3 CEILING(LOG(2, 17)) TRUNCATE(ABS(-3.3)) + SQRT(LN(a+b+c))

EXAMPLE OUTPUTS:

INPUT: fhirConvert("2+2", ["a", "b", "c", "d"]) OUTPUT: "2+2"

INPUT: fhirConvert("(a+b)^3", ["a", "b", "c", "d"]) OUTPUT: "((%a+%b).power(3))"

INPUT: fhirConvert("CEILING(LOG(2, 17))", ["a", "b", "c", "d"]) OUTPUT: "((17.log(2)).ceiling())"

INPUT: fhirConvert("TRUNCATE(ABS(-3.3))+SQRT(LN(a+b+c))", ["a", "b", "c", "d"]) OUTPUT: "((-3.3).abs()).truncate()+((%a+%b+%c).ln()).sqrt()"

FAQs

Package last updated on 03 Feb 2022

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