{"id":43500,"library":"obop","title":"obop","description":"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.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/kawanet/obop","tags":["javascript","array","filter","map","mongodb","sort"],"install":[{"cmd":"npm install obop","lang":"bash","label":"npm"},{"cmd":"yarn add obop","lang":"bash","label":"yarn"},{"cmd":"pnpm add obop","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM default export is a pre-initialized function object with .where, .order, .update, .view methods. In CommonJS, you must call require('obop')() to initialize.","wrong":"const obop = require('obop')","symbol":"default","correct":"import obop from 'obop'"},{"note":"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.","wrong":"import { where } from 'obop'","symbol":"where","correct":"import obop from 'obop'; obop.where(array, query)"},{"note":"order is a method on the default export. Curried: array.sort(obop.order(sortSpec)).","wrong":"import { order } from 'obop'","symbol":"order","correct":"import obop from 'obop'; obop.order(array, sortSpec)"},{"note":"update modifies array elements in place. Curried: array.forEach(obop.update(updateSpec)).","wrong":"import { update } from 'obop'","symbol":"update","correct":"import obop from 'obop'; obop.update(array, updateSpec)"}],"quickstart":{"code":"import obop from 'obop';\n\nconst inventory = [\n  { item: 'apple', type: 'fruit', qty: 15, price: 1.2 },\n  { item: 'banana', type: 'fruit', qty: 5, price: 0.8 },\n  { item: 'carrot', type: 'vegetable', qty: 20, price: 0.5 }\n];\n\n// Filter: get fruits with qty >= 10\nconst results = inventory.filter(obop.where({ type: 'fruit', qty: { $gte: 10 } }));\nconsole.log(results); // [{ item: 'apple', type: 'fruit', qty: 15, price: 1.2 }]\n\n// Sort: by price descending, then qty ascending\nconst sorted = inventory.sort(obop.order({ price: -1, qty: 1 }));\nconsole.log(sorted.map(i => i.item)); // ['apple', 'banana', 'carrot']\n\n// Update: set qty to 0 for items with price > 1\ninventory.forEach(obop.update({ $set: { qty: 0 } }));\nconsole.log(inventory); // all items have qty 0","lang":"javascript","description":"Filter, sort, and update an array of objects using MongoDB-style operators with obop."},"warnings":[{"fix":"Use const obop = require('obop')(); or import obop from 'obop'.","message":"Calling 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure you intend to mutate or use a shallow copy before calling update: const copy = array.map(o => ({...o})); obop.update(copy, updateSpec);","message":"obop.update mutates the original array elements in place. It does not create a new array.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use {field: {$gt: 10, $lt: 20}} instead of nesting under a single operator.","message":"The $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.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Ensure query is a valid JavaScript object. For empty query, use {}.","message":"When using the curried form (array.filter(obop.where(query))), obop.where may throw if query is not a plain object.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'5kb':68 'anyon':77 'api':75 'array':8,52,84 'array.filter':56 'array.foreach':58 'array.sort':57 'backend':80 'browser':63 'build':64 'commonj':61 'depend':71 'differenti':66 'direct':50 'esm':60 'etc':34 'exist':33 'familiar':73 'filter':11,85 'frontend':82 'function':45 'gt':30 'gzip':69 'inc':41 'javascript':83 'lightweight':67 'like':27 'manipul':9 'map':86 'mit':23 'mongodb':3,26,74,87 'mongodb-lik':25 'mongodb-styl':2 'object':5 'obop':1 'oper':6,39 'order':12 'paramet':36 'pass':54 'project':18 'provid':24 'publish':21 'push':42 'queri':28 'selector':29 'set':40 'sort':13,35,88 'stabl':20 'standalon':44 'style':4 'support':59 'transform':15 'transit':78 'unpkg/cdn':65 'updat':14,38 'use':49 'v1.0.0':19 'view':17 'zero':70","created_at":"2026-06-05T17:00:06.233264+00:00","updated_at":"2026-06-05T17:00:06.233264+00:00","problems":[{"fix":"Use const obop = require('obop')(); or import obop from 'obop'.","cause":"Calling obop.where(...) without initializing the module (CommonJS) or using named import incorrectly.","error":"obop is not a function"},{"fix":"Use import obop from 'obop' then obop.where(...).","cause":"Using destructured import like import { where } from 'obop' but where is not a named export.","error":"Cannot read property 'where' of undefined"},{"fix":"Use obop = require('obop')(); or obop = obopInit(); from ESM default.","cause":"Using the module as a constructor or calling require('obop') without parentheses (returns the function, not its methods).","error":"TypeError: obop.where is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/kawanet/obop#readme","github":"https://github.com/kawanet/obop","docs":null,"changelog":null,"pypi":null,"npm":"obop","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}