npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

scim2-ast

v0.3.2

Published

SCIM 2.0 filter parser with extended support for custom operators like in, nin, any, all, etc.

Readme

scim2-ast

SCIM 2.0 filter parser and serializer for Node.js and the browser. This package is an updated version of scim2-parse-filter (which itself was a fork of scim2-filter), modernized with new tooling, comprehensive tests, and extended with custom operators.

This library implements the filter syntax defined in RFC 7644 Section 3.4.2.2 (Filtering).

Features

  • Parse: Convert SCIM 2.0 filter strings into a typed Abstract Syntax Tree (AST).
  • Filter: Execute the AST against JSON objects to filter results in memory.
  • Stringify: Convert an AST back into a valid SCIM 2.0 filter string.
  • Extended Operators: Support for in, nin, any, all, regexp, and nil (null) values.
  • Adapters: Connect SCIM filters to various databases (e.g. MongoDB).
  • Modern Tooling: Built with TypeScript and tested with Vitest.

Installation

pnpm add scim2-ast
# or
npm install scim2-ast
# or
yarn add scim2-ast

Usage

Parsing a Filter

Convert a SCIM filter string into an AST object.

import { parse } from 'scim2-ast';

const ast = parse('userName eq "bjensen"');
console.log(ast);
/*
Output:
{
  op: "eq",
  attrPath: "userName",
  compValue: "bjensen"
}
*/

Filtering Data

Compile a parsed AST into a predicate function to filter arrays of objects.

import { parse, filter } from 'scim2-ast';

const users = [
  { userName: 'bjensen', active: true },
  { userName: 'jsmith', active: false }
];

const ast = parse('active eq true');
const predicate = filter(ast);

const activeUsers = users.filter(predicate);
// Result: [{ userName: 'bjensen', active: true }]

Stringifying an AST

Convert an AST object back into a SCIM filter string.

import { stringify } from 'scim2-ast';

const ast = {
  op: "eq",
  attrPath: "userName",
  compValue: "bjensen"
};

const filterString = stringify(ast);
// Result: 'userName eq "bjensen"'

Supported Operators

Standard SCIM 2.0 Operators

The following operators are defined in RFC 7644 Section 3.4.2.2.

| Operator | Description | Example String | Example AST | |----------|-------------|----------------|-------------| | eq | Equal | userName eq "bjensen" | { op: "eq", attrPath: "userName", compValue: "bjensen" } | | ne | Not Equal | active ne false | { op: "ne", attrPath: "active", compValue: false } | | co | Contains | title co "Manager" | { op: "co", attrPath: "title", compValue: "Manager" } | | sw | Starts With | userName sw "b" | { op: "sw", attrPath: "userName", compValue: "b" } | | ew | Ends With | userName ew "n" | { op: "ew", attrPath: "userName", compValue: "n" } | | gt | Greater Than | meta.lastModified gt "2011-05-13" | { op: "gt", attrPath: "meta.lastModified", compValue: "2011-05-13" } | | ge | Greater or Equal | age ge 18 | { op: "ge", attrPath: "age", compValue: 18 } | | lt | Less Than | priority lt 5 | { op: "lt", attrPath: "priority", compValue: 5 } | | le | Less or Equal | count le 10 | { op: "le", attrPath: "count", compValue: 10 } | | pr | Present (Has value) | title pr | { op: "pr", attrPath: "title" } | | and | Logical AND | title pr and active eq true | { op: "and", filters: [...] } | | or | Logical OR | title pr or active eq true | { op: "or", filters: [...] } | | not | Logical NOT | not (userType eq "Employee") | { op: "not", filter: { ... } } |

Array Handling

  • eq: If the attribute is an array, eq checks if the comparison value exists within that array (standard SCIM behavior for multi-valued attributes).
  • pr: Returns false if the attribute is an empty array [] (treats empty arrays as "not present").

Extended Operators

These operators are not part of the standard SCIM 2.0 spec but are supported by this library for enhanced filtering capabilities.

in

Checks if the attribute value exists in the provided array.

parse('userType in ["Employee", "Contractor"]');
// AST:
// {
//   op: "in",
//   attrPath: "userType",
//   compValue: ["Employee", "Contractor"]
// }

nin (Not In)

Checks if the attribute value does NOT exist in the provided array.

parse('userType nin ["Guest", "External"]');
// AST:
// {
//   op: "nin",
//   attrPath: "userType",
//   compValue: ["Guest", "External"]
// }

any

Checks if the array attribute has any intersection with the provided array (at least one match).

// Assuming 'roles' is an array like ["admin", "editor"]
parse('roles any ["admin", "root"]');
// AST:
// {
//   op: "any",
//   attrPath: "roles",
//   compValue: ["admin", "root"]
// }

all

Checks if the array attribute contains all of the values in the provided array.

// Assuming 'tags' is an array like ["red", "blue", "green"]
parse('tags all ["red", "blue"]');
// AST:
// {
//   op: "all",
//   attrPath: "tags",
//   compValue: ["red", "blue"]
// }

regexp

Checks if the attribute matches the regular expression pattern.

parse('userName regexp "^[a-z]+\\.[a-z]+$"');
// AST:
// {
//   op: "regexp",
//   attrPath: "userName",
//   compValue: "^[a-z]+\\.[a-z]+$"
// }

nil (Null) Support

You can explicitly compare against nil (which parses to null).

parse('name.middleName eq nil');
// AST:
// {
//   op: "eq",
//   attrPath: "name.middleName",
//   compValue: null
// }

Adapters

This library is designed to be extensible. Adapters allow you to convert SCIM ASTs into database specific queries.

| Adapter | Status | Description | | :--- | :--- | :--- | | scim2-ast-mongo | ✅ Available | Convert SCIM filters to MongoDB / Mongoose queries |

Contributing

Build

pnpm build

Test

pnpm test

License

MIT

Attributions

This project is an evolution of: