@url-sanitize/cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +27 -0
- package/README.md +25 -0
- package/dist/bin.js +54 -0
- package/package.json +36 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Antonio Orionus
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
Note: this MIT license applies to the @url-sanitize/core, @url-sanitize/cli,
|
|
24
|
+
@url-sanitize/fetch, and @url-sanitize/action packages. The
|
|
25
|
+
@url-sanitize/clearurls package ships a catalog derived from the ClearURLs
|
|
26
|
+
ruleset and is licensed under LGPL-3.0-only for that bundled data. See
|
|
27
|
+
packages/clearurls/LICENSE and docs/license-model.md for details.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# @url-sanitize/cli
|
|
2
|
+
|
|
3
|
+
Command-line URL sanitizer.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install -g @url-sanitize/cli
|
|
9
|
+
# or
|
|
10
|
+
npx @url-sanitize/cli "https://example.com/?utm_source=x"
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
url-sanitize "https://example.com/?utm_source=x"
|
|
17
|
+
# https://example.com/
|
|
18
|
+
|
|
19
|
+
url-sanitize --json "https://example.com/?utm_source=x"
|
|
20
|
+
# {"kind":"cleaned","original":"...","url":"...","strippedParams":["utm_source"],"matchedRules":[...]}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## License
|
|
24
|
+
|
|
25
|
+
MIT.
|
package/dist/bin.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/bin.ts
|
|
4
|
+
import { clearurlsCatalog } from "@url-sanitize/clearurls";
|
|
5
|
+
import { compileSanitizer } from "@url-sanitize/core";
|
|
6
|
+
var args = process.argv.slice(2);
|
|
7
|
+
if (args.length === 0 || args.includes("--help") || args.includes("-h")) {
|
|
8
|
+
printHelp();
|
|
9
|
+
process.exit(args.length === 0 ? 1 : 0);
|
|
10
|
+
}
|
|
11
|
+
var jsonMode = args.includes("--json");
|
|
12
|
+
var stripReferral = args.includes("--keep-referral") ? false : args.includes("--strip-referral");
|
|
13
|
+
var positional = args.filter((a) => !a.startsWith("--") && !a.startsWith("-"));
|
|
14
|
+
var sanitize = compileSanitizer(clearurlsCatalog, {
|
|
15
|
+
stripReferralMarketing: stripReferral
|
|
16
|
+
});
|
|
17
|
+
for (const url of positional) {
|
|
18
|
+
const result = sanitize(url);
|
|
19
|
+
if (jsonMode) {
|
|
20
|
+
process.stdout.write(`${JSON.stringify(result)}
|
|
21
|
+
`);
|
|
22
|
+
} else {
|
|
23
|
+
switch (result.kind) {
|
|
24
|
+
case "unchanged":
|
|
25
|
+
process.stdout.write(`${result.url}
|
|
26
|
+
`);
|
|
27
|
+
break;
|
|
28
|
+
case "cleaned":
|
|
29
|
+
case "redirected":
|
|
30
|
+
process.stdout.write(`${result.url}
|
|
31
|
+
`);
|
|
32
|
+
break;
|
|
33
|
+
case "blocked":
|
|
34
|
+
process.stderr.write(`blocked: ${result.original} (via ${result.via.provider})
|
|
35
|
+
`);
|
|
36
|
+
process.exitCode = 2;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function printHelp() {
|
|
42
|
+
process.stdout.write(
|
|
43
|
+
[
|
|
44
|
+
"url-sanitize <url> [<url>...]",
|
|
45
|
+
"",
|
|
46
|
+
"Options:",
|
|
47
|
+
" --json Emit JSON result objects (one per line)",
|
|
48
|
+
" --strip-referral Strip affiliate / referral marketing params (off by default)",
|
|
49
|
+
" --keep-referral Explicitly keep referral params (default)",
|
|
50
|
+
" -h, --help Show this help",
|
|
51
|
+
""
|
|
52
|
+
].join("\n")
|
|
53
|
+
);
|
|
54
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@url-sanitize/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Command-line URL sanitizer for cleaning, explaining, and validating tracking-heavy URLs.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"url-sanitize": "./dist/bin.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@url-sanitize/clearurls": "0.1.0",
|
|
15
|
+
"@url-sanitize/core": "0.1.0"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"cli",
|
|
19
|
+
"url",
|
|
20
|
+
"sanitize",
|
|
21
|
+
"tracking",
|
|
22
|
+
"clearurls"
|
|
23
|
+
],
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/antonio-orionus/url-sanitize.git",
|
|
30
|
+
"directory": "packages/cli"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsup src/bin.ts --format esm --clean",
|
|
34
|
+
"dev": "tsup src/bin.ts --format esm --watch"
|
|
35
|
+
}
|
|
36
|
+
}
|