scim2-filter
raw JSON → 0.2.0 verified Sat Apr 25 auth: no javascript
A parser and evaluator for RFC 7643 SCIM 2.0 filter syntax. Version 0.2.0 allows parsing filter expressions into an AST and applying them as JavaScript functions to filter JSON objects. Supports operators (eq, co, sw, pr, gt, ge, lt, le, and, or, not) and complex filters with attribute paths and value filters. Lightweight, dependency-free, and ESM-only. No TypeScript types provided. Differentiates from generic query parsers by adhering strictly to SCIM 2.0 filtering grammar.
Common errors
error SyntaxError: Cannot use import statement outside a module ↓
cause Using ESM import in a CommonJS context (e.g., Node.js without 'type':'module' in package.json).
fix
Add "type": "module" to package.json or use .mjs extension for importing file.
error TypeError: parse is not a function ↓
cause Incorrect import: using default import instead of named import.
fix
Use
import { parse } from 'scim2-filter' instead of import parse from 'scim2-filter' or const parse = require('scim2-filter'). error Uncaught TypeError: filter(...) is not a function ↓
cause The filter function returns a predicate, but it's being called on non-array or used incorrectly.
fix
Ensure the result of
filter(parse(...)) is a function; use it as a callback to Array.filter(). Warnings
gotcha Package has no TypeScript type declarations. Use with TypeScript may require 'any' casts or custom type definitions. ↓
fix Install @types/scim2-filter if available or add a declaration file manually. Alternatively, use JSDoc comments for type hints.
gotcha The `filter` function returns a predicate that expects array elements to be objects. Non-object elements may cause runtime errors or unexpected behavior. ↓
fix Ensure input data consists of plain JavaScript objects.
gotcha This package only parses and evaluates filters; it does not handle SCIM attribute validation, complex attribute names with sub-attributes, or proper escaping beyond the spec. Use with caution in production. ↓
fix Validate filter syntax and implement additional attribute handling as needed.
deprecated No deprecated features identified; however, version 0.2.0 may have limited support for all SCIM 2.0 filter operators (e.g., 'pr' for presence). ↓
fix Check the package source for supported operators; consider contributing missing features.
Install
npm install scim2-filter yarn add scim2-filter pnpm add scim2-filter Imports
- parse wrong
const parse = require('scim2-filter')correctimport { parse } from 'scim2-filter' - filter wrong
const filter = require('scim2-filter').filtercorrectimport { filter } from 'scim2-filter' - types (AST types) wrong
No wrong pattern knowncorrectimport type { ScimFilter, FilterOperator } from 'scim2-filter'
Quickstart
import { parse, filter } from 'scim2-filter';
const ast = parse(`userType eq "Employee" and emails[type eq "work" and value co "@example.com"]`);
console.log(JSON.stringify(ast, null, 2));
const userFilter = filter(parse(`userName eq "test1@example.com"`));
const users = [
{ userName: "test1@example.com" },
{ userName: "test2@example.com" }
];
const result = users.filter(userFilter);
console.log(result); // [{ userName: "test1@example.com" }]