node-red-nodes/analysis/swearfilter/74-swearfilter.js

18 lines
505 B
JavaScript
Raw Normal View History

module.exports = function(RED) {
"use strict";
function BadwordsNode(n) {
RED.nodes.createNode(this,n);
2019-03-14 15:04:06 +01:00
var badwordsRegExp = require('badwords/regexp');
var node = this;
2019-03-14 15:04:06 +01:00
node.on("input", function(msg) {
if (typeof msg.payload === "string") {
2019-03-14 15:04:06 +01:00
badwordsRegExp.lastIndex = 0
if ( !badwordsRegExp.test(msg.payload) ) { node.send(msg); }
}
});
}
RED.nodes.registerType("badwords",BadwordsNode);
}