Skip to content

About

A small language that compiles to Mapbox GL JS style expressions

Topics

Resources

Contributing

Stars

5 stars

Watchers

0 watching

Forks

Repository files navigation

mapbox-expr-lang

A small language that compiles to Mapbox GL JS style expressions.

npm version license

Playground • Guide • Operators • Grammar • Contributing

mapbox-expr-lang — write expressions naturally, compile them into Mapbox expressions


Write readable code, get back the JSON expression Mapbox expects.

var speed = get("speed")
var type = get("type")

if speed > 80 and type == "highway" then
  "red"
else
  "gray"

compiles to:

[
  "let",
  "speed",
  ["get", "speed"],
  "type",
  ["get", "type"],
  ["case", ["all", [">", ["var", "speed"], 80], ["==", ["var", "type"], "highway"]], "red", "gray"]
]

Install

npm install mapbox-expr-lang

Usage

import { compile } from "mapbox-expr-lang";

compile('get("speed") > 80');
// [">", ["get", "speed"], 80]

That's the whole API: one function. It throws on invalid source, with a message that says exactly what's wrong ('and' requires a boolean operand, but this is a number, Unknown function "typof", Variable "x" is not defined, ...) — never an internal detail you can't act on.

Docs

Contributing

Contributions of any size are welcome — a typo fix, a missing operator, a clearer error message.

git clone https://github.com/amine-a11/mapbox-expr-lang.git
cd mapbox-expr-lang
npm install
npm run test

See CONTRIBUTING.md for the full guide (project layout, available scripts, and what a PR should look like before it's opened).

License

MIT

About

A small language that compiles to Mapbox GL JS style expressions

Topics

Resources

Contributing

Stars

5 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages