Registry / database / obop
library1.0.0jsnpmunverified

MongoDB-style object operators for array manipulation: where (filter), order (sort), update (transform), and view (project). v1.0.0 stable, published under MIT. Provides MongoDB-like query selectors ($gt, $in, $or, $exists, etc.), sort parameters, and update operators ($set, $inc, $push) as standalone functions that can be used directly on arrays or passed to Array.filter, Array.sort, Array.forEach. Supports ESM, CommonJS, and browser builds (unpkg/CDN). Differentiator: lightweight (<5KB gzip), zero dependencies, and familiar MongoDB API for anyone transitioning from backend to frontend.

npm install obop
INSTALL
IMPORT
SIG · OBOP
O
obop
databasejavascriptv1.0.0
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.

default
import obop from 'obop'
const obop = require('obop')
ESM default export is a pre-initialized function object with .where, .order, .update, .view methods. In CommonJS, you must call require('obop')() to initialize.
where
import obop from 'obop'; obop.where(array, query)
import { where } from 'obop'
where is not a named export; it is a method on the default exported function. You can also use array.filter(obop.where(query)) for curried style.
order
import obop from 'obop'; obop.order(array, sortSpec)
import { order } from 'obop'
order is a method on the default export. Curried: array.sort(obop.order(sortSpec)).
update
import obop from 'obop'; obop.update(array, updateSpec)
import { update } from 'obop'
update modifies array elements in place. Curried: array.forEach(obop.update(updateSpec)).

Filter, sort, and update an array of objects using MongoDB-style operators with obop.

import obop from 'obop'; const inventory = [ { item: 'apple', type: 'fruit', qty: 15, price: 1.2 }, { item: 'banana', type: 'fruit', qty: 5, price: 0.8 }, { item: 'carrot', type: 'vegetable', qty: 20, price: 0.5 } ]; // Filter: get fruits with qty >= 10 const results = inventory.filter(obop.where({ type: 'fruit', qty: { $gte: 10 } })); console.log(results); // [{ item: 'apple', type: 'fruit', qty: 15, price: 1.2 }] // Sort: by price descending, then qty ascending const sorted = inventory.sort(obop.order({ price: -1, qty: 1 })); console.log(sorted.map(i => i.item)); // ['apple', 'banana', 'carrot'] // Update: set qty to 0 for items with price > 1 inventory.forEach(obop.update({ $set: { qty: 0 } })); console.log(inventory); // all items have qty 0
Debug
Known issues
gotchaCalling require('obop') without invoking as a function gives an object with methods that expect to be called on an array, but the static methods (where, order, update) will not work unless the function is called first.
fix
Use const obop = require('obop')(); or import obop from 'obop'.
affects: >=1.0.0
gotchaobop.update mutates the original array elements in place. It does not create a new array.
fix
Ensure you intend to mutate or use a shallow copy before calling update: const copy = array.map(o => ({...o})); obop.update(copy, updateSpec);
affects: >=1.0.0
deprecatedThe $gt and $gte operators when combined with $lt or $lte for the same field must be passed as separate keys in the object (e.g., {field: {$gt: 10, $lt: 20}}). Not a breaking change but a common misuse.
fix
Use {field: {$gt: 10, $lt: 20}} instead of nesting under a single operator.
affects: >=1.0.0
gotchaWhen using the curried form (array.filter(obop.where(query))), obop.where may throw if query is not a plain object.
fix
Ensure query is a valid JavaScript object. For empty query, use {}.
affects: >=1.0.0
Errors
Common errors & fixes
obop is not a function
Calling obop.where(...) without initializing the module (CommonJS) or using named import incorrectly.
fix
Use const obop = require('obop')(); or import obop from 'obop'.
Cannot read property 'where' of undefined
Using destructured import like import { where } from 'obop' but where is not a named export.
fix
Use import obop from 'obop' then obop.where(...).
TypeError: obop.where is not a function
Using the module as a constructor or calling require('obop') without parentheses (returns the function, not its methods).
fix
Use obop = require('obop')(); or obop = obopInit(); from ESM default.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
packageobop
obop — npm install obop · libregistry