@adguard/agtree 2.2.0 → 3.0.0-alpha.2
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/README.md +1 -1
- package/dist/ast-utils/clone.js +61 -0
- package/dist/ast-utils/modifiers.js +53 -0
- package/dist/ast-utils/network-rules.js +41 -0
- package/dist/ast-utils/scriptlets.js +87 -0
- package/dist/common/abp-snippet-injection-body-common.js +23 -0
- package/dist/common/agent-common.js +56 -0
- package/dist/common/ubo-selector-common.js +17 -0
- package/dist/compatibility-tables/base.js +262 -0
- package/dist/compatibility-tables/compatibility-table-data.js +11 -0
- package/dist/compatibility-tables/modifiers.js +55 -0
- package/dist/compatibility-tables/platforms.js +76 -0
- package/dist/compatibility-tables/redirects.js +100 -0
- package/dist/compatibility-tables/schemas/base.js +111 -0
- package/dist/compatibility-tables/schemas/modifier.js +129 -0
- package/dist/compatibility-tables/schemas/platform.js +69 -0
- package/dist/compatibility-tables/schemas/redirect.js +29 -0
- package/dist/compatibility-tables/schemas/resource-type.js +36 -0
- package/dist/compatibility-tables/schemas/scriptlet.js +79 -0
- package/dist/compatibility-tables/scriptlets.js +28 -0
- package/dist/compatibility-tables/utils/platform-helpers.js +105 -0
- package/dist/compatibility-tables/utils/resource-type-helpers.js +61 -0
- package/dist/compatibility-tables/utils/zod-camelcase.js +25 -0
- package/dist/converter/base-interfaces/base-converter.js +59 -0
- package/dist/converter/base-interfaces/conversion-result.js +38 -0
- package/dist/converter/base-interfaces/rule-converter-base.js +60 -0
- package/dist/converter/comment/index.js +54 -0
- package/dist/converter/cosmetic/css.js +69 -0
- package/dist/converter/cosmetic/element-hiding.js +62 -0
- package/dist/converter/cosmetic/header-removal.js +123 -0
- package/dist/converter/cosmetic/html.js +379 -0
- package/dist/converter/cosmetic/index.js +118 -0
- package/dist/converter/cosmetic/rule-modifiers/adg.js +79 -0
- package/dist/converter/cosmetic/scriptlet.js +354 -0
- package/dist/converter/css/index.js +188 -0
- package/dist/converter/data/css.js +126 -0
- package/dist/converter/filter-list.js +88 -0
- package/dist/converter/index.js +8 -0
- package/dist/converter/misc/network-rule-modifier.js +311 -0
- package/dist/converter/network/index.js +99 -0
- package/dist/converter/raw-filter-list.js +56 -0
- package/dist/converter/rule.js +81 -0
- package/dist/deserializer/base-deserializer.js +29 -0
- package/dist/deserializer/comment/agent-comment-deserializer.js +79 -0
- package/dist/deserializer/comment/agent-deserializer.js +65 -0
- package/dist/deserializer/comment/comment-rule-deserializer.js +54 -0
- package/dist/deserializer/comment/config-comment-deserializer.js +111 -0
- package/dist/deserializer/comment/hint-comment-deserializer.js +72 -0
- package/dist/deserializer/comment/hint-deserializer.js +85 -0
- package/dist/deserializer/comment/metadata-comment-deserializer.js +69 -0
- package/dist/deserializer/comment/pre-processor-comment-deserializer.js +112 -0
- package/dist/deserializer/comment/simple-comment-deserializer.js +65 -0
- package/dist/deserializer/cosmetic/cosmetic-rule-deserializer.js +131 -0
- package/dist/deserializer/cosmetic/css-injection-body-deserializer.js +56 -0
- package/dist/deserializer/cosmetic/element-hiding-body-deserializer.js +48 -0
- package/dist/deserializer/cosmetic/scriptlet-body/abp-snippet-injection-body-deserializer.js +39 -0
- package/dist/deserializer/cosmetic/scriptlet-body/adg-scriptlet-injection-body-deserializer.js +40 -0
- package/dist/deserializer/cosmetic/scriptlet-body/scriptlet-body-deserializer.js +54 -0
- package/dist/deserializer/cosmetic/scriptlet-body/ubo-scriptlet-injection-body-deserializer.js +38 -0
- package/dist/deserializer/empty-rule-deserializer.js +48 -0
- package/dist/deserializer/filterlist-deserializer.js +85 -0
- package/dist/deserializer/index.js +8 -0
- package/dist/deserializer/invalid-rule-deserializer.js +50 -0
- package/dist/deserializer/invalid-rule-error-node-deserializer.js +50 -0
- package/dist/deserializer/misc/domain-list-deserializer.js +64 -0
- package/dist/deserializer/misc/list-item-deserializer.js +69 -0
- package/dist/deserializer/misc/list-items-deserializer.js +30 -0
- package/dist/deserializer/misc/logical-expression-deserializer.js +196 -0
- package/dist/deserializer/misc/modifier-deserializer.js +87 -0
- package/dist/deserializer/misc/modifier-list-deserializer.js +61 -0
- package/dist/deserializer/misc/parameter-list-deserializer.js +64 -0
- package/dist/deserializer/misc/value-deserializer.js +50 -0
- package/dist/deserializer/network/host-rule-deserializer.js +67 -0
- package/dist/deserializer/network/hostname-list-deserializer.js +56 -0
- package/dist/deserializer/network/network-rule-deserializer.js +65 -0
- package/dist/deserializer/rule-deserializer.js +65 -0
- package/dist/deserializer/syntax-deserialization-map.js +21 -0
- package/dist/errors/adblock-syntax-error.js +39 -0
- package/dist/errors/binary-schema-mismatch-error.js +37 -0
- package/dist/errors/not-implemented-error.js +31 -0
- package/dist/errors/rule-conversion-error.js +26 -0
- package/dist/generator/base-generator.js +27 -0
- package/dist/generator/comment/agent-comment-generator.js +31 -0
- package/dist/generator/comment/agent-generator.js +36 -0
- package/dist/generator/comment/comment-rule-generator.js +47 -0
- package/dist/generator/comment/config-comment-generator.js +45 -0
- package/dist/generator/comment/hint-comment-generator.js +28 -0
- package/dist/generator/comment/hint-generator.js +33 -0
- package/dist/generator/comment/metadata-comment-generator.js +33 -0
- package/dist/generator/comment/pre-processor-comment-generator.js +48 -0
- package/dist/generator/comment/simple-comment-generator.js +29 -0
- package/dist/generator/cosmetic/body/abp-snippet-injection-body-generator.js +38 -0
- package/dist/generator/cosmetic/body/adg-scriptlet-injection-body-generator.js +43 -0
- package/dist/generator/cosmetic/body/ubo-scriptlet-injection-body-generator.js +45 -0
- package/dist/generator/cosmetic/cosmetic-rule-body-generator.js +94 -0
- package/dist/generator/cosmetic/cosmetic-rule-generator.js +54 -0
- package/dist/generator/cosmetic/cosmetic-rule-pattern-generator.js +42 -0
- package/dist/generator/css/adg-css-injection-generator.js +42 -0
- package/dist/generator/filterlist-generator.js +67 -0
- package/dist/generator/index.js +9 -0
- package/dist/generator/misc/domain-list-generator.js +26 -0
- package/dist/generator/misc/list-items-generator.js +39 -0
- package/dist/generator/misc/logical-expression-generator.js +48 -0
- package/dist/generator/misc/modifier-generator.js +34 -0
- package/dist/generator/misc/modifier-list-generator.js +29 -0
- package/dist/generator/misc/parameter-list-generator.js +41 -0
- package/dist/generator/misc/value-generator.js +24 -0
- package/dist/generator/network/host-rule-generator.js +39 -0
- package/dist/generator/network/network-rule-generator.js +38 -0
- package/dist/generator/rule-generator.js +65 -0
- package/dist/index.js +70 -0
- package/dist/marshalling-utils/comment/agent-comment-common.js +21 -0
- package/dist/marshalling-utils/comment/agent-common.js +40 -0
- package/dist/marshalling-utils/comment/config-comment-common.js +54 -0
- package/dist/marshalling-utils/comment/hint-comment-common.js +22 -0
- package/dist/marshalling-utils/comment/hint-common.js +56 -0
- package/dist/marshalling-utils/comment/metadata-comment-common.js +41 -0
- package/dist/marshalling-utils/comment/pre-processor-comment-common.js +59 -0
- package/dist/marshalling-utils/comment/simple-comment-common.js +22 -0
- package/dist/marshalling-utils/cosmetic/body/abp-snippet-injection-body-common.js +61 -0
- package/dist/marshalling-utils/cosmetic/body/adg-scriptlet-injection-body-common.js +66 -0
- package/dist/marshalling-utils/cosmetic/body/css-injection-body-common.js +24 -0
- package/dist/marshalling-utils/cosmetic/body/element-hiding-body-common.js +21 -0
- package/dist/marshalling-utils/cosmetic/body/ubo-scriptlet-injection-body-common.js +114 -0
- package/dist/marshalling-utils/cosmetic/cosmetic-rule-common.js +48 -0
- package/dist/marshalling-utils/empty-rule-common.js +20 -0
- package/dist/marshalling-utils/filter-list-common.js +21 -0
- package/dist/marshalling-utils/invalid-rule-common.js +21 -0
- package/dist/marshalling-utils/invalid-rule-error-node-common.js +22 -0
- package/dist/marshalling-utils/misc/binary-type-common.js +66 -0
- package/dist/marshalling-utils/misc/domain-list-common.js +36 -0
- package/dist/marshalling-utils/misc/host-rule-common.js +25 -0
- package/dist/marshalling-utils/misc/hostname-list-common.js +21 -0
- package/dist/marshalling-utils/misc/list-item-common.js +22 -0
- package/dist/marshalling-utils/misc/logical-expression-common.js +83 -0
- package/dist/marshalling-utils/misc/modifier-common.js +231 -0
- package/dist/marshalling-utils/misc/modifier-list-common.js +21 -0
- package/dist/marshalling-utils/misc/parameter-list-common.js +21 -0
- package/dist/marshalling-utils/misc/value-common.js +22 -0
- package/dist/marshalling-utils/network/network-rule-common.js +25 -0
- package/dist/marshalling-utils/syntax-serialization-map.js +30 -0
- package/dist/nodes/index.js +168 -0
- package/dist/package.json.js +9 -0
- package/dist/parser/base-parser.js +30 -0
- package/dist/parser/comment/agent-comment-parser.js +119 -0
- package/dist/parser/comment/agent-parser.js +110 -0
- package/dist/parser/comment/comment-parser.js +108 -0
- package/dist/parser/comment/config-comment-parser.js +137 -0
- package/dist/parser/comment/hint-comment-parser.js +117 -0
- package/dist/parser/comment/hint-parser.js +129 -0
- package/dist/parser/comment/metadata-comment-parser.js +129 -0
- package/dist/parser/comment/preprocessor-parser.js +199 -0
- package/dist/parser/comment/simple-comment-parser.js +106 -0
- package/dist/parser/cosmetic/body/abp-snippet-injection-body-parser.js +79 -0
- package/dist/parser/cosmetic/body/adg-scriptlet-injection-body-parser.js +149 -0
- package/dist/parser/cosmetic/body/ubo-scriptlet-injection-body-parser.js +110 -0
- package/dist/parser/cosmetic/cosmetic-rule-parser.js +453 -0
- package/dist/parser/css/adg-css-injection-parser.js +208 -0
- package/dist/parser/css/balancing.js +94 -0
- package/dist/parser/css/constants.js +18 -0
- package/dist/parser/css/css-token-stream.js +343 -0
- package/dist/parser/css/ubo-selector-parser.js +369 -0
- package/dist/parser/filterlist-parser.js +102 -0
- package/dist/parser/index.js +12 -0
- package/dist/parser/misc/app-list-parser.js +45 -0
- package/dist/parser/misc/domain-list-parser.js +52 -0
- package/dist/parser/misc/list-items-parser.js +116 -0
- package/dist/parser/misc/logical-expression-parser.js +279 -0
- package/dist/parser/misc/method-list-parser.js +46 -0
- package/dist/parser/misc/modifier-list.js +70 -0
- package/dist/parser/misc/modifier-parser.js +89 -0
- package/dist/parser/misc/parameter-list-parser.js +75 -0
- package/dist/parser/misc/stealth-option-list-parser.js +46 -0
- package/dist/parser/misc/ubo-parameter-list-parser.js +149 -0
- package/dist/parser/misc/value-parser.js +37 -0
- package/dist/parser/network/host-rule-parser.js +130 -0
- package/dist/parser/network/network-rule-parser.js +117 -0
- package/dist/parser/options.js +23 -0
- package/dist/parser/rule-parser.js +192 -0
- package/dist/serializer/base-serializer.js +29 -0
- package/dist/serializer/comment/agent-comment-serializer.js +74 -0
- package/dist/serializer/comment/agent-serializer.js +59 -0
- package/dist/serializer/comment/comment-rule-serializer.js +105 -0
- package/dist/serializer/comment/config-comment-serializer.js +82 -0
- package/dist/serializer/comment/hint-comment-serializer.js +65 -0
- package/dist/serializer/comment/hint-serializer.js +54 -0
- package/dist/serializer/comment/metadata-comment-serializer.js +73 -0
- package/dist/serializer/comment/pre-processor-comment-serializer.js +71 -0
- package/dist/serializer/comment/simple-comment-serializer.js +52 -0
- package/dist/serializer/cosmetic/body/abp-snippet-injection-body-serializer.js +36 -0
- package/dist/serializer/cosmetic/body/adg-scriptlet-injection-body-serializer.js +36 -0
- package/dist/serializer/cosmetic/body/scriptlet-body-serializer.js +50 -0
- package/dist/serializer/cosmetic/body/ubo-scriptlet-injection-body-serializer.js +36 -0
- package/dist/serializer/cosmetic/cosmetic-rule-serializer.js +120 -0
- package/dist/serializer/cosmetic/css-injection-body-serializer.js +51 -0
- package/dist/serializer/cosmetic/element-hiding-body-serializer.js +40 -0
- package/dist/serializer/empty-rule-serializer.js +37 -0
- package/dist/serializer/filterlist-serializer.js +45 -0
- package/dist/serializer/index.js +7 -0
- package/dist/serializer/invalid-rule-error-node-serializer.js +41 -0
- package/dist/serializer/invalid-rule-serializer.js +40 -0
- package/dist/serializer/misc/domain-list-serializer.js +64 -0
- package/dist/serializer/misc/list-item-serializer.js +58 -0
- package/dist/serializer/misc/list-items-serializer.js +29 -0
- package/dist/serializer/misc/logical-expression-serializer.js +136 -0
- package/dist/serializer/misc/modifier-list-serializer.js +58 -0
- package/dist/serializer/misc/modifier-serializer.js +49 -0
- package/dist/serializer/misc/parameter-list-serializer.js +52 -0
- package/dist/serializer/misc/value-serializer.js +50 -0
- package/dist/serializer/network/host-rule-serializer.js +70 -0
- package/dist/serializer/network/hostname-list-serializer.js +53 -0
- package/dist/serializer/network/network-rule-serializer.js +54 -0
- package/dist/serializer/rule-serializer.js +61 -0
- package/dist/types/ast-utils/clone.d.ts +26 -0
- package/dist/types/ast-utils/filter-list.d.ts +11 -0
- package/dist/types/ast-utils/modifiers.d.ts +20 -0
- package/dist/types/ast-utils/network-rules.d.ts +15 -0
- package/dist/types/ast-utils/scriptlets.d.ts +52 -0
- package/dist/types/common/abp-snippet-injection-body-common.d.ts +15 -0
- package/dist/types/common/agent-common.d.ts +10 -0
- package/dist/types/common/ubo-selector-common.d.ts +10 -0
- package/dist/types/compatibility-tables/base.d.ts +157 -0
- package/dist/types/compatibility-tables/compatibility-table-data.d.ts +68 -0
- package/dist/types/compatibility-tables/index.d.ts +13 -0
- package/dist/types/compatibility-tables/modifiers.d.ts +22 -0
- package/dist/types/compatibility-tables/platforms.d.ts +49 -0
- package/dist/types/compatibility-tables/redirects.d.ts +33 -0
- package/dist/types/compatibility-tables/schemas/base.d.ts +124 -0
- package/dist/types/compatibility-tables/schemas/index.d.ts +8 -0
- package/dist/types/compatibility-tables/schemas/modifier.d.ts +36 -0
- package/dist/types/compatibility-tables/schemas/platform.d.ts +16 -0
- package/dist/types/compatibility-tables/schemas/redirect.d.ts +25 -0
- package/dist/types/compatibility-tables/schemas/resource-type.d.ts +41 -0
- package/dist/types/compatibility-tables/schemas/scriptlet.d.ts +31 -0
- package/dist/types/compatibility-tables/scriptlets.d.ts +15 -0
- package/dist/types/compatibility-tables/types.d.ts +34 -0
- package/dist/types/compatibility-tables/utils/platform-helpers.d.ts +44 -0
- package/dist/types/compatibility-tables/utils/resource-type-helpers.d.ts +20 -0
- package/dist/types/compatibility-tables/utils/zod-camelcase.d.ts +15 -0
- package/dist/types/converter/base-interfaces/base-converter.d.ts +42 -0
- package/dist/types/converter/base-interfaces/conversion-result.d.ts +43 -0
- package/dist/types/converter/base-interfaces/rule-converter-base.d.ts +44 -0
- package/dist/types/converter/comment/index.d.ts +23 -0
- package/dist/types/converter/cosmetic/css.d.ts +23 -0
- package/dist/types/converter/cosmetic/element-hiding.d.ts +23 -0
- package/dist/types/converter/cosmetic/header-removal.d.ts +37 -0
- package/dist/types/converter/cosmetic/html.d.ts +54 -0
- package/dist/types/converter/cosmetic/index.d.ts +33 -0
- package/dist/types/converter/cosmetic/rule-modifiers/adg.d.ts +21 -0
- package/dist/types/converter/cosmetic/scriptlet.d.ts +33 -0
- package/dist/types/converter/css/index.d.ts +40 -0
- package/dist/types/converter/data/css.d.ts +48 -0
- package/dist/types/converter/filter-list.d.ts +31 -0
- package/dist/types/converter/index.d.ts +5 -0
- package/dist/types/converter/misc/network-rule-modifier.d.ts +35 -0
- package/dist/types/converter/network/index.d.ts +33 -0
- package/dist/types/converter/raw-filter-list.d.ts +31 -0
- package/dist/types/converter/raw-rule.d.ts +28 -0
- package/dist/types/converter/rule.d.ts +37 -0
- package/dist/types/deserializer/base-deserializer.d.ts +15 -0
- package/dist/types/deserializer/comment/agent-comment-deserializer.d.ts +34 -0
- package/dist/types/deserializer/comment/agent-deserializer.d.ts +25 -0
- package/dist/types/deserializer/comment/comment-rule-deserializer.d.ts +16 -0
- package/dist/types/deserializer/comment/config-comment-deserializer.d.ts +27 -0
- package/dist/types/deserializer/comment/hint-comment-deserializer.d.ts +24 -0
- package/dist/types/deserializer/comment/hint-deserializer.d.ts +26 -0
- package/dist/types/deserializer/comment/metadata-comment-deserializer.d.ts +26 -0
- package/dist/types/deserializer/comment/pre-processor-comment-deserializer.d.ts +29 -0
- package/dist/types/deserializer/comment/simple-comment-deserializer.d.ts +26 -0
- package/dist/types/deserializer/cosmetic/cosmetic-rule-deserializer.d.ts +18 -0
- package/dist/types/deserializer/cosmetic/css-injection-body-deserializer.d.ts +15 -0
- package/dist/types/deserializer/cosmetic/element-hiding-body-deserializer.d.ts +16 -0
- package/dist/types/deserializer/cosmetic/scriptlet-body/abp-snippet-injection-body-deserializer.d.ts +17 -0
- package/dist/types/deserializer/cosmetic/scriptlet-body/adg-scriptlet-injection-body-deserializer.d.ts +18 -0
- package/dist/types/deserializer/cosmetic/scriptlet-body/scriptlet-body-deserializer.d.ts +19 -0
- package/dist/types/deserializer/cosmetic/scriptlet-body/ubo-scriptlet-injection-body-deserializer.d.ts +17 -0
- package/dist/types/deserializer/empty-rule-deserializer.d.ts +16 -0
- package/dist/types/deserializer/filterlist-deserializer.d.ts +34 -0
- package/dist/types/deserializer/index.d.ts +2 -0
- package/dist/types/deserializer/invalid-rule-deserializer.d.ts +16 -0
- package/dist/types/deserializer/invalid-rule-error-node-deserializer.d.ts +16 -0
- package/dist/types/deserializer/misc/domain-list-deserializer.d.ts +15 -0
- package/dist/types/deserializer/misc/list-item-deserializer.d.ts +19 -0
- package/dist/types/deserializer/misc/list-items-deserializer.d.ts +16 -0
- package/dist/types/deserializer/misc/logical-expression-deserializer.d.ts +55 -0
- package/dist/types/deserializer/misc/modifier-deserializer.d.ts +18 -0
- package/dist/types/deserializer/misc/modifier-list-deserializer.d.ts +20 -0
- package/dist/types/deserializer/misc/parameter-list-deserializer.d.ts +18 -0
- package/dist/types/deserializer/misc/value-deserializer.d.ts +17 -0
- package/dist/types/deserializer/network/host-rule-deserializer.d.ts +18 -0
- package/dist/types/deserializer/network/hostname-list-deserializer.d.ts +15 -0
- package/dist/types/deserializer/network/network-rule-deserializer.d.ts +18 -0
- package/dist/types/deserializer/rule-deserializer.d.ts +17 -0
- package/dist/types/deserializer/syntax-deserialization-map.d.ts +2 -0
- package/dist/types/errors/adblock-syntax-error.d.ts +25 -0
- package/dist/types/errors/binary-schema-mismatch-error.d.ts +23 -0
- package/dist/types/errors/not-implemented-error.d.ts +14 -0
- package/dist/types/errors/rule-conversion-error.d.ts +14 -0
- package/dist/types/generator/base-generator.d.ts +12 -0
- package/dist/types/generator/comment/agent-comment-generator.d.ts +14 -0
- package/dist/types/generator/comment/agent-generator.d.ts +15 -0
- package/dist/types/generator/comment/comment-rule-generator.d.ts +14 -0
- package/dist/types/generator/comment/config-comment-generator.d.ts +14 -0
- package/dist/types/generator/comment/hint-comment-generator.d.ts +14 -0
- package/dist/types/generator/comment/hint-generator.d.ts +14 -0
- package/dist/types/generator/comment/index.d.ts +1 -0
- package/dist/types/generator/comment/metadata-comment-generator.d.ts +14 -0
- package/dist/types/generator/comment/pre-processor-comment-generator.d.ts +14 -0
- package/dist/types/generator/comment/simple-comment-generator.d.ts +14 -0
- package/dist/types/generator/cosmetic/body/abp-snippet-injection-body-generator.d.ts +15 -0
- package/dist/types/generator/cosmetic/body/adg-scriptlet-injection-body-generator.d.ts +21 -0
- package/dist/types/generator/cosmetic/body/ubo-scriptlet-injection-body-generator.d.ts +21 -0
- package/dist/types/generator/cosmetic/cosmetic-rule-body-generator.d.ts +20 -0
- package/dist/types/generator/cosmetic/cosmetic-rule-generator.d.ts +28 -0
- package/dist/types/generator/cosmetic/cosmetic-rule-pattern-generator.d.ts +18 -0
- package/dist/types/generator/cosmetic/index.d.ts +1 -0
- package/dist/types/generator/css/adg-css-injection-generator.d.ts +15 -0
- package/dist/types/generator/css/ubo-selector-generator.d.ts +14 -0
- package/dist/types/generator/filterlist-generator.d.ts +18 -0
- package/dist/types/generator/index.d.ts +3 -0
- package/dist/types/generator/misc/domain-list-generator.d.ts +15 -0
- package/dist/types/generator/misc/list-items-generator.d.ts +25 -0
- package/dist/types/generator/misc/logical-expression-generator.d.ts +14 -0
- package/dist/types/generator/misc/modifier-generator.d.ts +14 -0
- package/dist/types/generator/misc/modifier-list-generator.d.ts +14 -0
- package/dist/types/generator/misc/parameter-list-generator.d.ts +15 -0
- package/dist/types/generator/misc/value-generator.d.ts +14 -0
- package/dist/types/generator/network/host-rule-generator.d.ts +14 -0
- package/dist/types/generator/network/index.d.ts +2 -0
- package/dist/types/generator/network/network-rule-generator.d.ts +14 -0
- package/dist/types/generator/rule-generator.d.ts +24 -0
- package/dist/types/index.d.ts +55 -0
- package/dist/types/marshalling-utils/comment/agent-comment-common.d.ts +14 -0
- package/dist/types/marshalling-utils/comment/agent-common.d.ts +20 -0
- package/dist/types/marshalling-utils/comment/config-comment-common.d.ts +42 -0
- package/dist/types/marshalling-utils/comment/hint-comment-common.d.ts +15 -0
- package/dist/types/marshalling-utils/comment/hint-common.d.ts +33 -0
- package/dist/types/marshalling-utils/comment/metadata-comment-common.d.ts +21 -0
- package/dist/types/marshalling-utils/comment/pre-processor-comment-common.d.ts +37 -0
- package/dist/types/marshalling-utils/comment/simple-comment-common.d.ts +15 -0
- package/dist/types/marshalling-utils/cosmetic/body/abp-snippet-injection-body-common.d.ts +23 -0
- package/dist/types/marshalling-utils/cosmetic/body/adg-scriptlet-injection-body-common.d.ts +9 -0
- package/dist/types/marshalling-utils/cosmetic/body/css-injection-body-common.d.ts +17 -0
- package/dist/types/marshalling-utils/cosmetic/body/element-hiding-body-common.d.ts +14 -0
- package/dist/types/marshalling-utils/cosmetic/body/ubo-scriptlet-injection-body-common.d.ts +9 -0
- package/dist/types/marshalling-utils/cosmetic/cosmetic-rule-common.d.ts +28 -0
- package/dist/types/marshalling-utils/empty-rule-common.d.ts +13 -0
- package/dist/types/marshalling-utils/filter-list-common.d.ts +14 -0
- package/dist/types/marshalling-utils/invalid-rule-common.d.ts +14 -0
- package/dist/types/marshalling-utils/invalid-rule-error-node-common.d.ts +15 -0
- package/dist/types/marshalling-utils/misc/binary-type-common.d.ts +57 -0
- package/dist/types/marshalling-utils/misc/domain-list-common.d.ts +24 -0
- package/dist/types/marshalling-utils/misc/host-rule-common.d.ts +18 -0
- package/dist/types/marshalling-utils/misc/hostname-list-common.d.ts +14 -0
- package/dist/types/marshalling-utils/misc/list-item-common.d.ts +15 -0
- package/dist/types/marshalling-utils/misc/logical-expression-common.d.ts +47 -0
- package/dist/types/marshalling-utils/misc/modifier-common.d.ts +41 -0
- package/dist/types/marshalling-utils/misc/modifier-list-common.d.ts +14 -0
- package/dist/types/marshalling-utils/misc/parameter-list-common.d.ts +14 -0
- package/dist/types/marshalling-utils/misc/value-common.d.ts +15 -0
- package/dist/types/marshalling-utils/network/network-rule-common.d.ts +18 -0
- package/dist/types/marshalling-utils/syntax-serialization-map.d.ts +2 -0
- package/dist/types/nodes/index.d.ts +1183 -0
- package/dist/types/parser/base-parser.d.ts +16 -0
- package/dist/types/parser/comment/agent-comment-parser.d.ts +42 -0
- package/dist/types/parser/comment/agent-parser.d.ts +33 -0
- package/dist/types/parser/comment/comment-parser.d.ts +76 -0
- package/dist/types/parser/comment/config-comment-parser.d.ts +31 -0
- package/dist/types/parser/comment/hint-comment-parser.d.ts +33 -0
- package/dist/types/parser/comment/hint-parser.d.ts +30 -0
- package/dist/types/parser/comment/metadata-comment-parser.d.ts +29 -0
- package/dist/types/parser/comment/preprocessor-parser.d.ts +43 -0
- package/dist/types/parser/comment/simple-comment-parser.d.ts +33 -0
- package/dist/types/parser/cosmetic/body/abp-snippet-injection-body-parser.d.ts +34 -0
- package/dist/types/parser/cosmetic/body/adg-scriptlet-injection-body-parser.d.ts +47 -0
- package/dist/types/parser/cosmetic/body/ubo-scriptlet-injection-body-parser.d.ts +44 -0
- package/dist/types/parser/cosmetic/cosmetic-rule-parser.d.ts +51 -0
- package/dist/types/parser/css/adg-css-injection-parser.d.ts +28 -0
- package/dist/types/parser/css/balancing.d.ts +36 -0
- package/dist/types/parser/css/constants.d.ts +10 -0
- package/dist/types/parser/css/css-token-stream.d.ts +210 -0
- package/dist/types/parser/css/ubo-selector-parser.d.ts +46 -0
- package/dist/types/parser/filterlist-parser.d.ts +29 -0
- package/dist/types/parser/index.d.ts +6 -0
- package/dist/types/parser/misc/app-list-parser.d.ts +22 -0
- package/dist/types/parser/misc/domain-list-parser.d.ts +26 -0
- package/dist/types/parser/misc/list-items-parser.d.ts +37 -0
- package/dist/types/parser/misc/logical-expression-parser.d.ts +42 -0
- package/dist/types/parser/misc/method-list-parser.d.ts +22 -0
- package/dist/types/parser/misc/modifier-list.d.ts +24 -0
- package/dist/types/parser/misc/modifier-parser.d.ts +21 -0
- package/dist/types/parser/misc/parameter-list-parser.d.ts +17 -0
- package/dist/types/parser/misc/stealth-option-list-parser.d.ts +22 -0
- package/dist/types/parser/misc/ubo-parameter-list-parser.d.ts +21 -0
- package/dist/types/parser/misc/value-parser.d.ts +18 -0
- package/dist/types/parser/network/host-rule-parser.d.ts +35 -0
- package/dist/types/parser/network/network-rule-parser.d.ts +31 -0
- package/dist/types/parser/options.d.ts +41 -0
- package/dist/types/parser/rule-parser.d.ts +78 -0
- package/dist/types/serializer/base-serializer.d.ts +15 -0
- package/dist/types/serializer/comment/agent-comment-serializer.d.ts +34 -0
- package/dist/types/serializer/comment/agent-serializer.d.ts +15 -0
- package/dist/types/serializer/comment/comment-rule-serializer.d.ts +68 -0
- package/dist/types/serializer/comment/config-comment-serializer.d.ts +25 -0
- package/dist/types/serializer/comment/hint-comment-serializer.d.ts +23 -0
- package/dist/types/serializer/comment/hint-serializer.d.ts +24 -0
- package/dist/types/serializer/comment/metadata-comment-serializer.d.ts +25 -0
- package/dist/types/serializer/comment/pre-processor-comment-serializer.d.ts +28 -0
- package/dist/types/serializer/comment/simple-comment-serializer.d.ts +24 -0
- package/dist/types/serializer/cosmetic/body/abp-snippet-injection-body-serializer.d.ts +25 -0
- package/dist/types/serializer/cosmetic/body/adg-scriptlet-injection-body-serializer.d.ts +25 -0
- package/dist/types/serializer/cosmetic/body/scriptlet-body-serializer.d.ts +17 -0
- package/dist/types/serializer/cosmetic/body/ubo-scriptlet-injection-body-serializer.d.ts +25 -0
- package/dist/types/serializer/cosmetic/cosmetic-rule-serializer.d.ts +19 -0
- package/dist/types/serializer/cosmetic/css-injection-body-serializer.d.ts +15 -0
- package/dist/types/serializer/cosmetic/element-hiding-body-serializer.d.ts +15 -0
- package/dist/types/serializer/empty-rule-serializer.d.ts +15 -0
- package/dist/types/serializer/filterlist-serializer.d.ts +15 -0
- package/dist/types/serializer/index.d.ts +1 -0
- package/dist/types/serializer/invalid-rule-error-node-serializer.d.ts +15 -0
- package/dist/types/serializer/invalid-rule-serializer.d.ts +15 -0
- package/dist/types/serializer/misc/domain-list-serializer.d.ts +21 -0
- package/dist/types/serializer/misc/list-item-serializer.d.ts +16 -0
- package/dist/types/serializer/misc/list-items-serializer.d.ts +15 -0
- package/dist/types/serializer/misc/logical-expression-serializer.d.ts +52 -0
- package/dist/types/serializer/misc/modifier-list-serializer.d.ts +20 -0
- package/dist/types/serializer/misc/modifier-serializer.d.ts +18 -0
- package/dist/types/serializer/misc/parameter-list-serializer.d.ts +17 -0
- package/dist/types/serializer/misc/value-serializer.d.ts +17 -0
- package/dist/types/serializer/network/host-rule-serializer.d.ts +30 -0
- package/dist/types/serializer/network/hostname-list-serializer.d.ts +15 -0
- package/dist/types/serializer/network/network-rule-serializer.d.ts +18 -0
- package/dist/types/serializer/rule-serializer.d.ts +17 -0
- package/dist/types/utils/adblockers.d.ts +49 -0
- package/dist/types/utils/binary-schema-version.d.ts +9 -0
- package/dist/types/utils/byte-buffer.d.ts +54 -0
- package/dist/types/utils/categorizer.d.ts +14 -0
- package/dist/types/utils/clone.d.ts +15 -0
- package/dist/types/utils/constants.d.ts +188 -0
- package/dist/types/utils/cosmetic-rule-separator.d.ts +45 -0
- package/dist/types/utils/deep-freeze.d.ts +13 -0
- package/dist/types/utils/domain.d.ts +29 -0
- package/dist/types/utils/error.d.ts +8 -0
- package/dist/types/utils/index.d.ts +15 -0
- package/dist/types/utils/input-byte-buffer.d.ts +146 -0
- package/dist/types/utils/is-chromium.d.ts +7 -0
- package/dist/types/utils/logical-expression.d.ts +45 -0
- package/dist/types/utils/multi-value-map.d.ts +16 -0
- package/dist/types/utils/output-byte-buffer.d.ts +132 -0
- package/dist/types/utils/position-provider.d.ts +46 -0
- package/dist/types/utils/quotes.d.ts +94 -0
- package/dist/types/utils/regexp.d.ts +54 -0
- package/dist/types/utils/storage-interface.d.ts +23 -0
- package/dist/types/utils/string.d.ts +280 -0
- package/dist/types/utils/text-decoder-polyfill.d.ts +14 -0
- package/dist/types/utils/text-encoder-polyfill.d.ts +18 -0
- package/dist/types/utils/type-guards.d.ts +47 -0
- package/dist/types/validator/constants.d.ts +89 -0
- package/dist/types/validator/helpers.d.ts +37 -0
- package/dist/types/validator/index.d.ts +38 -0
- package/dist/types/validator/value.d.ts +12 -0
- package/dist/types/version.d.ts +5 -0
- package/dist/utils/adblockers.js +56 -0
- package/dist/utils/binary-schema-version.js +17 -0
- package/dist/utils/byte-buffer.js +91 -0
- package/dist/utils/categorizer.js +44 -0
- package/dist/utils/clone.js +28 -0
- package/dist/utils/constants.js +249 -0
- package/dist/utils/cosmetic-rule-separator.js +127 -0
- package/dist/utils/deep-freeze.js +32 -0
- package/dist/utils/domain.js +59 -0
- package/dist/utils/error.js +49 -0
- package/dist/utils/index.js +21 -0
- package/dist/utils/input-byte-buffer.js +265 -0
- package/dist/utils/is-chromium.js +20 -0
- package/dist/utils/logical-expression.js +92 -0
- package/dist/utils/multi-value-map.js +33 -0
- package/dist/utils/output-byte-buffer.js +231 -0
- package/dist/utils/position-provider.js +73 -0
- package/dist/utils/quotes.js +214 -0
- package/dist/utils/regexp.js +176 -0
- package/dist/utils/string.js +559 -0
- package/dist/utils/text-decoder-polyfill.js +107 -0
- package/dist/utils/text-encoder-polyfill.js +78 -0
- package/dist/utils/type-guards.js +47 -0
- package/dist/validator/constants.js +210 -0
- package/dist/validator/helpers.js +45 -0
- package/dist/validator/index.js +174 -0
- package/dist/validator/value.js +568 -0
- package/dist/version.js +18 -0
- package/package.json +61 -39
- package/dist/agtree.d.ts +0 -4155
- package/dist/agtree.js +0 -15819
- package/dist/agtree.mjs +0 -15720
- package/dist/compatibility-table-data.js +0 -12782
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AGTree v3.0.0-alpha.2 (build date: Tue, 17 Dec 2024 16:50:04 GMT)
|
|
3
|
+
* (c) 2024 Adguard Software Ltd.
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
+
*/
|
|
7
|
+
/* eslint-disable no-bitwise */
|
|
8
|
+
/**
|
|
9
|
+
* @file Core ByteBuffer implementation for handling binary data in chunks.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Core ByteBuffer implementation for handling binary data in chunks.
|
|
13
|
+
* This class allows for efficient byte storage and manipulation by organizing data into chunks
|
|
14
|
+
* and providing methods to read and write bytes.
|
|
15
|
+
*/
|
|
16
|
+
class ByteBuffer {
|
|
17
|
+
/**
|
|
18
|
+
* The size of each chunk in bytes (32 KB).
|
|
19
|
+
*/
|
|
20
|
+
// ! IMPORTANT: If you ever change this value, make sure to update optimized bitwise operations in the code.
|
|
21
|
+
static CHUNK_SIZE = 32768; // 32 * 1024
|
|
22
|
+
/**
|
|
23
|
+
* An array of Uint8Array chunks that make up the buffer.
|
|
24
|
+
*/
|
|
25
|
+
chunks;
|
|
26
|
+
/**
|
|
27
|
+
* The total number of chunks in the buffer.
|
|
28
|
+
*/
|
|
29
|
+
chunksLength;
|
|
30
|
+
/**
|
|
31
|
+
* Constructs a new ByteBuffer instance.
|
|
32
|
+
*
|
|
33
|
+
* @param chunks Optional array of chunks to initialize the ByteBuffer with.
|
|
34
|
+
* @param cloneChunks Flag indicating if the chunks should be cloned. For performance reasons,
|
|
35
|
+
* its default value is `false`. If the original chunks are guaranteed not to change,
|
|
36
|
+
* leave this flag as `false` to avoid unnecessary copying.
|
|
37
|
+
*/
|
|
38
|
+
constructor(chunks, cloneChunks = false) {
|
|
39
|
+
const chunksToUse = chunks ?? [];
|
|
40
|
+
this.chunks = cloneChunks ? chunksToUse.map((chunk) => new Uint8Array(chunk)) : chunksToUse;
|
|
41
|
+
this.chunksLength = chunks?.length ?? 0;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Ensures that the buffer has enough capacity to accommodate a given position.
|
|
45
|
+
* This method adjusts the `chunks` array size to ensure it can hold the specified position.
|
|
46
|
+
*
|
|
47
|
+
* @param position The position to ensure capacity for.
|
|
48
|
+
*/
|
|
49
|
+
ensureCapacity(position) {
|
|
50
|
+
// same as Math.floor(position / chunk size), just optimized for the 32 KB chunk size
|
|
51
|
+
const requiredChunkIndex = position >>> 0x000F;
|
|
52
|
+
for (let i = this.chunksLength; i <= requiredChunkIndex; i += 1) {
|
|
53
|
+
this.chunks.push(new Uint8Array(ByteBuffer.CHUNK_SIZE));
|
|
54
|
+
this.chunksLength += 1;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Writes a byte to the buffer at the specified position.
|
|
59
|
+
* If the position is outside of the buffer's current size, the buffer is resized to accommodate it.
|
|
60
|
+
*
|
|
61
|
+
* @param position The position at which to write the byte.
|
|
62
|
+
* @param value The byte value to write (0-255).
|
|
63
|
+
*/
|
|
64
|
+
writeByte(position, value) {
|
|
65
|
+
// same as Math.floor(position / chunk size), just optimized for the 32 KB chunk size
|
|
66
|
+
const chunkIndex = position >>> 0x000F;
|
|
67
|
+
// same as position % chunk size, just optimized for the 32 KB chunk size
|
|
68
|
+
const chunkOffset = position & 0x7FFF;
|
|
69
|
+
if (chunkIndex >= this.chunksLength) {
|
|
70
|
+
this.ensureCapacity(position);
|
|
71
|
+
}
|
|
72
|
+
this.chunks[chunkIndex][chunkOffset] = value;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Reads a byte from the specified position in the buffer.
|
|
76
|
+
* Returns `undefined` if the position is outside of the buffer's current size.
|
|
77
|
+
*
|
|
78
|
+
* @param position The position from which to read the byte.
|
|
79
|
+
* @returns The read byte value, or `undefined` if the position is out of bounds.
|
|
80
|
+
*/
|
|
81
|
+
readByte(position) {
|
|
82
|
+
const chunkIndex = position >>> 0x000F;
|
|
83
|
+
const chunkOffset = position & 0x7FFF;
|
|
84
|
+
if (chunkIndex >= this.chunksLength) {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
return this.chunks[chunkIndex][chunkOffset];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export { ByteBuffer };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AGTree v3.0.0-alpha.2 (build date: Tue, 17 Dec 2024 16:50:04 GMT)
|
|
3
|
+
* (c) 2024 Adguard Software Ltd.
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
+
*/
|
|
7
|
+
import { CosmeticRuleParser } from '../parser/cosmetic/cosmetic-rule-parser.js';
|
|
8
|
+
import { isNull } from './type-guards.js';
|
|
9
|
+
import { defaultParserOptions } from '../parser/options.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Utility functions for categorizing rules.
|
|
13
|
+
*/
|
|
14
|
+
// TODO: Optimize functions to avoid produce unnecessary data (currently, most of node data is not used).
|
|
15
|
+
// TODO: Add support for other rule categories, like network rules (when needed).
|
|
16
|
+
class RuleCategorizer {
|
|
17
|
+
/**
|
|
18
|
+
* Determines the type of a given raw cosmetic rule.
|
|
19
|
+
*
|
|
20
|
+
* @param rawRule Raw rule to check.
|
|
21
|
+
*
|
|
22
|
+
* @returns Type of the cosmetic rule or `null` if the rule is cannot be parsed as a cosmetic rule.
|
|
23
|
+
*/
|
|
24
|
+
static getCosmeticRuleType(rawRule) {
|
|
25
|
+
try {
|
|
26
|
+
const node = CosmeticRuleParser.parse(rawRule, {
|
|
27
|
+
...defaultParserOptions,
|
|
28
|
+
isLocIncluded: false,
|
|
29
|
+
includeRaws: false,
|
|
30
|
+
});
|
|
31
|
+
// If rule cannot be recognized as a cosmetic rule, return null.
|
|
32
|
+
if (isNull(node)) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return node.type;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// Be tolerant to parsing errors and simply return null.
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { RuleCategorizer };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AGTree v3.0.0-alpha.2 (build date: Tue, 17 Dec 2024 16:50:04 GMT)
|
|
3
|
+
* (c) 2024 Adguard Software Ltd.
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
+
*/
|
|
7
|
+
import cloneDeep from 'clone-deep';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @file Clone related utilities
|
|
11
|
+
*
|
|
12
|
+
* We should keep clone related functions in this file. Thus, we just provide
|
|
13
|
+
* a simple interface for cloning values, we use it across the AGTree project,
|
|
14
|
+
* and the implementation "under the hood" can be improved later, if needed.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Clones an input value to avoid side effects. Use it only in justified cases,
|
|
18
|
+
* because it can impact performance negatively.
|
|
19
|
+
*
|
|
20
|
+
* @param value Value to clone
|
|
21
|
+
* @returns Cloned value
|
|
22
|
+
*/
|
|
23
|
+
function clone(value) {
|
|
24
|
+
// TODO: Replace cloneDeep with a more efficient implementation
|
|
25
|
+
return cloneDeep(value);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { clone };
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AGTree v3.0.0-alpha.2 (build date: Tue, 17 Dec 2024 16:50:04 GMT)
|
|
3
|
+
* (c) 2024 Adguard Software Ltd.
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* @file Constant values used by all parts of the library
|
|
9
|
+
*/
|
|
10
|
+
// TODO: remove unused constants
|
|
11
|
+
// General
|
|
12
|
+
/**
|
|
13
|
+
* Empty string.
|
|
14
|
+
*/
|
|
15
|
+
const EMPTY = '';
|
|
16
|
+
const SPACE = ' ';
|
|
17
|
+
const TAB = '\t';
|
|
18
|
+
const COLON = ':';
|
|
19
|
+
const COMMA = ',';
|
|
20
|
+
const DOT = '.';
|
|
21
|
+
const SEMICOLON = ';';
|
|
22
|
+
const AMPERSAND = '&';
|
|
23
|
+
const ASTERISK = '*';
|
|
24
|
+
const AT_SIGN = '@';
|
|
25
|
+
const CARET = '^';
|
|
26
|
+
const DOLLAR_SIGN = '$';
|
|
27
|
+
const EQUALS = '=';
|
|
28
|
+
const EXCLAMATION_MARK = '!';
|
|
29
|
+
const HASHMARK = '#';
|
|
30
|
+
const PIPE = '|';
|
|
31
|
+
const PLUS = '+';
|
|
32
|
+
const QUESTION_MARK = '?';
|
|
33
|
+
const SLASH = '/';
|
|
34
|
+
const UNDERSCORE = '_';
|
|
35
|
+
// Escape characters
|
|
36
|
+
const BACKSLASH = '\\';
|
|
37
|
+
const ESCAPE_CHARACTER = BACKSLASH;
|
|
38
|
+
// Newlines
|
|
39
|
+
const CR = '\r';
|
|
40
|
+
const FF = '\f';
|
|
41
|
+
const LF = '\n';
|
|
42
|
+
const CRLF = CR + LF;
|
|
43
|
+
const NEWLINE = LF;
|
|
44
|
+
// Quotes
|
|
45
|
+
const BACKTICK_QUOTE = '`';
|
|
46
|
+
const DOUBLE_QUOTE = '"';
|
|
47
|
+
const SINGLE_QUOTE = '\'';
|
|
48
|
+
// Brackets
|
|
49
|
+
const OPEN_PARENTHESIS = '(';
|
|
50
|
+
const CLOSE_PARENTHESIS = ')';
|
|
51
|
+
const OPEN_SQUARE_BRACKET = '[';
|
|
52
|
+
const CLOSE_SQUARE_BRACKET = ']';
|
|
53
|
+
const OPEN_CURLY_BRACKET = '{';
|
|
54
|
+
const CLOSE_CURLY_BRACKET = '}';
|
|
55
|
+
// Letters
|
|
56
|
+
const SMALL_LETTER_A = 'a';
|
|
57
|
+
const SMALL_LETTER_B = 'b';
|
|
58
|
+
const SMALL_LETTER_C = 'c';
|
|
59
|
+
const SMALL_LETTER_D = 'd';
|
|
60
|
+
const SMALL_LETTER_E = 'e';
|
|
61
|
+
const SMALL_LETTER_F = 'f';
|
|
62
|
+
const SMALL_LETTER_G = 'g';
|
|
63
|
+
const SMALL_LETTER_H = 'h';
|
|
64
|
+
const SMALL_LETTER_I = 'i';
|
|
65
|
+
const SMALL_LETTER_J = 'j';
|
|
66
|
+
const SMALL_LETTER_K = 'k';
|
|
67
|
+
const SMALL_LETTER_L = 'l';
|
|
68
|
+
const SMALL_LETTER_M = 'm';
|
|
69
|
+
const SMALL_LETTER_N = 'n';
|
|
70
|
+
const SMALL_LETTER_O = 'o';
|
|
71
|
+
const SMALL_LETTER_P = 'p';
|
|
72
|
+
const SMALL_LETTER_Q = 'q';
|
|
73
|
+
const SMALL_LETTER_R = 'r';
|
|
74
|
+
const SMALL_LETTER_S = 's';
|
|
75
|
+
const SMALL_LETTER_T = 't';
|
|
76
|
+
const SMALL_LETTER_U = 'u';
|
|
77
|
+
const SMALL_LETTER_V = 'v';
|
|
78
|
+
const SMALL_LETTER_W = 'w';
|
|
79
|
+
const SMALL_LETTER_X = 'x';
|
|
80
|
+
const SMALL_LETTER_Y = 'y';
|
|
81
|
+
const SMALL_LETTER_Z = 'z';
|
|
82
|
+
/**
|
|
83
|
+
* Set of all small letters.
|
|
84
|
+
*/
|
|
85
|
+
const SMALL_LETTERS = new Set([
|
|
86
|
+
SMALL_LETTER_A,
|
|
87
|
+
SMALL_LETTER_B,
|
|
88
|
+
SMALL_LETTER_C,
|
|
89
|
+
SMALL_LETTER_D,
|
|
90
|
+
SMALL_LETTER_E,
|
|
91
|
+
SMALL_LETTER_F,
|
|
92
|
+
SMALL_LETTER_G,
|
|
93
|
+
SMALL_LETTER_H,
|
|
94
|
+
SMALL_LETTER_I,
|
|
95
|
+
SMALL_LETTER_J,
|
|
96
|
+
SMALL_LETTER_K,
|
|
97
|
+
SMALL_LETTER_L,
|
|
98
|
+
SMALL_LETTER_M,
|
|
99
|
+
SMALL_LETTER_N,
|
|
100
|
+
SMALL_LETTER_O,
|
|
101
|
+
SMALL_LETTER_P,
|
|
102
|
+
SMALL_LETTER_Q,
|
|
103
|
+
SMALL_LETTER_R,
|
|
104
|
+
SMALL_LETTER_S,
|
|
105
|
+
SMALL_LETTER_T,
|
|
106
|
+
SMALL_LETTER_U,
|
|
107
|
+
SMALL_LETTER_V,
|
|
108
|
+
SMALL_LETTER_W,
|
|
109
|
+
SMALL_LETTER_X,
|
|
110
|
+
SMALL_LETTER_Y,
|
|
111
|
+
SMALL_LETTER_Z,
|
|
112
|
+
]);
|
|
113
|
+
// Capital letters
|
|
114
|
+
const CAPITAL_LETTER_A = 'A';
|
|
115
|
+
const CAPITAL_LETTER_B = 'B';
|
|
116
|
+
const CAPITAL_LETTER_C = 'C';
|
|
117
|
+
const CAPITAL_LETTER_D = 'D';
|
|
118
|
+
const CAPITAL_LETTER_E = 'E';
|
|
119
|
+
const CAPITAL_LETTER_F = 'F';
|
|
120
|
+
const CAPITAL_LETTER_G = 'G';
|
|
121
|
+
const CAPITAL_LETTER_H = 'H';
|
|
122
|
+
const CAPITAL_LETTER_I = 'I';
|
|
123
|
+
const CAPITAL_LETTER_J = 'J';
|
|
124
|
+
const CAPITAL_LETTER_K = 'K';
|
|
125
|
+
const CAPITAL_LETTER_L = 'L';
|
|
126
|
+
const CAPITAL_LETTER_M = 'M';
|
|
127
|
+
const CAPITAL_LETTER_N = 'N';
|
|
128
|
+
const CAPITAL_LETTER_O = 'O';
|
|
129
|
+
const CAPITAL_LETTER_P = 'P';
|
|
130
|
+
const CAPITAL_LETTER_Q = 'Q';
|
|
131
|
+
const CAPITAL_LETTER_R = 'R';
|
|
132
|
+
const CAPITAL_LETTER_S = 'S';
|
|
133
|
+
const CAPITAL_LETTER_T = 'T';
|
|
134
|
+
const CAPITAL_LETTER_U = 'U';
|
|
135
|
+
const CAPITAL_LETTER_V = 'V';
|
|
136
|
+
const CAPITAL_LETTER_W = 'W';
|
|
137
|
+
const CAPITAL_LETTER_X = 'X';
|
|
138
|
+
const CAPITAL_LETTER_Y = 'Y';
|
|
139
|
+
const CAPITAL_LETTER_Z = 'Z';
|
|
140
|
+
/**
|
|
141
|
+
* Set of all capital letters.
|
|
142
|
+
*/
|
|
143
|
+
const CAPITAL_LETTERS = new Set([
|
|
144
|
+
CAPITAL_LETTER_A,
|
|
145
|
+
CAPITAL_LETTER_B,
|
|
146
|
+
CAPITAL_LETTER_C,
|
|
147
|
+
CAPITAL_LETTER_D,
|
|
148
|
+
CAPITAL_LETTER_E,
|
|
149
|
+
CAPITAL_LETTER_F,
|
|
150
|
+
CAPITAL_LETTER_G,
|
|
151
|
+
CAPITAL_LETTER_H,
|
|
152
|
+
CAPITAL_LETTER_I,
|
|
153
|
+
CAPITAL_LETTER_J,
|
|
154
|
+
CAPITAL_LETTER_K,
|
|
155
|
+
CAPITAL_LETTER_L,
|
|
156
|
+
CAPITAL_LETTER_M,
|
|
157
|
+
CAPITAL_LETTER_N,
|
|
158
|
+
CAPITAL_LETTER_O,
|
|
159
|
+
CAPITAL_LETTER_P,
|
|
160
|
+
CAPITAL_LETTER_Q,
|
|
161
|
+
CAPITAL_LETTER_R,
|
|
162
|
+
CAPITAL_LETTER_S,
|
|
163
|
+
CAPITAL_LETTER_T,
|
|
164
|
+
CAPITAL_LETTER_U,
|
|
165
|
+
CAPITAL_LETTER_V,
|
|
166
|
+
CAPITAL_LETTER_W,
|
|
167
|
+
CAPITAL_LETTER_X,
|
|
168
|
+
CAPITAL_LETTER_Y,
|
|
169
|
+
CAPITAL_LETTER_Z,
|
|
170
|
+
]);
|
|
171
|
+
// Numbers as strings
|
|
172
|
+
const NUMBER_0 = '0';
|
|
173
|
+
const NUMBER_1 = '1';
|
|
174
|
+
const NUMBER_2 = '2';
|
|
175
|
+
const NUMBER_3 = '3';
|
|
176
|
+
const NUMBER_4 = '4';
|
|
177
|
+
const NUMBER_5 = '5';
|
|
178
|
+
const NUMBER_6 = '6';
|
|
179
|
+
const NUMBER_7 = '7';
|
|
180
|
+
const NUMBER_8 = '8';
|
|
181
|
+
const NUMBER_9 = '9';
|
|
182
|
+
/**
|
|
183
|
+
* Set of all numbers as strings.
|
|
184
|
+
*/
|
|
185
|
+
const NUMBERS = new Set([
|
|
186
|
+
NUMBER_0,
|
|
187
|
+
NUMBER_1,
|
|
188
|
+
NUMBER_2,
|
|
189
|
+
NUMBER_3,
|
|
190
|
+
NUMBER_4,
|
|
191
|
+
NUMBER_5,
|
|
192
|
+
NUMBER_6,
|
|
193
|
+
NUMBER_7,
|
|
194
|
+
NUMBER_8,
|
|
195
|
+
NUMBER_9,
|
|
196
|
+
]);
|
|
197
|
+
const REGEX_MARKER = '/';
|
|
198
|
+
const ADG_SCRIPTLET_MASK = '//scriptlet';
|
|
199
|
+
const UBO_SCRIPTLET_MASK = '+js';
|
|
200
|
+
const UBO_SCRIPTLET_MASK_LEGACY = 'script:inject';
|
|
201
|
+
const UBO_HTML_MASK = '^';
|
|
202
|
+
// Modifiers are separated by ",". For example: "script,domain=example.com"
|
|
203
|
+
const MODIFIERS_SEPARATOR = ',';
|
|
204
|
+
const MODIFIER_ASSIGN_OPERATOR = '=';
|
|
205
|
+
const NEGATION_MARKER = '~';
|
|
206
|
+
/**
|
|
207
|
+
* The wildcard symbol — `*`.
|
|
208
|
+
*/
|
|
209
|
+
const WILDCARD = ASTERISK;
|
|
210
|
+
/**
|
|
211
|
+
* Classic domain separator.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```adblock
|
|
215
|
+
* ! Domains are separated by ",":
|
|
216
|
+
* example.com,~example.org##.ads
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
const COMMA_DOMAIN_LIST_SEPARATOR = ',';
|
|
220
|
+
/**
|
|
221
|
+
* Modifier separator for $app, $denyallow, $domain, $method.
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```adblock
|
|
225
|
+
* ! Domains are separated by "|":
|
|
226
|
+
* ads.js^$script,domains=example.com|~example.org
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
const PIPE_MODIFIER_SEPARATOR = '|';
|
|
230
|
+
const CSS_MEDIA_MARKER = '@media';
|
|
231
|
+
const CSS_NOT_PSEUDO = 'not';
|
|
232
|
+
const HINT_MARKER = '!+';
|
|
233
|
+
const HINT_MARKER_LEN = HINT_MARKER.length;
|
|
234
|
+
const NETWORK_RULE_EXCEPTION_MARKER = '@@';
|
|
235
|
+
const NETWORK_RULE_EXCEPTION_MARKER_LEN = NETWORK_RULE_EXCEPTION_MARKER.length;
|
|
236
|
+
const NETWORK_RULE_SEPARATOR = '$';
|
|
237
|
+
const AGLINT_COMMAND_PREFIX = 'aglint';
|
|
238
|
+
const AGLINT_CONFIG_COMMENT_MARKER = '--';
|
|
239
|
+
const PREPROCESSOR_MARKER = '!#';
|
|
240
|
+
const PREPROCESSOR_MARKER_LEN = PREPROCESSOR_MARKER.length;
|
|
241
|
+
const PREPROCESSOR_SEPARATOR = ' ';
|
|
242
|
+
const SAFARI_CB_AFFINITY = 'safari_cb_affinity';
|
|
243
|
+
const IF = 'if';
|
|
244
|
+
const INCLUDE = 'include';
|
|
245
|
+
const NULL = 0;
|
|
246
|
+
const UINT8_MAX = 255;
|
|
247
|
+
const UINT16_MAX = 65535;
|
|
248
|
+
|
|
249
|
+
export { ADG_SCRIPTLET_MASK, AGLINT_COMMAND_PREFIX, AGLINT_CONFIG_COMMENT_MARKER, AMPERSAND, ASTERISK, AT_SIGN, BACKSLASH, BACKTICK_QUOTE, CAPITAL_LETTERS, CAPITAL_LETTER_A, CAPITAL_LETTER_B, CAPITAL_LETTER_C, CAPITAL_LETTER_D, CAPITAL_LETTER_E, CAPITAL_LETTER_F, CAPITAL_LETTER_G, CAPITAL_LETTER_H, CAPITAL_LETTER_I, CAPITAL_LETTER_J, CAPITAL_LETTER_K, CAPITAL_LETTER_L, CAPITAL_LETTER_M, CAPITAL_LETTER_N, CAPITAL_LETTER_O, CAPITAL_LETTER_P, CAPITAL_LETTER_Q, CAPITAL_LETTER_R, CAPITAL_LETTER_S, CAPITAL_LETTER_T, CAPITAL_LETTER_U, CAPITAL_LETTER_V, CAPITAL_LETTER_W, CAPITAL_LETTER_X, CAPITAL_LETTER_Y, CAPITAL_LETTER_Z, CARET, CLOSE_CURLY_BRACKET, CLOSE_PARENTHESIS, CLOSE_SQUARE_BRACKET, COLON, COMMA, COMMA_DOMAIN_LIST_SEPARATOR, CR, CRLF, CSS_MEDIA_MARKER, CSS_NOT_PSEUDO, DOLLAR_SIGN, DOT, DOUBLE_QUOTE, EMPTY, EQUALS, ESCAPE_CHARACTER, EXCLAMATION_MARK, FF, HASHMARK, HINT_MARKER, HINT_MARKER_LEN, IF, INCLUDE, LF, MODIFIERS_SEPARATOR, MODIFIER_ASSIGN_OPERATOR, NEGATION_MARKER, NETWORK_RULE_EXCEPTION_MARKER, NETWORK_RULE_EXCEPTION_MARKER_LEN, NETWORK_RULE_SEPARATOR, NEWLINE, NULL, NUMBERS, NUMBER_0, NUMBER_1, NUMBER_2, NUMBER_3, NUMBER_4, NUMBER_5, NUMBER_6, NUMBER_7, NUMBER_8, NUMBER_9, OPEN_CURLY_BRACKET, OPEN_PARENTHESIS, OPEN_SQUARE_BRACKET, PIPE, PIPE_MODIFIER_SEPARATOR, PLUS, PREPROCESSOR_MARKER, PREPROCESSOR_MARKER_LEN, PREPROCESSOR_SEPARATOR, QUESTION_MARK, REGEX_MARKER, SAFARI_CB_AFFINITY, SEMICOLON, SINGLE_QUOTE, SLASH, SMALL_LETTERS, SMALL_LETTER_A, SMALL_LETTER_B, SMALL_LETTER_C, SMALL_LETTER_D, SMALL_LETTER_E, SMALL_LETTER_F, SMALL_LETTER_G, SMALL_LETTER_H, SMALL_LETTER_I, SMALL_LETTER_J, SMALL_LETTER_K, SMALL_LETTER_L, SMALL_LETTER_M, SMALL_LETTER_N, SMALL_LETTER_O, SMALL_LETTER_P, SMALL_LETTER_Q, SMALL_LETTER_R, SMALL_LETTER_S, SMALL_LETTER_T, SMALL_LETTER_U, SMALL_LETTER_V, SMALL_LETTER_W, SMALL_LETTER_X, SMALL_LETTER_Y, SMALL_LETTER_Z, SPACE, TAB, UBO_HTML_MASK, UBO_SCRIPTLET_MASK, UBO_SCRIPTLET_MASK_LEGACY, UINT16_MAX, UINT8_MAX, UNDERSCORE, WILDCARD };
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AGTree v3.0.0-alpha.2 (build date: Tue, 17 Dec 2024 16:50:04 GMT)
|
|
3
|
+
* (c) 2024 Adguard Software Ltd.
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
+
*/
|
|
7
|
+
import { CosmeticRuleSeparator } from '../nodes/index.js';
|
|
8
|
+
import { AT_SIGN, SPACE } from './constants.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @file Cosmetic rule separator finder and categorizer
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Utility class for cosmetic rule separators.
|
|
15
|
+
*/
|
|
16
|
+
class CosmeticRuleSeparatorUtils {
|
|
17
|
+
/**
|
|
18
|
+
* Checks whether the specified separator is an exception.
|
|
19
|
+
*
|
|
20
|
+
* @param separator Separator to check
|
|
21
|
+
* @returns `true` if the separator is an exception, `false` otherwise
|
|
22
|
+
*/
|
|
23
|
+
static isException(separator) {
|
|
24
|
+
// Simply check the second character
|
|
25
|
+
return separator[1] === AT_SIGN;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Checks whether the specified separator is marks an Extended CSS cosmetic rule.
|
|
29
|
+
*
|
|
30
|
+
* @param separator Separator to check
|
|
31
|
+
* @returns `true` if the separator is marks an Extended CSS cosmetic rule, `false` otherwise
|
|
32
|
+
*/
|
|
33
|
+
static isExtendedCssMarker(separator) {
|
|
34
|
+
return (separator === CosmeticRuleSeparator.ExtendedElementHiding
|
|
35
|
+
|| separator === CosmeticRuleSeparator.ExtendedElementHidingException
|
|
36
|
+
|| separator === CosmeticRuleSeparator.AdgExtendedCssInjection
|
|
37
|
+
|| separator === CosmeticRuleSeparator.AdgExtendedCssInjectionException);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Looks for the cosmetic rule separator in the rule. This is a simplified version that
|
|
41
|
+
* masks the recursive function.
|
|
42
|
+
*
|
|
43
|
+
* @param rule Raw rule
|
|
44
|
+
* @returns Separator result or null if no separator was found
|
|
45
|
+
*/
|
|
46
|
+
static find(rule) {
|
|
47
|
+
/**
|
|
48
|
+
* Helper function to create results of the `find` method.
|
|
49
|
+
*
|
|
50
|
+
* @param start Start position
|
|
51
|
+
* @param separator Separator type
|
|
52
|
+
* @returns Cosmetic rule separator node
|
|
53
|
+
*/
|
|
54
|
+
// eslint-disable-next-line max-len
|
|
55
|
+
function createResult(start, separator) {
|
|
56
|
+
return {
|
|
57
|
+
separator,
|
|
58
|
+
start,
|
|
59
|
+
end: start + separator.length,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
for (let i = 0; i < rule.length; i += 1) {
|
|
63
|
+
if (rule[i] === '#') {
|
|
64
|
+
if (rule[i + 1] === '#' && rule[i - 1] !== SPACE) {
|
|
65
|
+
// ##
|
|
66
|
+
return createResult(i, CosmeticRuleSeparator.ElementHiding);
|
|
67
|
+
}
|
|
68
|
+
if (rule[i + 1] === '?' && rule[i + 2] === '#') {
|
|
69
|
+
// #?#
|
|
70
|
+
return createResult(i, CosmeticRuleSeparator.ExtendedElementHiding);
|
|
71
|
+
}
|
|
72
|
+
if (rule[i + 1] === '%' && rule[i + 2] === '#') {
|
|
73
|
+
// #%#
|
|
74
|
+
return createResult(i, CosmeticRuleSeparator.AdgJsInjection);
|
|
75
|
+
}
|
|
76
|
+
if (rule[i + 1] === '$') {
|
|
77
|
+
if (rule[i + 2] === '#') {
|
|
78
|
+
// #$#
|
|
79
|
+
return createResult(i, CosmeticRuleSeparator.AdgCssInjection);
|
|
80
|
+
}
|
|
81
|
+
if (rule[i + 2] === '?' && rule[i + 3] === '#') {
|
|
82
|
+
// #$?#
|
|
83
|
+
return createResult(i, CosmeticRuleSeparator.AdgExtendedCssInjection);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// Exceptions
|
|
87
|
+
if (rule[i + 1] === '@') {
|
|
88
|
+
if (rule[i + 2] === '#' && rule[i - 1] !== SPACE) {
|
|
89
|
+
// #@#
|
|
90
|
+
return createResult(i, CosmeticRuleSeparator.ElementHidingException);
|
|
91
|
+
}
|
|
92
|
+
if (rule[i + 2] === '?' && rule[i + 3] === '#') {
|
|
93
|
+
// #@?#
|
|
94
|
+
return createResult(i, CosmeticRuleSeparator.ExtendedElementHidingException);
|
|
95
|
+
}
|
|
96
|
+
if (rule[i + 2] === '%' && rule[i + 3] === '#') {
|
|
97
|
+
// #@%#
|
|
98
|
+
return createResult(i, CosmeticRuleSeparator.AdgJsInjectionException);
|
|
99
|
+
}
|
|
100
|
+
if (rule[i + 2] === '$') {
|
|
101
|
+
if (rule[i + 3] === '#') {
|
|
102
|
+
// #@$#
|
|
103
|
+
return createResult(i, CosmeticRuleSeparator.AdgCssInjectionException);
|
|
104
|
+
}
|
|
105
|
+
if (rule[i + 3] === '?' && rule[i + 4] === '#') {
|
|
106
|
+
// #@$?#
|
|
107
|
+
return createResult(i, CosmeticRuleSeparator.AdgExtendedCssInjectionException);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (rule[i] === '$') {
|
|
113
|
+
if (rule[i + 1] === '$') {
|
|
114
|
+
// $$
|
|
115
|
+
return createResult(i, CosmeticRuleSeparator.AdgHtmlFiltering);
|
|
116
|
+
}
|
|
117
|
+
if (rule[i + 1] === '@' && rule[i + 2] === '$') {
|
|
118
|
+
// $@$
|
|
119
|
+
return createResult(i, CosmeticRuleSeparator.AdgHtmlFilteringException);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export { CosmeticRuleSeparatorUtils };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AGTree v3.0.0-alpha.2 (build date: Tue, 17 Dec 2024 16:50:04 GMT)
|
|
3
|
+
* (c) 2024 Adguard Software Ltd.
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Simple deep freeze implementation.
|
|
9
|
+
* It freezes the object and all its properties recursively.
|
|
10
|
+
*
|
|
11
|
+
* @param object Object to freeze.
|
|
12
|
+
*
|
|
13
|
+
* @returns Frozen object.
|
|
14
|
+
*
|
|
15
|
+
* @template T Type of the object to freeze.
|
|
16
|
+
*
|
|
17
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze#deep_freezing}
|
|
18
|
+
*/
|
|
19
|
+
const deepFreeze = (object) => {
|
|
20
|
+
// Retrieve the property names defined on object
|
|
21
|
+
const propNames = Reflect.ownKeys(object);
|
|
22
|
+
// Freeze properties before freezing self
|
|
23
|
+
for (const name of propNames) {
|
|
24
|
+
const value = object[name];
|
|
25
|
+
if ((value && typeof value === 'object') || typeof value === 'function') {
|
|
26
|
+
deepFreeze(value);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return Object.freeze(object);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { deepFreeze };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AGTree v3.0.0-alpha.2 (build date: Tue, 17 Dec 2024 16:50:04 GMT)
|
|
3
|
+
* (c) 2024 Adguard Software Ltd.
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
+
*/
|
|
7
|
+
import { parse } from 'tldts';
|
|
8
|
+
import { WILDCARD, DOT } from './constants.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @file Utility functions for domain and hostname validation.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Marker for a wildcard top-level domain — `.*`.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* `example.*` — matches with any TLD, e.g. `example.org`, `example.com`, etc.
|
|
18
|
+
*/
|
|
19
|
+
const WILDCARD_TLD = DOT + WILDCARD;
|
|
20
|
+
/**
|
|
21
|
+
* Marker for a wildcard subdomain — `*.`.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* `*.example.org` — matches with any subdomain, e.g. `foo.example.org` or `bar.example.org`
|
|
25
|
+
*/
|
|
26
|
+
const WILDCARD_SUBDOMAIN = WILDCARD + DOT;
|
|
27
|
+
/**
|
|
28
|
+
* Utility functions for domain and hostname validation.
|
|
29
|
+
*/
|
|
30
|
+
class DomainUtils {
|
|
31
|
+
/**
|
|
32
|
+
* Check if the input is a valid domain or hostname.
|
|
33
|
+
*
|
|
34
|
+
* @param domain Domain to check
|
|
35
|
+
* @returns `true` if the domain is valid, `false` otherwise
|
|
36
|
+
*/
|
|
37
|
+
static isValidDomainOrHostname(domain) {
|
|
38
|
+
let domainToCheck = domain;
|
|
39
|
+
// Wildcard-only domain, typically a generic rule
|
|
40
|
+
if (domainToCheck === WILDCARD) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
// https://adguard.com/kb/general/ad-filtering/create-own-filters/#wildcard-for-tld
|
|
44
|
+
if (domainToCheck.endsWith(WILDCARD_TLD)) {
|
|
45
|
+
// Remove the wildcard TLD
|
|
46
|
+
domainToCheck = domainToCheck.substring(0, domainToCheck.length - WILDCARD_TLD.length);
|
|
47
|
+
}
|
|
48
|
+
if (domainToCheck.startsWith(WILDCARD_SUBDOMAIN)) {
|
|
49
|
+
// Remove the wildcard subdomain
|
|
50
|
+
domainToCheck = domainToCheck.substring(WILDCARD_SUBDOMAIN.length);
|
|
51
|
+
}
|
|
52
|
+
// Parse the domain with tldts
|
|
53
|
+
const tldtsResult = parse(domainToCheck);
|
|
54
|
+
// Check if the domain is valid
|
|
55
|
+
return domainToCheck === tldtsResult.domain || domainToCheck === tldtsResult.hostname;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { DomainUtils, WILDCARD_SUBDOMAIN, WILDCARD_TLD };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AGTree v3.0.0-alpha.2 (build date: Tue, 17 Dec 2024 16:50:04 GMT)
|
|
3
|
+
* (c) 2024 Adguard Software Ltd.
|
|
4
|
+
* Released under the MIT license
|
|
5
|
+
* https://github.com/AdguardTeam/tsurlfilter/tree/master/packages/agtree#readme
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Checks if error has message.
|
|
9
|
+
*
|
|
10
|
+
* @param error Error object.
|
|
11
|
+
* @returns If param is error.
|
|
12
|
+
*/
|
|
13
|
+
function isErrorWithMessage(error) {
|
|
14
|
+
return (typeof error === 'object'
|
|
15
|
+
&& error !== null
|
|
16
|
+
&& 'message' in error
|
|
17
|
+
&& typeof error.message === 'string');
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Converts error to the error with message.
|
|
21
|
+
*
|
|
22
|
+
* @param maybeError Possible error.
|
|
23
|
+
* @returns Error with message.
|
|
24
|
+
*/
|
|
25
|
+
function toErrorWithMessage(maybeError) {
|
|
26
|
+
if (isErrorWithMessage(maybeError)) {
|
|
27
|
+
return maybeError;
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
return new Error(JSON.stringify(maybeError));
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// fallback in case there's an error stringifying the maybeError
|
|
34
|
+
// like with circular references for example.
|
|
35
|
+
return new Error(String(maybeError));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Converts error object to error with message. This method might be helpful to handle thrown errors.
|
|
40
|
+
*
|
|
41
|
+
* @param error Error object.
|
|
42
|
+
*
|
|
43
|
+
* @returns Message of the error.
|
|
44
|
+
*/
|
|
45
|
+
function getErrorMessage(error) {
|
|
46
|
+
return toErrorWithMessage(error).message;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { getErrorMessage };
|