-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug fixes on regexes containing
:
and default acts
array; Add cli…
… for ease of use
- Loading branch information
Showing
4 changed files
with
48 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// `node cli.js <url[]> [<options>]` | ||
// `url` is the URL to purify. You can pass multiple URLs to purify them all. | ||
// `options` can contain: | ||
// - `--rules <enabled-rules>`, where `enabled-rules` is a comma-separated list of rules to enable. Default is all rules. Short-hand `-r`. | ||
|
||
const Purlfy = require("./purlfy"); | ||
const { parseArgs } = require("node:util"); | ||
|
||
const options = { | ||
rules: { | ||
type: "string", | ||
short: "r", | ||
default: "" | ||
} | ||
}; | ||
const args = process.argv.slice(2); | ||
const { | ||
values, | ||
positionals: urls, | ||
} = parseArgs({ args, options, allowPositionals: true }); | ||
const { rules: rulesStr } = values; | ||
const enabledRules = rulesStr.trim().length ? rulesStr.split(",").map((rule) => rule.trim()).filter(Boolean) : require("./rules/list.json"); | ||
console.log("Enabled rules:", enabledRules); | ||
console.log("---"); | ||
|
||
const purifier = new Purlfy({ | ||
fetchEnabled: true, | ||
lambdaEnabled: true, | ||
}); | ||
const rules = enabledRules.map((rule) => require(`./rules/${rule}.json`)); | ||
purifier.importRules(...rules); | ||
for (const url of urls) { | ||
purifier.purify(url).then((purified) => { | ||
console.log(url, "=>", purified.url); | ||
}); | ||
} |
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