Skip to content

Commit

Permalink
prepared 0.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
VadimDez committed Feb 16, 2017
1 parent 26e4db6 commit e2d7a5b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 0.1.6
* [[#24](https://github.com/VadimDez/ng2-filter-pipe/pull/24)] - Ability to pass in a function as a filter

## 0.1.5
* [[#15](https://github.com/VadimDez/ng2-filter-pipe/issues/15)] - Filter by object key which can be equals null

Expand Down
13 changes: 13 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 @@ -124,6 +124,19 @@ describe('Pipe: Ng2FilterPipe', () => {
expect(pipe.transform(objects, void 0)).toEqual(objects);
});


it('should take a function as a filter', () => {
const objects = [
{ num: 1, nested: { a: 1 } },
{ num: 1, nested: { a: 2 } },
{ num: 2, nested: { a: 2, b: 'waz' } },
{ num: 2, nested: { a: 2, b: 'was' } }
];

const fn = (object: any) => object.num < 2 || object.nested.b === 'was';
expect(pipe.transform(objects, fn)).toEqual([objects[0], objects[1], objects[3]]);
});

// it('should filter by using $or operator', () => {
// const objects = [
// {
Expand Down
4 changes: 4 additions & 0 deletions examples/ng-cli/src/app/shared/ng2-filter.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ export class Ng2FilterPipe {
return array.filter(this.filterByObject(filter));
}

if (type === 'function') {
return array.filter(filter);
}

return array.filter(this.filterDefault(filter));
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng2-filter-pipe",
"version": "0.1.5",
"version": "0.1.6",
"author": "Vadym Yatsyuk <[email protected]>",
"license": "MIT",
"angular-cli": {},
Expand Down

0 comments on commit e2d7a5b

Please sign in to comment.