From c5dce96fbdbaffbaa5e84ff19774ef2e08be4af0 Mon Sep 17 00:00:00 2001 From: cagataycivici Date: Tue, 28 May 2019 15:56:58 +0300 Subject: [PATCH] Add filterutils --- src/components/utils/FilterUtils.js | 81 ++++++++++++++++++++++++++++ src/components/utils/ObjectUtils.js | 82 ----------------------------- 2 files changed, 81 insertions(+), 82 deletions(-) create mode 100644 src/components/utils/FilterUtils.js diff --git a/src/components/utils/FilterUtils.js b/src/components/utils/FilterUtils.js new file mode 100644 index 000000000..71eade50f --- /dev/null +++ b/src/components/utils/FilterUtils.js @@ -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; + } +} diff --git a/src/components/utils/ObjectUtils.js b/src/components/utils/ObjectUtils.js index c0e249102..880013c6a 100644 --- a/src/components/utils/ObjectUtils.js +++ b/src/components/utils/ObjectUtils.js @@ -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; - } - } } \ No newline at end of file