Created
November 11, 2017 11:35
-
-
Save nathandaly/e27bef6707938fd185362afa38999c35 to your computer and use it in GitHub Desktop.
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
import { Component, NgModule, OnInit } from '@angular/core'; | |
import { Pipe, PipeTransform } from '@angular/core'; | |
import { BrowserModule } from '@angular/platform-browser'; | |
import _ from 'lodash'; | |
@Pipe({name: 'Search'}) | |
export class SearchService implements PipeTransform { | |
transform(obj: any, term) { | |
if (obj != null && term) { | |
return obj.filter(el => { | |
let testString = JSON.stringify(el); | |
Object.keys(el).forEach(k => { | |
testString = testString.replace(k, ''); | |
}); | |
const terms = term.replace(/[\s]+/gm, '').replace(/^[\s]|[\s]$/gm, '').split(' '); | |
let containCount = 0; | |
terms.forEach(item => { | |
if (testString.toLowerCase().indexOf(item.toLowerCase()) > -1) { | |
++containCount; | |
} | |
}); | |
return (containCount === terms.length); | |
}); | |
} | |
return obj; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment