2017-07-28 08:29:29 +00:00
|
|
|
export class FuseUtils
|
|
|
|
{
|
|
|
|
|
|
|
|
public static filterArrayByString(mainArr, searchText)
|
|
|
|
{
|
2017-07-28 09:26:56 +00:00
|
|
|
if ( searchText === '' )
|
|
|
|
{
|
|
|
|
return mainArr;
|
|
|
|
}
|
|
|
|
|
2017-07-28 08:29:29 +00:00
|
|
|
searchText = searchText.toLowerCase();
|
|
|
|
|
|
|
|
return mainArr.filter(itemObj => {
|
|
|
|
return this.searchInObj(itemObj, searchText);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public static searchInObj(itemObj, searchText)
|
|
|
|
{
|
|
|
|
|
|
|
|
for ( const prop in itemObj )
|
|
|
|
{
|
|
|
|
if ( !itemObj.hasOwnProperty(prop) )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const value = itemObj[prop];
|
|
|
|
|
|
|
|
if ( typeof value === 'string' )
|
|
|
|
{
|
|
|
|
if ( this.searchInSting(value, searchText) )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else if ( Array.isArray(value) )
|
|
|
|
{
|
|
|
|
if ( this.searchInArray(value, searchText) )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( typeof value === 'object' )
|
|
|
|
{
|
|
|
|
if ( this.searchInObj(value, searchText) )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static searchInArray(arr, searchText)
|
|
|
|
{
|
|
|
|
for ( const value of arr )
|
|
|
|
{
|
|
|
|
if ( typeof value === 'string' )
|
|
|
|
{
|
|
|
|
if ( this.searchInSting(value, searchText) )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( typeof value === 'object' )
|
|
|
|
{
|
|
|
|
if ( this.searchInObj(value, searchText) )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static searchInSting(value, searchText)
|
|
|
|
{
|
|
|
|
if ( value.toLowerCase().includes(searchText) )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2017-07-28 14:40:11 +00:00
|
|
|
|
|
|
|
public static genearateGUID()
|
|
|
|
{
|
|
|
|
function S4()
|
|
|
|
{
|
|
|
|
return (((1 + Math.random()) * 0x10000) || 0).toString(16).substring(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (S4() + S4());
|
|
|
|
}
|
2017-07-28 08:29:29 +00:00
|
|
|
}
|