@url-sanitize/merged 2.0.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 +21 -0
- package/NOTICE +8 -0
- package/README.md +50 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +61 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
This package merges catalogs from:
|
|
2
|
+
|
|
3
|
+
- @url-sanitize/clearurls: ClearURLs-derived data, LGPL-3.0-only
|
|
4
|
+
- @url-sanitize/adguard: AdGuard URL Tracking Protection data, LGPL-3.0-only
|
|
5
|
+
- @url-sanitize/brave: Brave Debouncer data, MPL-2.0
|
|
6
|
+
- @url-sanitize/firefox: Firefox Query Stripping data, MPL-2.0
|
|
7
|
+
|
|
8
|
+
The merge adapter code is MIT. Bundled upstream data remains under its source license.
|
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# @url-sanitize/merged
|
|
2
|
+
|
|
3
|
+
Default merged catalog for [`@url-sanitize/core`](../core).
|
|
4
|
+
|
|
5
|
+
Combines sources in deterministic priority order:
|
|
6
|
+
|
|
7
|
+
```text
|
|
8
|
+
clearurls → adguard → brave → firefox
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Exact semantic duplicate rules are deduped; distinct scoped rules are preserved.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install @url-sanitize/core @url-sanitize/merged
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { sanitize, mergedCatalog, mergedMetadata } from '@url-sanitize/merged';
|
|
23
|
+
import { compileSanitizer } from '@url-sanitize/core';
|
|
24
|
+
|
|
25
|
+
sanitize('https://example.com/?utm_source=x');
|
|
26
|
+
|
|
27
|
+
const aggressive = compileSanitizer(mergedCatalog, {
|
|
28
|
+
stripReferralMarketing: true,
|
|
29
|
+
domainBlocking: true
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
console.log(mergedMetadata.sources);
|
|
33
|
+
console.log(aggressive('https://y2u.be/dQw4w9WgXcQ'));
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Custom merge
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { clearurlsCatalog } from '@url-sanitize/clearurls';
|
|
40
|
+
import { firefoxCatalog } from '@url-sanitize/firefox';
|
|
41
|
+
import { mergeSources } from '@url-sanitize/merged';
|
|
42
|
+
|
|
43
|
+
const catalog = mergeSources([clearurlsCatalog, firefoxCatalog]);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## License
|
|
47
|
+
|
|
48
|
+
Merge adapter code is MIT. Bundled upstream data keeps its source license:
|
|
49
|
+
ClearURLs and AdGuard are LGPL-3.0-only; Brave and Firefox data are MPL-2.0.
|
|
50
|
+
See [NOTICE](NOTICE).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as _url_sanitize_firefox from '@url-sanitize/firefox';
|
|
2
|
+
import * as _url_sanitize_clearurls from '@url-sanitize/clearurls';
|
|
3
|
+
import * as _url_sanitize_brave from '@url-sanitize/brave';
|
|
4
|
+
import * as _url_sanitize_adguard from '@url-sanitize/adguard';
|
|
5
|
+
import * as _url_sanitize_core from '@url-sanitize/core';
|
|
6
|
+
import { SanitizerCatalog, Sanitizer } from '@url-sanitize/core';
|
|
7
|
+
|
|
8
|
+
interface MergeSourcesOptions {
|
|
9
|
+
dedupe?: boolean;
|
|
10
|
+
}
|
|
11
|
+
declare function mergeSources(catalogs?: SanitizerCatalog[], options?: MergeSourcesOptions): SanitizerCatalog;
|
|
12
|
+
declare const mergedCatalog: SanitizerCatalog;
|
|
13
|
+
declare const mergedMetadata: {
|
|
14
|
+
readonly version: string;
|
|
15
|
+
readonly generatedAt: string;
|
|
16
|
+
readonly sources: {
|
|
17
|
+
name: _url_sanitize_core.RuleSource;
|
|
18
|
+
version?: string;
|
|
19
|
+
hash?: string;
|
|
20
|
+
license?: string;
|
|
21
|
+
upstream?: string;
|
|
22
|
+
}[];
|
|
23
|
+
readonly sourceMetadata: {
|
|
24
|
+
readonly adguard: _url_sanitize_adguard.AdguardMetadata;
|
|
25
|
+
readonly brave: _url_sanitize_brave.BraveMetadata;
|
|
26
|
+
readonly clearurls: _url_sanitize_clearurls.ClearUrlsMetadata;
|
|
27
|
+
readonly firefox: _url_sanitize_firefox.FirefoxMetadata;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
declare const sanitize: Sanitizer;
|
|
31
|
+
|
|
32
|
+
export { type MergeSourcesOptions, mergeSources, mergedCatalog, mergedMetadata, sanitize };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { adguardCatalog, adguardMetadata } from "@url-sanitize/adguard";
|
|
3
|
+
import { braveCatalog, braveMetadata } from "@url-sanitize/brave";
|
|
4
|
+
import { clearurlsCatalog, clearurlsMetadata } from "@url-sanitize/clearurls";
|
|
5
|
+
import {
|
|
6
|
+
compileSanitizer
|
|
7
|
+
} from "@url-sanitize/core";
|
|
8
|
+
import { firefoxCatalog, firefoxMetadata } from "@url-sanitize/firefox";
|
|
9
|
+
var defaultCatalogs = [clearurlsCatalog, adguardCatalog, braveCatalog, firefoxCatalog];
|
|
10
|
+
function mergeSources(catalogs = defaultCatalogs, options = {}) {
|
|
11
|
+
const dedupe = options.dedupe ?? true;
|
|
12
|
+
const rules = [];
|
|
13
|
+
const seen = /* @__PURE__ */ new Set();
|
|
14
|
+
for (const catalog of catalogs) {
|
|
15
|
+
for (const rule of catalog.rules) {
|
|
16
|
+
const key = semanticRuleKey(rule);
|
|
17
|
+
if (dedupe && seen.has(key)) continue;
|
|
18
|
+
seen.add(key);
|
|
19
|
+
rules.push(cloneRule(rule));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
version: `merged(${catalogs.map((catalog) => catalog.version).join(",")})`,
|
|
24
|
+
generatedAt: catalogs.map((catalog) => catalog.generatedAt).reduce((latest, generatedAt) => generatedAt > latest ? generatedAt : latest),
|
|
25
|
+
sources: catalogs.flatMap((catalog) => catalog.sources.map((source) => ({ ...source }))),
|
|
26
|
+
rules
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
var mergedCatalog = mergeSources();
|
|
30
|
+
var mergedMetadata = {
|
|
31
|
+
version: mergedCatalog.version,
|
|
32
|
+
generatedAt: mergedCatalog.generatedAt,
|
|
33
|
+
sources: mergedCatalog.sources,
|
|
34
|
+
sourceMetadata: {
|
|
35
|
+
adguard: adguardMetadata,
|
|
36
|
+
brave: braveMetadata,
|
|
37
|
+
clearurls: clearurlsMetadata,
|
|
38
|
+
firefox: firefoxMetadata
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var sanitize = compileSanitizer(mergedCatalog);
|
|
42
|
+
function semanticRuleKey(rule) {
|
|
43
|
+
const { provider: _provider, source: _source, ...semantic } = rule;
|
|
44
|
+
return JSON.stringify(sortValue(semantic));
|
|
45
|
+
}
|
|
46
|
+
function sortValue(value) {
|
|
47
|
+
if (Array.isArray(value)) return value.map(sortValue);
|
|
48
|
+
if (typeof value !== "object" || value === null) return value;
|
|
49
|
+
return Object.fromEntries(
|
|
50
|
+
Object.entries(value).sort(([a], [b]) => a.localeCompare(b)).map(([key, nested]) => [key, sortValue(nested)])
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
function cloneRule(rule) {
|
|
54
|
+
return rule.exceptions ? { ...rule, exceptions: [...rule.exceptions] } : { ...rule };
|
|
55
|
+
}
|
|
56
|
+
export {
|
|
57
|
+
mergeSources,
|
|
58
|
+
mergedCatalog,
|
|
59
|
+
mergedMetadata,
|
|
60
|
+
sanitize
|
|
61
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@url-sanitize/merged",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Merged ClearURLs, AdGuard, Brave, and Firefox catalog for @url-sanitize/core.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"NOTICE"
|
|
19
|
+
],
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@url-sanitize/brave": "2.0.0",
|
|
22
|
+
"@url-sanitize/core": "2.0.0",
|
|
23
|
+
"@url-sanitize/firefox": "2.0.0",
|
|
24
|
+
"@url-sanitize/clearurls": "2.0.0",
|
|
25
|
+
"@url-sanitize/adguard": "2.0.0"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"url",
|
|
29
|
+
"sanitize",
|
|
30
|
+
"tracking",
|
|
31
|
+
"clearurls",
|
|
32
|
+
"adguard",
|
|
33
|
+
"brave",
|
|
34
|
+
"firefox"
|
|
35
|
+
],
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "https://github.com/antonio-orionus/url-sanitize.git",
|
|
42
|
+
"directory": "packages/merged"
|
|
43
|
+
},
|
|
44
|
+
"sideEffects": false,
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
47
|
+
"dev": "tsup src/index.ts --format esm --dts --watch"
|
|
48
|
+
}
|
|
49
|
+
}
|