1.0.0 • Published 7 years ago
keyword-filter v1.0.0
an extreme lightweight keyword filter for node.js
install
npm install keyword-filter
api
- hasKeyword
- replaceKeywords
- getOccurances
example
const KeywordFilter = require('keyword-filter')
const filter = new KeywordFilter()
const keyArrays = ['go', 'js', 'lang', '我哈', '你呀']
filter.init(keyArrays)
const content = 'what is the best lang, go or js?\n' +
'你呀个妹,咿呀我哈噶'
filter.hasKeyword(content)
filter.replaceKeywords(content, '*')
filter.replaceKeywords(content, 'happy')
filter.getOccurances(content) // -> Returns [{1,'go'},{1,'js'},{1,'lang'}, {2, '我哈'}, {2, '你呀'}]