@url-sanitize/merged 2.0.4 → 2.0.5
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/dist/index.d.ts +24 -30
- package/dist/index.js +46 -48
- package/package.json +8 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,32 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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;
|
|
1
|
+
import { Sanitizer, SanitizerCatalog } from "@url-sanitize/core";
|
|
2
|
+
//#region src/index.d.ts
|
|
3
|
+
export interface MergeSourcesOptions {
|
|
4
|
+
dedupe?: boolean;
|
|
10
5
|
}
|
|
11
|
-
declare function mergeSources(catalogs?: SanitizerCatalog[], options?: MergeSourcesOptions): SanitizerCatalog;
|
|
12
|
-
declare const mergedCatalog: SanitizerCatalog;
|
|
13
|
-
declare const mergedMetadata: {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
6
|
+
export declare function mergeSources(catalogs?: SanitizerCatalog[], options?: MergeSourcesOptions): SanitizerCatalog;
|
|
7
|
+
export declare const mergedCatalog: SanitizerCatalog;
|
|
8
|
+
export declare const mergedMetadata: {
|
|
9
|
+
readonly version: string;
|
|
10
|
+
readonly generatedAt: string;
|
|
11
|
+
readonly sources: {
|
|
12
|
+
name: import("@url-sanitize/core").RuleSource;
|
|
13
|
+
version?: string;
|
|
14
|
+
hash?: string;
|
|
15
|
+
license?: string;
|
|
16
|
+
upstream?: string;
|
|
17
|
+
}[];
|
|
18
|
+
readonly sourceMetadata: {
|
|
19
|
+
readonly adguard: import("@url-sanitize/adguard").AdguardMetadata;
|
|
20
|
+
readonly brave: import("@url-sanitize/brave").BraveMetadata;
|
|
21
|
+
readonly clearurls: import("@url-sanitize/clearurls").ClearUrlsMetadata;
|
|
22
|
+
readonly firefox: import("@url-sanitize/firefox").FirefoxMetadata;
|
|
23
|
+
};
|
|
29
24
|
};
|
|
30
|
-
declare const sanitize: Sanitizer;
|
|
31
|
-
|
|
32
|
-
export { type MergeSourcesOptions, mergeSources, mergedCatalog, mergedMetadata, sanitize };
|
|
25
|
+
export declare const sanitize: Sanitizer;
|
|
26
|
+
//#endregion
|
package/dist/index.js
CHANGED
|
@@ -1,61 +1,59 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
1
|
import { adguardCatalog, adguardMetadata } from "@url-sanitize/adguard";
|
|
3
2
|
import { braveCatalog, braveMetadata } from "@url-sanitize/brave";
|
|
4
3
|
import { clearurlsCatalog, clearurlsMetadata } from "@url-sanitize/clearurls";
|
|
5
|
-
import {
|
|
6
|
-
compileSanitizer
|
|
7
|
-
} from "@url-sanitize/core";
|
|
4
|
+
import { compileSanitizer } from "@url-sanitize/core";
|
|
8
5
|
import { firefoxCatalog, firefoxMetadata } from "@url-sanitize/firefox";
|
|
9
|
-
|
|
6
|
+
//#region src/index.ts
|
|
7
|
+
const defaultCatalogs = [
|
|
8
|
+
clearurlsCatalog,
|
|
9
|
+
adguardCatalog,
|
|
10
|
+
braveCatalog,
|
|
11
|
+
firefoxCatalog
|
|
12
|
+
];
|
|
10
13
|
function mergeSources(catalogs = defaultCatalogs, options = {}) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
rules
|
|
27
|
-
};
|
|
14
|
+
const dedupe = options.dedupe ?? true;
|
|
15
|
+
const rules = [];
|
|
16
|
+
const seen = /* @__PURE__ */ new Set();
|
|
17
|
+
for (const catalog of catalogs) for (const rule of catalog.rules) {
|
|
18
|
+
const key = semanticRuleKey(rule);
|
|
19
|
+
if (dedupe && seen.has(key)) continue;
|
|
20
|
+
seen.add(key);
|
|
21
|
+
rules.push(cloneRule(rule));
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
version: `merged(${catalogs.map((catalog) => catalog.version).join(",")})`,
|
|
25
|
+
generatedAt: catalogs.map((catalog) => catalog.generatedAt).reduce((latest, generatedAt) => generatedAt > latest ? generatedAt : latest, ""),
|
|
26
|
+
sources: catalogs.flatMap((catalog) => catalog.sources.map((source) => ({ ...source }))),
|
|
27
|
+
rules
|
|
28
|
+
};
|
|
28
29
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
const mergedCatalog = mergeSources();
|
|
31
|
+
const mergedMetadata = {
|
|
32
|
+
version: mergedCatalog.version,
|
|
33
|
+
generatedAt: mergedCatalog.generatedAt,
|
|
34
|
+
sources: mergedCatalog.sources,
|
|
35
|
+
sourceMetadata: {
|
|
36
|
+
adguard: adguardMetadata,
|
|
37
|
+
brave: braveMetadata,
|
|
38
|
+
clearurls: clearurlsMetadata,
|
|
39
|
+
firefox: firefoxMetadata
|
|
40
|
+
}
|
|
40
41
|
};
|
|
41
|
-
|
|
42
|
+
const sanitize = compileSanitizer(mergedCatalog);
|
|
42
43
|
function semanticRuleKey(rule) {
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
const { provider: _provider, source: _source, ...semantic } = rule;
|
|
45
|
+
return JSON.stringify(sortValue(semantic));
|
|
45
46
|
}
|
|
46
47
|
function sortValue(value) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
Object.entries(value).sort(([a], [b]) => a.localeCompare(b)).map(([key, nested]) => [key, sortValue(nested)])
|
|
51
|
-
);
|
|
48
|
+
if (Array.isArray(value)) return value.map(sortValue);
|
|
49
|
+
if (typeof value !== "object" || value === null) return value;
|
|
50
|
+
return Object.fromEntries(Object.entries(value).sort(([a], [b]) => a.localeCompare(b)).map(([key, nested]) => [key, sortValue(nested)]));
|
|
52
51
|
}
|
|
53
52
|
function cloneRule(rule) {
|
|
54
|
-
|
|
53
|
+
return rule.exceptions ? {
|
|
54
|
+
...rule,
|
|
55
|
+
exceptions: [...rule.exceptions]
|
|
56
|
+
} : { ...rule };
|
|
55
57
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
mergedCatalog,
|
|
59
|
-
mergedMetadata,
|
|
60
|
-
sanitize
|
|
61
|
-
};
|
|
58
|
+
//#endregion
|
|
59
|
+
export { mergeSources, mergedCatalog, mergedMetadata, sanitize };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@url-sanitize/merged",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"description": "Merged ClearURLs, AdGuard, Brave, and Firefox catalog for @url-sanitize/core.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
"NOTICE"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@url-sanitize/
|
|
22
|
-
"@url-sanitize/
|
|
23
|
-
"@url-sanitize/brave": "2.0.
|
|
24
|
-
"@url-sanitize/
|
|
25
|
-
"@url-sanitize/core": "2.0.
|
|
21
|
+
"@url-sanitize/adguard": "2.0.5",
|
|
22
|
+
"@url-sanitize/clearurls": "2.0.5",
|
|
23
|
+
"@url-sanitize/brave": "2.0.5",
|
|
24
|
+
"@url-sanitize/firefox": "2.0.5",
|
|
25
|
+
"@url-sanitize/core": "2.0.5"
|
|
26
26
|
},
|
|
27
27
|
"keywords": [
|
|
28
28
|
"url",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
"sideEffects": false,
|
|
45
45
|
"scripts": {
|
|
46
|
-
"build": "
|
|
47
|
-
"dev": "
|
|
46
|
+
"build": "vp pack",
|
|
47
|
+
"dev": "vp pack --watch"
|
|
48
48
|
}
|
|
49
49
|
}
|