Gathering detailed insights and metrics for filter-anything
Gathering detailed insights and metrics for filter-anything
Gathering detailed insights and metrics for filter-anything
Gathering detailed insights and metrics for filter-anything
npm install filter-anything
89.4
Supply Chain
100
Quality
78.5
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
35 Stars
93 Commits
1 Watching
5 Branches
1 Contributors
Updated on 17 Nov 2024
TypeScript (97.02%)
JavaScript (2.98%)
Cumulative downloads
Total Downloads
Last day
-29.3%
1,942
Compared to previous day
Last week
0.9%
12,351
Compared to previous week
Last month
15.5%
52,198
Compared to previous month
Last year
38.4%
509,066
Compared to previous year
2
5
npm i filter-anything
An implementation that filters out object props like the TypeScript "pick" and "omit". In the Laravel world, this is also called "fillables" and "guard".
I created this package because I needed:
*
for nested propertiesWith pick
you pass an object and an array of keys of an object - the props which may stay.
1import { pick } from 'filter-anything' 2 3const squirtle = { id: '007', name: 'Squirtle', type: 'water' } 4 5const newObject = pick(squirtle, ['name', 'type']) 6// returns { name: 'Squirtle', type: 'water' }
With omit
you pass an object and an array of keys of an object - the props which should be removed.
1import { omit } from 'filter-anything' 2 3const squirtle = { id: '007', name: 'Squirtle', type: 'water' } 4 5const withoutId = omit(squirtle, ['id']) 6// returns { name: 'Squirtle', type: 'water' }
pick()
and omit()
can also be imported with the names fillable()
and guard()
. This pays homage to my history with Laravel. 😉
TypeScript users will love this, because, as you can see, the result has the correct type automatically!
In the example below we want to get rid of the nested property called "discard".
1const doc = { items: { keep: '📌', discard: '✂️' } } 2 3pick(doc, ['items.keep']) 4// returns {items: {keep: '📌'}} 5 6omit(doc, ['items.discard']) 7// returns {items: {keep: '📌'}}
Please note that TypeScript users will need to cast the result when using nested props.
Yes! You can also work with wildcards by using *
in the path.
1const doc = { 2 123: { keep: '📌', discard: '✂️' }, 3 456: { keep: '📌', discard: '✂️' }, 4} 5// use wildcard * 6omit(doc, ['*.discard']) 7// returns { 8// '123': {keep: '📌'}, 9// '456': {keep: '📌'} 10// }
Please note that TypeScript users will need to cast the result when using wildcards props.
Feel free to open issues for any requests, questions or bugs!
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
5 existing vulnerabilities detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/20 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2024-11-18
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