Installations
npm install obop
Developer Guide
Typescript
No
Module System
CommonJS, ESM
Node Version
22.12.0
NPM Version
10.9.0
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (95.99%)
Makefile (3.1%)
HTML (0.91%)
Developer
Download Statistics
Total Downloads
5,023,154
Last Day
8,992
Last Week
39,285
Last Month
165,776
Last Year
1,743,629
GitHub Statistics
12 Stars
87 Commits
1 Forks
4 Watching
7 Branches
1 Contributors
Bundle Size
8.35 kB
Minified
2.19 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.0.0
Package Id
obop@1.0.0
Unpacked Size
72.42 kB
Size
15.81 kB
File Count
14
NPM Version
10.9.0
Node Version
22.12.0
Publised On
15 Dec 2024
Total Downloads
Cumulative downloads
Total Downloads
5,023,154
Last day
0.3%
8,992
Compared to previous day
Last week
-14%
39,285
Compared to previous week
Last month
7.9%
165,776
Compared to previous month
Last year
44%
1,743,629
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
obop
MongoDB-style object operators makes array manipulation easy: where/order/update/view
SYNOPSIS
1import obop from "obop"; 2 3const array = [{a: 1}, {a: 2}, {a: 3}]; 4 5const out = obop.where(array, {a: 2}); // => [ { a: 2 } ] 6 7const out = array.filter(obop.where({a: 2})); // => [ { a: 2 } ]
Alternatively, you can generate the original obop
function via the default export.
1import obopInit from "obop"; 2 3const obop = obopInit(); 4 5const out = obop.where(array, {a: 2}); // => [ { a: 2 } ]
CommonJS
1const obop = require('obop')(); 2 3const out = obop.where(array, {a: 2}); // => [ { a: 2 } ]
Browser Environment
1<script src="obop.min.js"></script> 2<script> 3 const array = [{a: 1}, {a: 2}, {a: 3}]; 4 const out = obop.where(array, {a: 2}); // => [ { a: 2 } ] 5</script>
Download obop.min.js browser build of this module.
METHODS
See document for more detail.
Query Selectors
where() method supports the following query selectors:
1{ field: value } // equal to 2{ field: { $gt: value } } // greater than 3{ field: { $gte: value } } // greater than or equal to 4{ field: { $in: [value1, value2, ... ] } } // in 5{ field: { $lt: value } } // less than 6{ field: { $lte: value } } // less than or equal to 7{ field: { $ne: value } } // not equal to 8{ field: { $nin: [ value1, value2 ... ]} } // not in 9{ $or: [ { query1 }, { qury2 }, ... ] } // logical OR 10{ $and: [ { query1 }, { query2 }, ... ] } // logical AND 11{ field: { $not: { query } } } // not 12{ field: { $exists: boolean } } // exists 13{ field: { $size: value } } // array size
Example:
1const out1 = obop.where(array1, {genre: 'fruit', price: {$gt: 100, $gt: 200}}); 2const out2 = obop.where(array2, {'review.score': {$gte: 4.0}}); 3 4// OR 5const out1 = array1.filter(obop.where({genre: 'fruit', price: {$gt: 100, $gt: 200}})); 6const out2 = array2.filter(obop.where({'review.score': {$gte: 4.0}}));
Sort Parameters
order() method supports the following styles of sort parameters:
1{ field: 1 } // ascending 2{ field: -1 } // descending 3{ field1: 1, field2: -1, ... } // combination 4[ [ 'field1', 1 ], [ 'field2', -1 ], ... ] // array style
Example:
1obop.order(array1, {price: 1, stock: -1}); 2obop.order(array2, [['price', 1], ['stock', -1]]); // same as above 3 4// OR 5array1.sort(obop.order({price: 1, stock: -1})); 6array2.sort(obop.order([['price', 1], ['stock', -1]])); // same as above
Update Operators
update() method supports the following update operators:
1{ $set: { field: value } } // set value 2{ $unset: { field: '' } } // remove field 3{ $rename: { oldname: newname } } // rename field 4{ $inc: { field: amount } } // increment value 5{ $pull: { field: query } } // remove item from array 6{ $push: { field: value } } // add item to array
Example:
1obop.update(array1, {$inc: {stock: -1}, $set: {'review.score': 4}}); 2obop.update(array2, {$unset: {order: ''}}); 3 4// OR 5array1.forEach(obop.update({$inc: {stock: -1}, $set: {'review.score': 4}})); 6array2.forEach(obop.update({$unset: {order: ''}}));
Projection Parameters
view() method supports the following styles of projection parameters:
1{ field1: 1 } // output fields1 only 2{ field1: 1, field2: 1, ... } // output fields1, 2 and more 3{ field1: 0 } // output all fields except for fields1 4{ field1: 0, field2: 0, ... } // except fields1, 2 and more
Example:
1const out1 = obop.view(array1, {name: 1, price: 1, stock: 1}); // include fields 2const out2 = obop.view(array2, {_id: 0, secret: 0}); // exclude fields 3 4// OR 5const out1 = array1.map(obop.view({name: 1, price: 1, stock: 1})); // include fields 6const out2 = array2.map(obop.view({_id: 0, secret: 0})); // exclude fields
LINKS
- https://cdn.jsdelivr.net/npm/obop/build/obop.min.js
- https://github.com/kawanet/obop
- https://www.npmjs.com/package/obop
LICENCE
Copyright 2013-2024 @kawanet
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
8 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 6
Reason
Found 0/12 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/nodejs.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Info: Possibly incomplete results: error parsing shell code: < must be followed by a word: Makefile:0
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/nodejs.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/kawanet/obop/nodejs.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/nodejs.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/kawanet/obop/nodejs.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/nodejs.yml:19
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 21 are checked with a SAST tool
Score
4
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More