1 | const blacklistConfig = require('../../config/usernames-blacklist.json')
|
2 | const blacklist = require('the-big-username-blacklist').list
|
3 |
|
4 | class BlacklistService {
|
5 | constructor () {
|
6 | this.reset()
|
7 | }
|
8 |
|
9 | addWord (word) {
|
10 | this.list.push(BlacklistService._prepareWord(word))
|
11 | }
|
12 |
|
13 | reset (config) {
|
14 | this.list = BlacklistService._initList(config)
|
15 | }
|
16 |
|
17 | validate (word) {
|
18 | return this.list.indexOf(BlacklistService._prepareWord(word)) === -1
|
19 | }
|
20 |
|
21 | static _initList (config = blacklistConfig) {
|
22 | return [
|
23 | ...(config.useTheBigUsernameBlacklist ? blacklist : []),
|
24 | ...config.customBlacklistedUsernames
|
25 | ]
|
26 | }
|
27 |
|
28 | static _prepareWord (word) {
|
29 | return word.trim().toLocaleLowerCase()
|
30 | }
|
31 | }
|
32 |
|
33 | module.exports = new BlacklistService()
|