Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
ngx-mgmg-filter-pipe
Advanced tools
Filter arrays
Angular +17 pipeline for filtering arrays.
https://MagdyElsayyad.github.io/ngx-mgmg-filter-pipe/
{{ collection | filterBy: searchTerm }}
Param | Type | Details |
---|---|---|
collection | array | The collection to filter |
searchTerm | string or number or object or array or function | Predicate used to filter items from collection |
npm install ngx-mgmg-filter-pipe
Import FilterPipe
to your Standalone component or Module
@Component({
selector: 'app-root',
standalone: true,
imports: [
FilterPipe
],
templateUrl: './app.component.html',
styleUrl: './app.component.scss'
})
And use pipe in the template
import { Component } from '@angular/core';
@Component({
selector: 'example-app',
standalone: true,
imports: [FilterPip],
template: `
<div>
<input type="text" [(ngModel)]="userFilter.name" placeholder="name">
<ul>
<li *ngFor="let user of users | filterBy: userFilter">{{ user.name }}</li>
<!-- in case you want to show empty message -->
<li *ngIf="(users | filterBy: userFilter).length === 0">No matching elements</li>
</ul>
</div>
`
})
export class AppComponent {
users: any[] = [{ name: 'John' }, { name: 'Jane' }, { name: 'Mario' }];
userFilter: any = { name: '' };
}
Use $or
to filter by more then one values.
$or
expects an Array
.
In your component:
// your array
const languages = ['English', 'German', 'Russian', 'Italian', 'Ukrainian'];
// your $or filter
const filter = { $or: ['German', 'English'] };
In your template:
<div *ngFor="let language of languages | filterBy: filter">
{{ language }}
</div>
Result will be:
<div>English</div>
<div>German</div>
In your component:
// your array
const languages = [
{ language: 'English' },
{ language: 'German' },
{ language: 'Italian' }
];
// your $or filter
const filter = {
language: {
$or: ['Italian', 'English']
}
};
In your template:
<div *ngFor="let object of languages | filterBy: filter">
{{ object.language }}
</div>
Result:
<div>English</div>
<div>Italian</div>
const objects = [
{ name: 'John' },
{ firstName: 'John' }
]
const filter = { $or: [{ name: 'John' }, { firstName: 'John' }] }
In your template:
<div *ngFor="let object of objects | filterBy: filter">
{{ object | json }}
</div>
Result:
<div>{ name: 'John' }</div>
<div>{ firstName: 'John' }</div>
Inject FilterPipe
into your component and use it:
class AppComponent {
objects = [
{ name: 'John' },
{ name: 'Nick' },
{ name: 'Jane' }
];
constructor(private filter: FilterPipe) {
let result = this.filter.transform(this.objects, { name: 'J' });
console.log(result); // [{ name: 'John' }, { name: 'Jane' }]
}
}
FAQs
Angular +17 pipeline for filtering arrays
We found that ngx-mgmg-filter-pipe demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.