@looker/filter-expressions
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

@looker/filter-expressions

This TypeScript package provides the necessary functions for transforming Looker filter expressions into data structures and localized text summaries – and vice versa.

getExpressionType

Returns a valid filter expression type when given the type and field properties of an IDashboardFilter object as defined in @looker/sdk.

getExpressionType({ field: { is_numeric: true }, type: 'field_filter' });
// 'number'

parseFilterExpression

Returns an Abstract Syntax Tree (AST) that logically represents the filter expression string passed in, as well as the filter expression type (and optional user attributes).

parseFilterExpression('number', '[0,20],>30');
// {
//   type: ',',
//   left: {
//     type: 'between',
//     bounds: '[]',
//     low: 0,
//     high: 20,
//     is: true,
//   },
//   right: {
//     is: true,
//     type: '>',
//     value: [30],
//   },
// }

summary

The summary function returns a localized, human-readable summary of a filter expression, given the expression's type, the expression itself, and the user attributes and field, if applicable.

summary('number', '[0,20],>30');
// 'is in range [0, 20] or is > 30'

typeToGrammar

Returns an object with utility functions and values pertaining to a given expression type:

  • toString: a function that converts an AST into an expression of the given type
  • subTypes: an array containing the sub-types of the expression type, for example ">", "<", "=", "between", etc, for a number expression type

getFilterTokenItem

Converts an AST to a single item for use in a token (i.e. not advanced) filter.

Readme

Keywords

none

Package Sidebar

Install

npm i @looker/filter-expressions

Weekly Downloads

256

Version

1.0.4

License

MIT

Unpacked Size

2.29 MB

Total Files

1136

Last publish

Collaborators

  • drstrangelooker
  • guyellis
  • looker-ops
  • scullin
  • jkaster
  • looker-open-source
  • fabio-looker
  • bryans99
  • mdodgelooker
  • dbchristopher
  • google-wombot