Skip to content

Commit

Permalink
Add filterutils
Browse files Browse the repository at this point in the history
  • Loading branch information
cagataycivici committed May 28, 2019
1 parent 481a0fc commit c5dce96
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 82 deletions.
81 changes: 81 additions & 0 deletions src/components/utils/FilterUtils.js
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;
}
}
82 changes: 0 additions & 82 deletions src/components/utils/ObjectUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,86 +130,4 @@ export default class ObjectUtils {

return false;
}

static filterConstraints = {

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;
},

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;
},

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;
},

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();
},

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();
},

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;
}
}
}

0 comments on commit c5dce96

Please sign in to comment.