Skip to main content

README.md

# fexpr

[![Package Version](https://img.shields.io/hexpm/v/fexpr)](https://hex.pm/packages/fexpr)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/fexpr/)

A filter query executor for Gleam.

This library was heavily inspired by [fexpr](https://github.com/ganigeorgiev/fexpr) for Go.

```sh
gleam add fexpr@1
```
```gleam
import fexpr

pub fn main() -> Nil {
  let user_json =
    json.object([
      #("id", json.string("user_123456")),
      #("username", json.string("Remy")),
      #("balance", json.float(250.5)),
      #("last_connection", birl.now() |> birl.to_iso8601() |> json.string),
      #("is_admin", json.bool(True)),
      #(
        "settings",
        json.object([
          #("theme", json.string("dark")),
          #("notifications", json.bool(False)),
        ]),
      ),
    ])

  let res =
    fexpr.verify_fexpr(
      fexpr.fexpr("is_admin", fexpr.Equal, fexpr.Bool(True))
        |> fexpr.and("settings.theme", fexpr.Equal, fexpr.String("dark")),
      json.to_string(user_json),
    )
  assert res == True

  let res =
    fexpr.verify_fexpr(
      fexpr.fexpr("balance", fexpr.Greater, fexpr.Float(100.0))
        |> fexpr.or("settings.notifications", fexpr.Equal, fexpr.Bool(True)),
      json.to_string(user_json),
    )
  assert res == True
}
```

Further documentation can be found at <https://hexdocs.pm/fexpr>.

## Development

```sh
gleam run   # Run the project
gleam test  # Run the tests
```