1 const SPECIALCHARS
= /([\\.?+*$^|()[\]{}])/g;
4 constructor(config
= { camo
: { enabled
: false } }) {
5 this.config
= config
.camo
;
6 if (this.config
.server
) {
7 this.config
.server
= this.config
.server
.replace(/\/+$/, '');
13 if (this.config
.encoding
14 && !~['url', 'hex'].indexOf(this.config
.encoding
)) {
15 throw new Error(`Value for key 'encoding' must be either 'url' or 'hex', not '${this.config.encoding}'`);
20 return this.config
.enabled
;
24 return this.config
.key
;
28 return this.config
.server
;
31 getWhitelistedDomains() {
32 return this.config
['whitelisted-domains'] || [];
35 getWhitelistedDomainsRegexp() {
36 const domains
= this.getWhitelistedDomains()
37 .map(d
=> '\\.' + d
.replace(SPECIALCHARS
, '\\$1') + '$');
38 if (domains
.length
=== 0) {
39 // If no whitelist, match nothing
40 return new RegExp('$^');
43 return new RegExp(domains
.join('|'), 'i');
47 return this.config
.encoding
|| 'url';
51 export { CamoConfig
};