View Source Plausible.Stats.FilterParser (Plausible v0.0.1)

A module for parsing filters used in stat queries.

Summary

Functions

Parses different filter formats.

Functions

Parses different filter formats.

Depending on the format and type of the filters argument, returns:

  • a decoded map, when filters is encoded JSON
  • a parsed filter map, when filters is a filter expression string
  • the same map, when filters is a map

Returns an empty map when argument type is unexpected (e.g. nil).

Examples:

iex> FilterParser.parse_filters("{\"page\":\"/blog/**\"}")
%{"page" => "/blog/**"}

iex> FilterParser.parse_filters("visit:browser!=Chrome")
%{"visit:browser" => {:is_not, "Chrome"}}

iex> FilterParser.parse_filters(nil)
%{}