Installations
npm install filter-anything
Score
89.4
Supply Chain
100
Quality
78.5
Maintenance
100
Vulnerability
100
License
Developer
Developer Guide
Module System
ESM
Min. Node Version
>=18
Typescript Support
No
Node Version
20.12.2
NPM Version
10.8.1
Statistics
35 Stars
93 Commits
1 Watching
5 Branches
1 Contributors
Updated on 17 Nov 2024
Languages
TypeScript (97.02%)
JavaScript (2.98%)
Total Downloads
Cumulative downloads
Total Downloads
1,299,363
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
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
2
Dev Dependencies
5
Filter anything ⚔️
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".
Motivation
I created this package because I needed:
- be able to filter out object props based on just what we need - aka "pick" props
- be able to filter out object props based on what we don't need - aka "omit" props
- supports for nested properties
- supports wildcards
*
for nested properties - the return type must be TypeScript supported! (see screenshots below)
Meet the family (more tiny utils with TS support)
- is-what 🙉
- is-where 🙈
- merge-anything 🥡
- check-anything 👁
- remove-anything ✂️
- getorset-anything 🐊
- map-anything 🗺
- filter-anything ⚔️
- copy-anything 🎭
- case-anything 🐫
- flatten-anything 🏏
- nestify-anything 🧅
Usage
Pick
With 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' }
Omit
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' }
Aliases
pick()
and omit()
can also be imported with the names fillable()
and guard()
. This pays homage to my history with Laravel. 😉
TypeScript
TypeScript users will love this, because, as you can see, the result has the correct type automatically!
Nested props
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.
Wildcards
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
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
5 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-64vr-g452-qvp3
- Warn: Project is vulnerable to: GHSA-9cwx-2883-4wfx
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:31: update your workflow using https://app.stepsecurity.io/secureworkflow/mesqueeb/filter-anything/test.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/mesqueeb/filter-anything/test.yml/main?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 1 out of 1 npmCommand dependencies pinned
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
- Warn: no topLevel permission defined: .github/workflows/test.yml:1
- Info: no jobLevel write permissions found
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
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 10 are checked with a SAST tool
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Score
3.2
/10
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