Parser for SCIM Filter Query Strings
JavaScript
Latest commit 141837e Dec 15, 2016 @mike-marcacci mike-marcacci cleanup
Permalink
Failed to load latest commit information.
.eslintrc write parser and tests Dec 14, 2016
.gitignore Initial commit Dec 14, 2016
.travis.yml
LICENSE Initial commit Dec 14, 2016
README.md update readme Dec 15, 2016
index.js add filter.test Dec 15, 2016
package.json
test.js add filter.test Dec 15, 2016

README.md

Build Status

tl;dr

    const Filter = require('scim-query-filter-parser');

    const filter = new Filter('userName eq "somebody123"');

    // get the parsed filter as an RPN stack
    const rpn = filter.rpn;

    // get the parsed filter as an expression tree
    const tree = filter.tree;

    // get the parsed filter as an expression tree
    const results = [
        {userName: 'somebody123'},
        {userName: 'somebody456'}
    ].filter(filter.test);

Description

This implements a parser for the filtering syntax defined in System for Cross-Domain Identity Management (SCIM) Protocol 1.1. It is originally a port of scim-query-filter-parser-rb and was built for use by AuthX;

This package can parse one of these filter queries and produce a Reverse Polish Notation (RPN) stack or expression tree.

It can also be used to test resources against the parsed filter query.

For example, parse this filter query string:

userType eq "Employee" and (emails co "example.com" or emails co "example.org")

Into this RPN stack (array):

['userType', '"Employee"', 'eq', 'emails', '"example.com"', 'co', 'emails', '"example.org"', 'co', 'or', 'and']

Or, optionally into this expression tree:

['and',
    ['eq',
        'userType',
        '"Employee"'],
    ['or',
        ['co',
            'emails',
            '"example.com"'],
        ['co',
            'emails',
            '"example.org"']]]

Methods & Properties

new Filter(filterQueryString, [preserveCase=false])

Parse a SCIM filter query and return a Filter object.

filter.rpn

Get the RPN array created by the most recent parse.

filter.tree

Get the parse result converted to a tree form.

filter.test(resource)

Tests a resource against a filter. This method is already bound to the filter, so that it can easily be used as an argument for Array.prototype.filter and similar methods.