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

@mapbox/expression-jamsession

Package Overview
Dependencies
Maintainers
199
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mapbox/expression-jamsession

Write Mapbox GL expressions in a more familiar, handwritable, spreadsheet-like, programming-like syntax.

  • 0.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.4K
increased by226.89%
Maintainers
199
Weekly downloads
 
Created
Source

@mapbox/expression-jamsession

Build Status

Write Mapbox GL expressions in a more familiar, handwritable, spreadsheet-like, programming-like syntax. This library translates these handwritten formulas into valid spec-compliant Mapbox GL expressions that you can use in a Mapbox style.

Formula syntax features

  • Arithmetic operators (+ - * /) and parentheses work like in high school math, e.g. ((3 + 4) * 2) / 7.
  • Expressions are represented like function invocations in programming, e.g. get("population"), log2(get("population")).
  • & operator concatenates strings, as in spreadsheet programs.
// Input
2 + 2

// Output
["+", 2, 2]
// Input
max(3, log2(6))

// Output
["max", 3, ["log2", 6]]
// Input
((3 + get("num")) * 2) / 7

// Output
["/", ["*", ["+", 3, get("num")], 2], 7]
// Input
"name: " & get("name")

// Output
["concat", ["name ", ["get", "name"]]]

Usage

The module exports two functions so you can transform in both directions:

  • formulaToExpression transforms (string) formulas to (array) expressions.
  • expressionToFormula transforms expressions to formulas.
import jamsession from '@mapbox/expression-jamsession';

jamsession.formulaToExpression("3 + 4"); // ["+", 3, 4]

jamsession.expressionToFormula(["+", 3, 4]); // "3 + 4"

Caveats

  • You can use this library to create expressions that are syntactically acceptable but invalid as Mapbox GL expressions, e.g. notARealExpression(true) outputs ["notARealExpression", true].

FAQs

Package last updated on 17 Jan 2018

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