-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
481a0fc
commit c5dce96
Showing
2 changed files
with
81 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
export default class FilterUtils { | ||
|
||
static startsWith(value, filter) { | ||
if(filter === undefined || filter === null || filter.trim() === '') { | ||
return true; | ||
} | ||
|
||
if(value === undefined || value === null) { | ||
return false; | ||
} | ||
|
||
let filterValue = filter.toLowerCase(); | ||
return value.toString().toLowerCase().slice(0, filterValue.length) === filterValue; | ||
} | ||
|
||
static contains(value, filter) { | ||
if(filter === undefined || filter === null || (typeof filter === 'string' && filter.trim() === '')) { | ||
return true; | ||
} | ||
|
||
if(value === undefined || value === null) { | ||
return false; | ||
} | ||
|
||
return value.toString().toLowerCase().indexOf(filter.toLowerCase()) !== -1; | ||
} | ||
|
||
static endsWith(value, filter) { | ||
if(filter === undefined || filter === null || filter.trim() === '') { | ||
return true; | ||
} | ||
|
||
if(value === undefined || value === null) { | ||
return false; | ||
} | ||
|
||
let filterValue = filter.toString().toLowerCase(); | ||
return value.toString().toLowerCase().indexOf(filterValue, value.toString().length - filterValue.length) !== -1; | ||
} | ||
|
||
static equals(value, filter) { | ||
if(filter === undefined || filter === null || (typeof filter === 'string' && filter.trim() === '')) { | ||
return true; | ||
} | ||
|
||
if(value === undefined || value === null) { | ||
return false; | ||
} | ||
|
||
return value.toString().toLowerCase() === filter.toString().toLowerCase(); | ||
} | ||
|
||
static notEquals(value, filter) { | ||
if(filter === undefined || filter === null || (typeof filter === 'string' && filter.trim() === '')) { | ||
return false; | ||
} | ||
|
||
if(value === undefined || value === null) { | ||
return true; | ||
} | ||
|
||
return value.toString().toLowerCase() !== filter.toString().toLowerCase(); | ||
} | ||
|
||
static in(value, filter) { | ||
if(filter === undefined || filter === null || filter.length === 0) { | ||
return true; | ||
} | ||
|
||
if(value === undefined || value === null) { | ||
return false; | ||
} | ||
|
||
for(let i = 0; i < filter.length; i++) { | ||
if(filter[i] === value) | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters