/
filters.js
74 lines (64 loc) · 1.95 KB
/
filters.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
***** BEGIN LICENSE BLOCK *****
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* The Initial Developer of the Original Code is the Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2012
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Rob Miller (rmiller@mozilla.com)
*
***** END LICENSE BLOCK *****
*/
"use strict";
var severityMaxProvider = function(config) {
var severityMax = function(msg) {
if (msg['severity'] > config['severity']) {
return false;
};
return true;
};
return severityMax;
};
var typeBlacklistProvider = function(config) {
var typeBlacklist = function(msg) {
if (msg['type'] in config['types']) {
return false;
};
return true;
};
return typeBlacklist;
};
var typeWhitelistProvider = function(config) {
var typeWhitelist = function(msg) {
if (!(msg['type'] in config['types'])) {
return false;
};
return true;
};
return typeWhitelist;
};
var typeSeverityMaxProvider = function(config) {
var typeFilters = {};
for (typeName in config.types) {
if (config.types.hasOwnProperty(typeName)) {
var typeConfig = config.types[typeName];
typeFilters[typeName] = severityMaxProvider(typeConfig);
};
};
var typeSeveritMax = function(msg) {
var severityMax = typeFilters[msg['type']];
if (severityMax === undefined) {
return true;
};
return severityMax(msg);
};
return typeSeverityMax;
};
exports.severityMaxProvider = severityMaxProvider;
exports.typeBlacklistProvider = typeBlacklistProvider;
exports.typeWhitelistProvider = typeWhitelistProvider;
exports.typeSeverityMaxProvider = typeSeverityMaxProvider;