View Source Plausible.Stats.Filters (Plausible v0.0.1)
A module for parsing filters used in stat queries.
Summary
Functions
Gets the first top level filter with matching dimension (or nil).
Parses different filter formats.
Updates filters via transformer
.
Functions
Gets the first top level filter with matching dimension (or nil).
Only use in cases where it's known that filters are only set on the top level as it does not handle AND/OR/NOT!
Parses different filter formats.
Depending on the format and type of the filters
argument, returns:
- a decoded list, when
filters
is encoded JSON - a parsed filter list, when
filters
is a filter expression string - the same list, when
filters
is a map
Returns an empty list when argument type is unexpected (e.g. nil
).
Examples:
iex> Filters.parse("{\"page\":\"/blog/**\"}")
[[:matches_wildcard, "event:page", ["/blog/**"]]]
iex> Filters.parse("visit:browser!=Chrome")
[[:is_not, "visit:browser", ["Chrome"]]]
iex> Filters.parse(nil)
[]
Updates filters via transformer
.
Transformer will receive each node (filter, and/or/not subtree) of query and must return a list of nodes to replace it with or nil to ignore and look deeper.