Installations
npm install object-array-filter
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
12.16.3
NPM Version
6.14.4
Score
62.9
Supply Chain
96.8
Quality
74.5
Maintenance
50
Vulnerability
99.6
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (100%)
Developer
zerico007
Download Statistics
Total Downloads
1,474
Last Day
1
Last Week
7
Last Month
16
Last Year
204
GitHub Statistics
1 Stars
8 Commits
1 Watching
1 Branches
1 Contributors
Bundle Size
947.00 B
Minified
487.00 B
Minified + Gzipped
Package Meta Information
Latest Version
1.0.4
Package Id
object-array-filter@1.0.4
Unpacked Size
17.86 kB
Size
4.61 kB
File Count
6
NPM Version
6.14.4
Node Version
12.16.3
Total Downloads
Cumulative downloads
Total Downloads
1,474
Last day
0%
1
Compared to previous day
Last week
-12.5%
7
Compared to previous week
Last month
23.1%
16
Compared to previous month
Last year
-62.2%
204
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
3
object-array-filter
Explanation
Filters an array of objects by compariing a field's value in each object to a search term. The following operators can be used: "eq" | "ne" | "lt" | "gt" | "lte" | "gte". Returns a promise of a filtered array. Field values must be strings, numbers or booleans.
Installation & Usage
Run npm install --save object-array-filter
1const find = require('object-array-filter'); 2 3/** 4 * @param search object 5 * @param array an array of object with the same properties 6 * @param key <optional> object key to perform comparison. 7 * @param comparison <optional> comparison operator to use. 8 * @returns {Promise<object[] | []>} Returns filtered array 9 */ 10 11 12 13const testArray = [ 14 { color: "black", size: 2, big: false }, 15 { color: "pink", size: 3, big: false }, 16 { color: "black", size: 3, big: false }, 17 { color: "pink", size: 14, big: true} 18]; 19 20const size = 3; 21const color = 'black'; 22const big = true; 23 24const testing = async () => { 25 try { 26 const filteredSize = await find.default({ size }, testArray); 27 const filteredColor = await find.default({ color }, testArray); 28 const filteredNotBig = await find.default({ big }, testArray); 29 console.log({ filteredSize, filteredColor, filteredBig }); 30 } catch (error) { 31 console.log(error); 32 } 33}; 34 35//Run function 36testing(); 37 38/* expected output: { 39 filteredSize: [ 40 { color: 'pink', size: 3, big: false }, 41 { color: 'black', size: 3, big: false } 42 ], 43 filteredColor: [ 44 { color: 'black', size: 2, big: false }, 45 { color: 'black', size: 3, big: false } 46 ], 47 filteredBig: [ { color: 'pink', size: 14, big: true } ] 48} */ 49 50/* 51NB: Variable name should match the name of the field in the object. 52If the variable name does not match the field name, the following syntax must be used 53 */ 54const color2 = 'pink' 55find.default({ color2 }, testArray, "color") 56 .then((filtered) => console.log(filtered)) 57 .catch((error) => console.log(error)); 58 59/* expected output: [ { color: 'pink', size: 3 }, { color: 'pink', size: 14 } ] */ 60 61//NB: The default operator is 'eq'. If you wish to use another operator, below are some examples. 62const testingOperators = async () => { 63 try { 64 const filteredLessThanOrEqual3 = await find.default({ size }, testArray, "size", "lte"); 65 const filteredGreaterThan3 = await find.default({ size }, testArray, "size", "gt"); 66 const filteredNotBlack = await find.default({ color }, testArray, "color", "ne"); 67 const filteredNotBig = await find.default({ big }, testArray, "big", "ne"); 68 console.log({ filteredLessThanOrEqual3, filteredGreaterThan3, filteredNotBlack, filteredNotBig }); 69 } catch (error) { 70 console.log(error); 71 } 72}; 73 74testingOperators(); 75 76/* expected output: { 77 filteredLessThanOrEqual3: [ 78 { color: 'black', size: 2, big: false }, 79 { color: 'pink', size: 3, big: false }, 80 { color: 'black', size: 3, big: false } 81 ], 82 filteredGreaterThan3: [ { color: 'pink', size: 14, big: true } ], 83 filteredNotBlack: [ 84 { color: 'pink', size: 3, big: false }, 85 { color: 'pink', size: 14, big: true } 86 ], 87 filteredNotBig: [ 88 { color: 'black', size: 2, big: false }, 89 { color: 'pink', size: 3, big: false }, 90 { color: 'black', size: 3, big: false } 91 ] 92} */ 93
TypeScript Usage
1import find from 'object-array-filter'; 2 3/** 4 * @param search object 5 * @param array an array of object with the same properties 6 * @param key <optional> object key to perform comparison. 7 * @param comparison <optional> comparison operator to use. 8 * @returns {Promise<object[] | []>} Returns filtered array 9 */ 10 11 12 13const testArray = [ 14 { color: "black", size: 2, big: false }, 15 { color: "pink", size: 3, big: false }, 16 { color: "black", size: 3, big: false }, 17 { color: "pink", size: 14, big: true} 18]; 19 20const size = 3; 21const color = 'black'; 22const big = true; 23 24const testing = async () => { 25 try { 26 const filteredSize = await find({ size }, testArray); 27 const filteredColor = await find({ color }, testArray); 28 const filteredNotBig = await find({ big }, testArray); 29 console.log({ filteredSize, filteredColor, filteredBig }); 30 } catch (error) { 31 console.log(error); 32 } 33}; 34 35//Run function 36testing(); 37 38/* expected output: { 39 filteredSize: [ 40 { color: 'pink', size: 3, big: false }, 41 { color: 'black', size: 3, big: false } 42 ], 43 filteredColor: [ 44 { color: 'black', size: 2, big: false }, 45 { color: 'black', size: 3, big: false } 46 ], 47 filteredBig: [ { color: 'pink', size: 14, big: true } ] 48} */ 49
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
7 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97
- Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/8 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
no effort to earn an OpenSSF best practices badge detected
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
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
1.7
/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 MoreOther packages similar to object-array-filter
os-filter-obj
Filter an array of objects to a specific OS
object.omit
Return a copy of an object excluding the given key, or array of keys. Also accepts an optional filter function as the last argument.
obop
MongoDB-style object operators makes array manipulation easy: where/order/update/view
filter-object-array
Filter an array of objects with an object