Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@alpaca-travel/fexp-js

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@alpaca-travel/fexp-js

Functional expressions

  • 1.0.2-alpha.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

fexp-js - Functional Expressions in JavaScript

Simple modular expressions described in a portal format (JSON).

Syntax

The syntax: [[!]<name>, [param1[, param2[, ..., paramN]]]]

Evaluation

import { evaluate } from "@alpaca-travel/fexp-js";
import lang from "@alpaca-travel/fexp-js-lang";

// Expressions are just JSON strings
const expression = JSON.parse(`["==", ["get", "foo"], "bar"]`);

// Evaluate the expression against context
const result = evaluate(expr, lang, { foo: "bar" });
console.log(result); // Output; true

Core functions

  • Equality: ==, !=, <, >, <=, >=
  • Context: get
  • Deep Equality: equal/equals, !equal/!equals
  • Existence: has/have/exist/exists/empty, !has/!have/!exist/!exists/!empty
  • Membership: in/!in
  • Types: typeof, to-boolean, to-string, to-number, to-regex
  • Regular Expressions: "regex-test"
  • Combining: all/any/none
  • String manipulation: concat, uppercase, lowercase
  • Math: +, -, *, /, floor, ceil
  • more..

Declaring new functions

// My own function
const foobar = ([a, b]) => a * b;

// Example expression with our own function
const expression = JSON.parse(`["foobar", ["get", "foo"], ["get", "bar"]]`);
const result = evaluate(expression, { ...lang, foobar }, { foo: 2, bar: 3 });
console.log(result); // 6

FAQs

Package last updated on 16 Jun 2020

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc