fuse-angular/src/app/core/fuseUtils.ts

94 lines
2.0 KiB
TypeScript
Raw Normal View History

export class FuseUtils
{
public static filterArrayByString(mainArr, searchText)
{
2017-07-28 09:26:56 +00:00
if ( searchText === '' )
{
return mainArr;
}
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)
{
2017-08-17 07:31:04 +00:00
return value.toLowerCase().includes(searchText);
}
2017-07-28 14:40:11 +00:00
2017-08-18 11:50:19 +00:00
public static generateGUID()
2017-07-28 14:40:11 +00:00
{
function S4()
{
return (((1 + Math.random()) * 0x10000) || 0).toString(16).substring(1);
}
return (S4() + S4());
}
}