AshBackendDrivenOptimisticUi.JsonLogic (AshBackendDrivenOptimisticUi v0.1.0)

Copy Markdown View Source

Evaluates JSON Logic the way the client does: the full standard (var, missing, missing_some, if, ?:, == != === !==, ! !!, or, and, > >= < <= including the three-operand "between" form, max, min, + - * / %, map, filter, reduce, all, none, some, merge, in, cat, substr, log), checked against the official JSON Logic test suite, plus five custom operations: has (whether a dotted path's last key is present, even with a null value), abs, round (one or two operands, half away from zero), to_string (nil becomes empty text) and now (the current UTC time as ISO 8601 text). Literals pass through and a list that is not an operation evaluates each element.

Where JavaScript would produce NaN, which JSON cannot carry, this raises ArgumentError instead: arithmetic (+ - * / % min max abs round) accepts only numbers and numeric strings. An unknown operation, or a map holding more than one operation, raises too. Comparison with <, >, <= and >= never raises: two texts compare as text, anything else compares as numbers, and a side that is not numeric makes the result false.

cat prints nil as null and a whole float without its fraction.

Summary

Functions

Evaluates rule against data, a map with string keys.

JSON Logic truthiness: everything but false, nil, 0, "" and [].

Functions

run(rule, data)

@spec run(term(), term()) :: term()

Evaluates rule against data, a map with string keys.

truthy?(value)

@spec truthy?(term()) :: boolean()

JSON Logic truthiness: everything but false, nil, 0, "" and [].