-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from oncletom/feature-11
rules as regexp
- Loading branch information
Showing
15 changed files
with
336 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
"use strict"; | ||
|
||
/*jshint node:true strict: true */ | ||
|
||
/* | ||
* Default list of exporters | ||
*/ | ||
var exporters = [ | ||
require(__dirname + '/standard-json.js'), | ||
require(__dirname + '/legacy-json.js') | ||
]; | ||
|
||
module.exports = exporters; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"use strict"; | ||
|
||
/*jshint node:true strict: true */ | ||
|
||
var Rule = require(__dirname + '/../rule.js'); | ||
|
||
function legacyJSONExport(xlds){ | ||
var data = []; | ||
|
||
xlds.forEach(function(xld){ | ||
data.push( new Rule(xld) ); | ||
}); | ||
|
||
return ['rules-legacy.json', data]; | ||
} | ||
|
||
|
||
module.exports = legacyJSONExport; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"use strict"; | ||
|
||
/*jshint node:true strict: true */ | ||
|
||
var Rule = require(__dirname + '/../rule.js'); | ||
|
||
function standardJSONExport(xlds){ | ||
var data = {}; | ||
|
||
xlds.forEach(function(xld){ | ||
var rule = new Rule(xld); | ||
|
||
if (!data[rule.firstLevel]){ | ||
data[rule.firstLevel] = []; | ||
} | ||
|
||
if (rule.wildcard){ | ||
data[rule.firstLevel].push('*' + (rule.secondLevel || '')); | ||
} | ||
|
||
if (rule.exception){ | ||
data[rule.firstLevel].push('!' + (rule.secondLevel || '')); | ||
} | ||
|
||
if (!rule.exception && !rule.wildcard && rule.secondLevel){ | ||
data[rule.firstLevel].push(rule.secondLevel); | ||
} | ||
}); | ||
|
||
// Compressing data | ||
for (var tld in data){ | ||
data[tld] = data[tld].join('|'); | ||
} | ||
|
||
return ['rules.json', data]; | ||
} | ||
|
||
|
||
module.exports = standardJSONExport; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
"use strict"; | ||
|
||
/*jshint node:true strict: true */ | ||
|
||
function PublicSuffixOrgParser(){ | ||
|
||
} | ||
|
||
/** | ||
* Parse a one-domain-per-line file | ||
* | ||
* @param body {String} | ||
* @return {Array} | ||
*/ | ||
PublicSuffixOrgParser.parse = function (body){ | ||
return (body+'') | ||
.split(/\n/m) | ||
.filter(PublicSuffixOrgParser.filterRow) | ||
.map(PublicSuffixOrgParser.domainBuilder); | ||
}; | ||
|
||
/** | ||
* Returns a rule based on string analysis | ||
* | ||
* @param rule {PublicSuffixRule} | ||
*/ | ||
PublicSuffixOrgParser.domainBuilder = function (row){ | ||
var rule = {}; | ||
row = row.trim(); | ||
|
||
//setting initial rule | ||
rule.source = row; | ||
|
||
//exception | ||
row = row.replace(/^!(.+)$/, function(m, tld){ | ||
rule.exception = true; | ||
|
||
return tld; | ||
}); | ||
|
||
//wildcard | ||
row = row.replace(/^(\*\.)(.+)$/, function(m, dummy, tld){ | ||
rule.wildcard = true; | ||
|
||
return tld; | ||
}); | ||
|
||
//splitting domains | ||
row.replace(/^((.+)\.)?([^\.]+)$/, function(m, dummy, secondLevel, firstLevel){ | ||
rule.firstLevel = firstLevel; | ||
|
||
if (secondLevel){ | ||
rule.secondLevel = secondLevel; | ||
} | ||
|
||
}); | ||
|
||
return rule; | ||
}; | ||
|
||
/** | ||
* Filters a commented or empty line | ||
* | ||
* @param row {String} | ||
* @return {String|null} | ||
*/ | ||
PublicSuffixOrgParser.filterRow = function (row) { | ||
return (/^\/\//).test(row) ? null : row; | ||
}; | ||
|
||
module.exports = PublicSuffixOrgParser; |
Oops, something went wrong.