web-mech / badwords

A javascript filter for badwords
MIT License
618 stars 325 forks source link

TypeError: word.replace is not a function #49

Open CoreyCole opened 5 years ago

CoreyCole commented 5 years ago

Found this error message that no one else has raised an issue about:

TypeError: word.replace is not a function
  at list.filter (.../node_modules/bad-words/lib/badwords.js:33:47)',
  at Array.filter (<anonymous>)',
  at Filter.isProfane (.../node_modules/bad-words/lib/badwords.js:32:8)'

Ended up being because I was using an old sytax that I think used to be working, but isn't any more:

filter.addWords(['some', 'bad', 'word']);

I needed to change it to this to work.

filter.addWords('some', 'bad', 'word');
// one could also use the spread operator
filter.addWords(...['some', 'bad', 'word']);

Just thought I'd docuement it for anyone else upgrading the npm module and hitting this error. Going to leave this issue open in case the maintainers want to provide an error when you provide an array instead of string args.

web-mech commented 5 years ago

Thanks Corey. Right, this was part of the breaking changes that led to a major version upgrade. Noted here: https://github.com/web-mech/badwords/commit/656b87c47033a795dd394d18ee875aa91b1f7a1c I do think we can add a type error for that.