Skip to content

Commit

Permalink
Merge branch 'master' into feature/#31
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
#	examples/ng-cli/src/app/shared/ng2-filter.pipe.spec.ts
#	package.json
#	src/ng2-filter.pipe.spec.ts
  • Loading branch information
VadimDez committed Jun 1, 2017
2 parents 2fa84dc + 6b3fd4c commit 5e61334
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 5 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
* [[#31](https://github.com/VadimDez/ng2-filter-pipe/issues/31)] - How to filter by two variables of the same array.
* [[#4](https://github.com/VadimDez/ng2-filter-pipe/issues/4)] - Add $or operator.

## 0.1.9
* [[#32](https://github.com/VadimDez/ng2-filter-pipe/issues/32)] - Filter fails when filter value is zero

## 0.1.8
* Removed warning in Angular 4+

## 0.1.7
* [[#28](https://github.com/VadimDez/ng2-filter-pipe/pull/28)] - Filter number by string
* [[#28](https://github.com/VadimDez/ng2-filter-pipe/issues/28)] - Filter number by string
* Removed post install script

## 0.1.6
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
Angular 2+ pipeline for filtering arrays.

##### [Demo Page](https://vadimdez.github.io/ng2-filter-pipe/)

<p align="center">
<img src="https://cloud.githubusercontent.com/assets/3748453/23809236/3276cf26-05cd-11e7-94f7-b4078104adbd.gif" width="300">
</p>

### Demo Page

[https://vadimdez.github.io/ng2-filter-pipe/](https://vadimdez.github.io/ng2-filter-pipe/)

## Install

```
Expand Down
25 changes: 25 additions & 0 deletions examples/ng-cli/src/app/shared/ng2-filter.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,31 @@ describe('Pipe: Ng2FilterPipe', () => {
expect(pipe.transform(objects, filter)).toEqual([objects[1]]);
});

it('should filter by two variables', () => {
const objects = [
{ name: 'Mario', code: 'Mario' },
{ name: 'Mario', code: 'Guy' },
{ name: 'Guy', code: 'Mario' },
];
const filter = { name: 'Mario', code: 'Mario' };

expect(pipe.transform(objects, filter)).toEqual([objects[0]]);

expect(pipe.transform(objects, { name: 'Guy', code: 'Guy' })).toEqual([]);
});

it('should filter by 0', () => {
const objects = [
{ age: 0 },
{ age: 1 },
{ age: 2 },
];
const filter = { age: 0 };

expect(pipe.transform(objects, filter)).toEqual([objects[0]]);
expect(pipe.transform([1, 2, 0], 0)).toEqual([0]);
});

it('should filter array by string', () => {
const objects = [
{ languages: ['English'] },
Expand Down
2 changes: 1 addition & 1 deletion examples/ng-cli/src/app/shared/ng2-filter.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class Ng2FilterPipe {
*/
private filterDefault(filter) {
return value => {
return !filter || filter == value;
return filter === undefined || filter == value;
}
}

Expand Down
25 changes: 25 additions & 0 deletions src/ng2-filter.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,31 @@ describe('Pipe: Ng2FilterPipe', () => {
expect(pipe.transform(objects, filter)).toEqual([objects[1]]);
});

it('should filter by two variables', () => {
const objects = [
{ name: 'Mario', code: 'Mario' },
{ name: 'Mario', code: 'Guy' },
{ name: 'Guy', code: 'Mario' },
];
const filter = { name: 'Mario', code: 'Mario' };

expect(pipe.transform(objects, filter)).toEqual([objects[0]]);

expect(pipe.transform(objects, { name: 'Guy', code: 'Guy' })).toEqual([]);
});

it('should filter by 0', () => {
const objects = [
{ age: 0 },
{ age: 1 },
{ age: 2 },
];
const filter = { age: 0 };

expect(pipe.transform(objects, filter)).toEqual([objects[0]]);
expect(pipe.transform([1, 2, 0], 0)).toEqual([0]);
});

it('should filter array by string', () => {
const objects = [
{ languages: ['English'] },
Expand Down
2 changes: 1 addition & 1 deletion src/ng2-filter.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class Ng2FilterPipe {
*/
private filterDefault(filter) {
return value => {
return !filter || filter == value;
return filter === undefined || filter == value;
}
}

Expand Down

0 comments on commit 5e61334

Please sign in to comment.