Registry / storage / power-filter

power-filter

JSON →
library0.1.9jsnpmunverified

Filter arrays of objects using MongoDB-like query operators. Version 0.1.9. Part of the Phenyl framework, it supports operators such as $and, $or, $nor, $regex, $gte, $in, $exists, and many more. The query format is compatible with MongoDB's query operators, allowing complex filtering with nested field paths (e.g., 'foo.bar[0].baz'). It provides a lightweight, zero-dependency solution for in-memory filtering. Compared to similar libraries like 'mingo' or 'sift', power-filter is focused on simplicity and TypeScript/Flow support via the 'mongolike-operations' module.

npm install power-filter
INSTALL
IMPORT
SIG · POWER-FILTER
P
power-filter
storagejavascriptv0.1.9
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

filter
import { filter } from 'power-filter'
import filter from 'power-filter'
The package exports a named function 'filter', not a default export. Common JS users: const { filter } = require('power-filter').
filter (Flow types)
import { filter } from 'power-filter/jsnext'
import { filter } from 'power-filter'
For Flow type annotations, use the '/jsnext' entrypoint. This is specific to Flow; TypeScript users can use the main entry.

Imports the filter function and uses it to filter an array of objects with $or, $gte, and $regex operators.

import { filter } from 'power-filter'; const objs = [ { name: 'John', age: 25 }, { name: 'Naomi', age: 30 }, { name: 'Shin', age: 20 }, ]; // Filter using MongoDB-like operators const result = filter(objs, { $or: [ { age: { $gte: 25 } }, { name: { $regex: /n$/i } } ] }); console.log(result); // [{ name: 'John', age: 25 }, { name: 'Naomi', age: 30 }, { name: 'Shin', age: 20 }]
Debug
Known issues
deprecatedThe $where operator is listed in documentation as 'To Be Implemented' and is not supported.
fix
Do not use $where. Use $expr or other operators instead, or implement custom filtering.
affects: <=0.1.9
deprecatedThe geospatial operators ($geoIntersects, $geoWithin, $near, $nearSphere) are listed as 'To Be Implemented' and are not supported.
fix
Do not use geospatial operators. They are not implemented.
affects: <=0.1.9
gotchaThe $options operator must be used with $regex as a string; it does not accept RegExp flags object.
fix
Use $regex with a RegExp object that includes flags, or use $options as a string (e.g., { $regex: 'pattern', $options: 'i' }).
affects: <=0.1.9
Errors
Common errors & fixes
Cannot find module 'power-filter'
The package is not installed or imported incorrectly.
fix
Run 'npm install power-filter' (or 'yarn add power-filter'). Ensure you are using 'import { filter } from 'power-filter' (not default import).
TypeError: filter is not a function
Using a default import instead of named import.
fix
Use 'import { filter } from 'power-filter' (curly braces) instead of 'import filter from 'power-filter'.
TypeError: power_filter.filter is not a function (CommonJS)
Using require incorrectly.
fix
Use 'const { filter } = require('power-filter')' (destructure) instead of 'const filter = require('power-filter')'.
Upgrade
Version history
0.1.9latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
12
Amazon
1
Resources
power-filter — npm install power-filter · libregistry