@url-sanitize/merged 2.0.3 → 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 CHANGED
@@ -1,32 +1,26 @@
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;
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
- 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
- };
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
- var defaultCatalogs = [clearurlsCatalog, adguardCatalog, braveCatalog, firefoxCatalog];
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
- 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
- };
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
- 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
- }
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
- var sanitize = compileSanitizer(mergedCatalog);
42
+ const sanitize = compileSanitizer(mergedCatalog);
42
43
  function semanticRuleKey(rule) {
43
- const { provider: _provider, source: _source, ...semantic } = rule;
44
- return JSON.stringify(sortValue(semantic));
44
+ const { provider: _provider, source: _source, ...semantic } = rule;
45
+ return JSON.stringify(sortValue(semantic));
45
46
  }
46
47
  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
- );
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
- return rule.exceptions ? { ...rule, exceptions: [...rule.exceptions] } : { ...rule };
53
+ return rule.exceptions ? {
54
+ ...rule,
55
+ exceptions: [...rule.exceptions]
56
+ } : { ...rule };
55
57
  }
56
- export {
57
- mergeSources,
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",
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/adguard": "2.0.3",
22
- "@url-sanitize/brave": "2.0.3",
23
- "@url-sanitize/clearurls": "2.0.3",
24
- "@url-sanitize/firefox": "2.0.3",
25
- "@url-sanitize/core": "2.0.3"
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": "tsup src/index.ts --format esm --dts --clean",
47
- "dev": "tsup src/index.ts --format esm --dts --watch"
46
+ "build": "vp pack",
47
+ "dev": "vp pack --watch"
48
48
  }
49
49
  }