@adguard/agtree 4.0.0 → 4.0.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 +4 -3
- package/dist/ast-utils/clone.js +12 -8
- package/dist/ast-utils/modifiers.js +13 -11
- package/dist/ast-utils/network-rules.js +10 -9
- package/dist/ast-utils/scriptlets.js +20 -18
- package/dist/common/abp-snippet-injection-body-common.js +1 -1
- package/dist/common/agent-common.js +1 -1
- package/dist/common/ubo-html-filtering-body-common.js +1 -1
- package/dist/common/ubo-selector-common.js +1 -1
- package/dist/compatibility-tables/base.js +7 -6
- package/dist/compatibility-tables/compatibility-table-data.js +1 -1
- package/dist/compatibility-tables/modifiers.js +4 -3
- package/dist/compatibility-tables/platforms.js +1 -1
- package/dist/compatibility-tables/redirects.js +4 -4
- package/dist/compatibility-tables/schemas/base.js +2 -2
- package/dist/compatibility-tables/schemas/modifier.js +4 -4
- package/dist/compatibility-tables/schemas/platform.js +3 -2
- package/dist/compatibility-tables/schemas/redirect.js +1 -1
- package/dist/compatibility-tables/schemas/resource-type.js +1 -1
- package/dist/compatibility-tables/schemas/scriptlet.js +1 -1
- package/dist/compatibility-tables/scriptlets.js +2 -2
- package/dist/compatibility-tables/utils/platform-helpers.js +6 -4
- package/dist/compatibility-tables/utils/resource-type-helpers.js +1 -1
- package/dist/compatibility-tables/utils/zod-camelcase.js +3 -3
- package/dist/converter/base-interfaces/base-converter.js +22 -16
- package/dist/converter/base-interfaces/conversion-result.js +15 -11
- package/dist/converter/base-interfaces/rule-converter-base.js +19 -13
- package/dist/converter/comment/index.js +11 -9
- package/dist/converter/cosmetic/css.js +12 -10
- package/dist/converter/cosmetic/element-hiding.js +12 -10
- package/dist/converter/cosmetic/header-removal.js +16 -13
- package/dist/converter/cosmetic/html.js +18 -18
- package/dist/converter/cosmetic/index.js +28 -24
- package/dist/converter/cosmetic/rule-modifiers/adg.js +15 -12
- package/dist/converter/cosmetic/rule-modifiers/ubo.js +22 -19
- package/dist/converter/cosmetic/scriptlet.js +26 -22
- package/dist/converter/css/index.js +13 -11
- package/dist/converter/data/css.js +8 -8
- package/dist/converter/filter-list.js +12 -10
- package/dist/converter/index.js +1 -1
- package/dist/converter/misc/network-rule-modifier.js +20 -16
- package/dist/converter/network/index.js +16 -12
- package/dist/converter/raw-filter-list.js +12 -10
- package/dist/converter/raw-rule.js +14 -12
- package/dist/converter/rule.js +17 -13
- package/dist/errors/adblock-syntax-error.js +1 -1
- package/dist/errors/not-implemented-error.js +2 -2
- package/dist/errors/rule-conversion-error.js +2 -2
- package/dist/generator/base-generator.js +1 -1
- package/dist/generator/comment/agent-comment-generator.js +4 -3
- package/dist/generator/comment/agent-generator.js +5 -4
- package/dist/generator/comment/comment-rule-generator.js +6 -5
- package/dist/generator/comment/config-comment-generator.js +5 -4
- package/dist/generator/comment/hint-comment-generator.js +5 -4
- package/dist/generator/comment/hint-generator.js +4 -3
- package/dist/generator/comment/metadata-comment-generator.js +3 -2
- package/dist/generator/comment/pre-processor-comment-generator.js +6 -5
- package/dist/generator/comment/simple-comment-generator.js +3 -2
- package/dist/generator/cosmetic/cosmetic-rule-body-generator.js +13 -11
- package/dist/generator/cosmetic/cosmetic-rule-generator.js +5 -4
- package/dist/generator/cosmetic/cosmetic-rule-pattern-generator.js +7 -5
- package/dist/generator/cosmetic/html-filtering-body/adg-html-filtering-body-generator.js +3 -3
- package/dist/generator/cosmetic/html-filtering-body/html-filtering-body-generator.js +1 -1
- package/dist/generator/cosmetic/html-filtering-body/ubo-html-filtering-body-generator.js +2 -2
- package/dist/generator/cosmetic/scriptlet-body/abp-snippet-injection-body-generator.js +7 -5
- package/dist/generator/cosmetic/scriptlet-body/adg-scriptlet-injection-body-generator.js +7 -5
- package/dist/generator/cosmetic/scriptlet-body/ubo-scriptlet-injection-body-generator.js +8 -6
- package/dist/generator/cosmetic/selector/attribute-selector-generator.js +2 -2
- package/dist/generator/cosmetic/selector/class-selector-generator.js +1 -1
- package/dist/generator/cosmetic/selector/complex-selector-generator.js +4 -4
- package/dist/generator/cosmetic/selector/id-selector-generator.js +1 -1
- package/dist/generator/cosmetic/selector/pseudo-class-selector-generator.js +1 -1
- package/dist/generator/cosmetic/selector/selector-combinator-generator.js +1 -1
- package/dist/generator/cosmetic/selector/selector-list-generator.js +1 -1
- package/dist/generator/cosmetic/selector/type-selector-generator.js +1 -1
- package/dist/generator/css/adg-css-injection-generator.js +5 -1
- package/dist/generator/filterlist-generator.js +5 -4
- package/dist/generator/index.js +1 -1
- package/dist/generator/misc/domain-list-generator.js +1 -1
- package/dist/generator/misc/list-items-generator.js +5 -3
- package/dist/generator/misc/logical-expression-generator.js +5 -4
- package/dist/generator/misc/modifier-generator.js +4 -3
- package/dist/generator/misc/modifier-list-generator.js +5 -4
- package/dist/generator/misc/parameter-list-generator.js +6 -5
- package/dist/generator/misc/value-generator.js +2 -1
- package/dist/generator/network/host-rule-generator.js +2 -1
- package/dist/generator/network/network-rule-generator.js +2 -1
- package/dist/generator/rule-generator.js +6 -4
- package/dist/index.js +1 -2
- package/dist/nodes/index.js +1 -1
- package/dist/package.json.js +2 -2
- package/dist/parser/base-parser.js +1 -1
- package/dist/parser/comment/agent-comment-parser.js +11 -9
- package/dist/parser/comment/agent-parser.js +12 -9
- package/dist/parser/comment/comment-parser.js +8 -7
- package/dist/parser/comment/config-comment-parser.js +9 -6
- package/dist/parser/comment/hint-comment-parser.js +17 -12
- package/dist/parser/comment/hint-parser.js +10 -7
- package/dist/parser/comment/metadata-comment-parser.js +9 -7
- package/dist/parser/comment/preprocessor-parser.js +14 -11
- package/dist/parser/comment/simple-comment-parser.js +5 -2
- package/dist/parser/cosmetic/cosmetic-rule-parser.js +29 -25
- package/dist/parser/cosmetic/html-filtering-body/adg-html-filtering-body-parser.js +3 -3
- package/dist/parser/cosmetic/html-filtering-body/html-filtering-body-parser.js +4 -4
- package/dist/parser/cosmetic/html-filtering-body/ubo-html-filtering-body-parser.js +7 -7
- package/dist/parser/cosmetic/scriptlet-body/abp-snippet-injection-body-parser.js +12 -9
- package/dist/parser/cosmetic/scriptlet-body/adg-scriptlet-injection-body-parser.js +12 -9
- package/dist/parser/cosmetic/scriptlet-body/ubo-scriptlet-injection-body-parser.js +11 -8
- package/dist/parser/cosmetic/selector/handlers/attribute-selector-handler.js +1 -1
- package/dist/parser/cosmetic/selector/handlers/class-selector-handler.js +1 -1
- package/dist/parser/cosmetic/selector/handlers/complex-selector-handler.js +1 -1
- package/dist/parser/cosmetic/selector/handlers/compound-selector-handler.js +2 -2
- package/dist/parser/cosmetic/selector/handlers/id-selector-handler.js +1 -1
- package/dist/parser/cosmetic/selector/handlers/pseudo-class-selector-handler.js +5 -3
- package/dist/parser/cosmetic/selector/handlers/type-selector-handler.js +1 -1
- package/dist/parser/cosmetic/selector/selector-list-parser.js +7 -7
- package/dist/parser/css/adg-css-injection-parser.js +4 -3
- package/dist/parser/css/balancing.js +22 -18
- package/dist/parser/css/constants.js +1 -1
- package/dist/parser/css/css-token-stream.js +15 -4
- package/dist/parser/css/ubo-selector-parser.js +8 -4
- package/dist/parser/filterlist-parser.js +8 -5
- package/dist/parser/index.js +1 -1
- package/dist/parser/misc/app-list-parser.js +4 -3
- package/dist/parser/misc/domain-list-parser.js +8 -6
- package/dist/parser/misc/list-items-parser.js +8 -6
- package/dist/parser/misc/logical-expression-parser.js +25 -18
- package/dist/parser/misc/method-list-parser.js +4 -3
- package/dist/parser/misc/modifier-list.js +3 -3
- package/dist/parser/misc/modifier-parser.js +5 -4
- package/dist/parser/misc/parameter-list-parser.js +6 -5
- package/dist/parser/misc/stealth-option-list-parser.js +4 -3
- package/dist/parser/misc/ubo-parameter-list-parser.js +10 -9
- package/dist/parser/misc/value-parser.js +2 -2
- package/dist/parser/network/host-rule-parser.js +15 -7
- package/dist/parser/network/network-rule-parser.js +11 -9
- package/dist/parser/options.js +1 -1
- package/dist/parser/rule-parser.js +11 -7
- package/dist/types/ast-utils/clone.d.ts +12 -8
- package/dist/types/ast-utils/filter-list.d.ts +5 -4
- package/dist/types/ast-utils/modifiers.d.ts +11 -9
- package/dist/types/ast-utils/network-rules.d.ts +8 -7
- package/dist/types/ast-utils/scriptlets.d.ts +19 -17
- package/dist/types/compatibility-tables/base.d.ts +6 -5
- package/dist/types/compatibility-tables/redirects.d.ts +1 -1
- package/dist/types/compatibility-tables/schemas/platform.d.ts +1 -0
- package/dist/types/compatibility-tables/utils/platform-helpers.d.ts +5 -3
- package/dist/types/compatibility-tables/utils/zod-camelcase.d.ts +3 -3
- package/dist/types/converter/base-interfaces/base-converter.d.ts +21 -15
- package/dist/types/converter/base-interfaces/conversion-result.d.ts +20 -16
- package/dist/types/converter/base-interfaces/rule-converter-base.d.ts +19 -13
- package/dist/types/converter/comment/index.d.ts +9 -7
- package/dist/types/converter/cosmetic/css.d.ts +9 -7
- package/dist/types/converter/cosmetic/element-hiding.d.ts +9 -7
- package/dist/types/converter/cosmetic/header-removal.d.ts +10 -7
- package/dist/types/converter/cosmetic/html.d.ts +9 -9
- package/dist/types/converter/cosmetic/index.d.ts +14 -10
- package/dist/types/converter/cosmetic/rule-modifiers/adg.d.ts +9 -6
- package/dist/types/converter/cosmetic/rule-modifiers/ubo.d.ts +9 -6
- package/dist/types/converter/cosmetic/scriptlet.d.ts +14 -10
- package/dist/types/converter/css/index.d.ts +9 -7
- package/dist/types/converter/data/css.d.ts +1 -1
- package/dist/types/converter/filter-list.d.ts +10 -8
- package/dist/types/converter/index.d.ts +1 -1
- package/dist/types/converter/misc/network-rule-modifier.d.ts +13 -9
- package/dist/types/converter/network/index.d.ts +15 -11
- package/dist/types/converter/raw-filter-list.d.ts +8 -6
- package/dist/types/converter/raw-rule.d.ts +8 -6
- package/dist/types/converter/rule.d.ts +14 -10
- package/dist/types/errors/not-implemented-error.d.ts +1 -1
- package/dist/types/errors/rule-conversion-error.d.ts +1 -1
- package/dist/types/generator/comment/agent-comment-generator.d.ts +3 -2
- package/dist/types/generator/comment/agent-generator.d.ts +4 -3
- package/dist/types/generator/comment/comment-rule-generator.d.ts +3 -2
- package/dist/types/generator/comment/config-comment-generator.d.ts +4 -3
- package/dist/types/generator/comment/hint-comment-generator.d.ts +4 -3
- package/dist/types/generator/comment/hint-generator.d.ts +3 -2
- package/dist/types/generator/comment/metadata-comment-generator.d.ts +1 -0
- package/dist/types/generator/comment/pre-processor-comment-generator.d.ts +3 -2
- package/dist/types/generator/comment/simple-comment-generator.d.ts +2 -1
- package/dist/types/generator/cosmetic/cosmetic-rule-body-generator.d.ts +7 -5
- package/dist/types/generator/cosmetic/cosmetic-rule-generator.d.ts +3 -2
- package/dist/types/generator/cosmetic/cosmetic-rule-pattern-generator.d.ts +4 -2
- package/dist/types/generator/cosmetic/html-filtering-body/adg-html-filtering-body-generator.d.ts +1 -1
- package/dist/types/generator/cosmetic/html-filtering-body/html-filtering-body-generator.d.ts +1 -1
- package/dist/types/generator/cosmetic/html-filtering-body/ubo-html-filtering-body-generator.d.ts +2 -2
- package/dist/types/generator/cosmetic/scriptlet-body/abp-snippet-injection-body-generator.d.ts +5 -3
- package/dist/types/generator/cosmetic/scriptlet-body/adg-scriptlet-injection-body-generator.d.ts +5 -3
- package/dist/types/generator/cosmetic/scriptlet-body/ubo-scriptlet-injection-body-generator.d.ts +7 -5
- package/dist/types/generator/css/adg-css-injection-generator.d.ts +4 -0
- package/dist/types/generator/css/ubo-selector-generator.d.ts +4 -3
- package/dist/types/generator/filterlist-generator.d.ts +3 -2
- package/dist/types/generator/misc/list-items-generator.d.ts +4 -2
- package/dist/types/generator/misc/logical-expression-generator.d.ts +4 -3
- package/dist/types/generator/misc/modifier-generator.d.ts +3 -2
- package/dist/types/generator/misc/modifier-list-generator.d.ts +4 -3
- package/dist/types/generator/misc/parameter-list-generator.d.ts +5 -4
- package/dist/types/generator/misc/value-generator.d.ts +1 -0
- package/dist/types/generator/network/host-rule-generator.d.ts +1 -0
- package/dist/types/generator/network/network-rule-generator.d.ts +1 -0
- package/dist/types/generator/rule-generator.d.ts +5 -3
- package/dist/types/index.d.ts +1 -2
- package/dist/types/nodes/index.d.ts +55 -54
- package/dist/types/parser/comment/agent-comment-parser.d.ts +5 -3
- package/dist/types/parser/comment/agent-parser.d.ts +7 -4
- package/dist/types/parser/comment/comment-parser.d.ts +5 -3
- package/dist/types/parser/comment/config-comment-parser.d.ts +5 -2
- package/dist/types/parser/comment/hint-comment-parser.d.ts +11 -6
- package/dist/types/parser/comment/hint-parser.d.ts +6 -3
- package/dist/types/parser/comment/metadata-comment-parser.d.ts +5 -3
- package/dist/types/parser/comment/preprocessor-parser.d.ts +9 -6
- package/dist/types/parser/comment/simple-comment-parser.d.ts +3 -0
- package/dist/types/parser/cosmetic/cosmetic-rule-parser.d.ts +9 -6
- package/dist/types/parser/cosmetic/html-filtering-body/adg-html-filtering-body-parser.d.ts +3 -3
- package/dist/types/parser/cosmetic/html-filtering-body/html-filtering-body-parser.d.ts +4 -4
- package/dist/types/parser/cosmetic/html-filtering-body/ubo-html-filtering-body-parser.d.ts +4 -4
- package/dist/types/parser/cosmetic/scriptlet-body/abp-snippet-injection-body-parser.d.ts +8 -5
- package/dist/types/parser/cosmetic/scriptlet-body/adg-scriptlet-injection-body-parser.d.ts +9 -6
- package/dist/types/parser/cosmetic/scriptlet-body/ubo-scriptlet-injection-body-parser.d.ts +8 -5
- package/dist/types/parser/cosmetic/selector/context.d.ts +2 -2
- package/dist/types/parser/cosmetic/selector/selector-list-parser.d.ts +2 -2
- package/dist/types/parser/css/adg-css-injection-parser.d.ts +1 -0
- package/dist/types/parser/css/balancing.d.ts +17 -12
- package/dist/types/parser/css/css-token-stream.d.ts +11 -0
- package/dist/types/parser/css/ubo-selector-parser.d.ts +3 -0
- package/dist/types/parser/filterlist-parser.d.ts +5 -2
- package/dist/types/parser/misc/app-list-parser.d.ts +1 -0
- package/dist/types/parser/misc/domain-list-parser.d.ts +5 -3
- package/dist/types/parser/misc/list-items-parser.d.ts +5 -3
- package/dist/types/parser/misc/logical-expression-parser.d.ts +9 -5
- package/dist/types/parser/misc/method-list-parser.d.ts +1 -0
- package/dist/types/parser/misc/modifier-list.d.ts +2 -1
- package/dist/types/parser/misc/modifier-parser.d.ts +2 -1
- package/dist/types/parser/misc/parameter-list-parser.d.ts +3 -2
- package/dist/types/parser/misc/stealth-option-list-parser.d.ts +1 -0
- package/dist/types/parser/misc/ubo-parameter-list-parser.d.ts +2 -1
- package/dist/types/parser/misc/value-parser.d.ts +1 -1
- package/dist/types/parser/network/host-rule-parser.d.ts +10 -2
- package/dist/types/parser/network/network-rule-parser.d.ts +5 -3
- package/dist/types/parser/options.d.ts +1 -1
- package/dist/types/parser/rule-parser.d.ts +6 -2
- package/dist/types/tokenizer/tokenizer.d.ts +2 -2
- package/dist/types/utils/adblockers.d.ts +9 -6
- package/dist/types/utils/clone.d.ts +4 -3
- package/dist/types/utils/constants.d.ts +1 -1
- package/dist/types/utils/cosmetic-rule-separator.d.ts +13 -10
- package/dist/types/utils/deep-freeze.d.ts +4 -4
- package/dist/types/utils/domain.d.ts +3 -2
- package/dist/types/utils/logical-expression.d.ts +9 -5
- package/dist/types/utils/multi-value-map.d.ts +3 -3
- package/dist/types/utils/position-provider.d.ts +3 -2
- package/dist/types/utils/quotes.d.ts +48 -42
- package/dist/types/utils/regexp.d.ts +24 -17
- package/dist/types/utils/string.d.ts +135 -103
- package/dist/types/utils/type-guards.d.ts +1 -0
- package/dist/types/validator/helpers.d.ts +1 -1
- package/dist/types/validator/index.d.ts +3 -3
- package/dist/types/version.d.ts +1 -1
- package/dist/utils/adblockers.js +10 -7
- package/dist/utils/bit-count.js +1 -1
- package/dist/utils/categorizer.js +2 -2
- package/dist/utils/clone.js +5 -4
- package/dist/utils/constants.js +2 -2
- package/dist/utils/cosmetic-rule-separator.js +15 -11
- package/dist/utils/deep-freeze.js +5 -5
- package/dist/utils/domain.js +4 -3
- package/dist/utils/error.js +3 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/logical-expression.js +10 -6
- package/dist/utils/multi-value-map.js +4 -4
- package/dist/utils/noop-modifier.js +1 -1
- package/dist/utils/position-provider.js +2 -1
- package/dist/utils/quotes.js +49 -43
- package/dist/utils/regexp.js +25 -18
- package/dist/utils/string.js +136 -104
- package/dist/utils/type-guards.js +2 -1
- package/dist/validator/constants.js +1 -1
- package/dist/validator/helpers.js +1 -1
- package/dist/validator/index.js +8 -8
- package/dist/validator/value.js +6 -6
- package/dist/version.js +2 -2
- package/package.json +3 -1
- package/dist/errors/binary-schema-mismatch-error.js +0 -37
- package/dist/types/errors/binary-schema-mismatch-error.d.ts +0 -23
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ParameterListParser } from './parameter-list-parser.js';
|
|
2
1
|
import { type ParameterList } from '../../nodes/index.js';
|
|
2
|
+
import { ParameterListParser } from './parameter-list-parser.js';
|
|
3
3
|
/**
|
|
4
4
|
* Parser for uBO-specific parameter lists.
|
|
5
5
|
*/
|
|
@@ -13,6 +13,7 @@ export declare class UboParameterListParser extends ParameterListParser {
|
|
|
13
13
|
* @param separator Separator character (default: comma).
|
|
14
14
|
* @param requireQuotes Whether to require quotes around the parameter values (default: false).
|
|
15
15
|
* @param supportedQuotes Set of accepted quotes (default: {@link QUOTE_SET}).
|
|
16
|
+
*
|
|
16
17
|
* @returns Parameter list node.
|
|
17
18
|
*
|
|
18
19
|
* @note Based on {@link https://github.com/gorhill/uBlock/blob/f9ab4b75041815e6e5690d80851189ae3dc660d0/src/js/static-filtering-parser.js#L607-L699} to provide consistency.
|
|
@@ -6,20 +6,27 @@ import { BaseParser } from '../base-parser.js';
|
|
|
6
6
|
* HostRule is a structure for simple host-level rules (i.e. /etc/hosts syntax).
|
|
7
7
|
* It also supports "just domain" syntax. In this case, the IP will be set to 0.0.0.0.
|
|
8
8
|
*
|
|
9
|
-
* Rules syntax looks like this
|
|
9
|
+
* Rules syntax looks like this:.
|
|
10
10
|
* ```text
|
|
11
11
|
* IP_address canonical_hostname [aliases...]
|
|
12
12
|
* ```
|
|
13
13
|
*
|
|
14
|
+
* @see {@link http://man7.org/linux/man-pages/man5/hosts.5.html}
|
|
15
|
+
*
|
|
14
16
|
* @example
|
|
15
17
|
* `192.168.1.13 bar.mydomain.org bar` -- ipv4
|
|
16
18
|
* `ff02::1 ip6-allnodes` -- ipv6
|
|
17
19
|
* `::1 localhost ip6-localhost ip6-loopback` -- ipv6 aliases
|
|
18
20
|
* `example.org` -- "just domain" syntax
|
|
19
|
-
* @see {@link http://man7.org/linux/man-pages/man5/hosts.5.html}
|
|
20
21
|
*/
|
|
21
22
|
export declare class HostRuleParser extends BaseParser {
|
|
23
|
+
/**
|
|
24
|
+
* Default IP address for host rules without explicit IP.
|
|
25
|
+
*/
|
|
22
26
|
static readonly NULL_IP = "0.0.0.0";
|
|
27
|
+
/**
|
|
28
|
+
* Comment marker character.
|
|
29
|
+
*/
|
|
23
30
|
static readonly COMMENT_MARKER = "#";
|
|
24
31
|
/**
|
|
25
32
|
* Parses an etc/hosts-like rule.
|
|
@@ -27,6 +34,7 @@ export declare class HostRuleParser extends BaseParser {
|
|
|
27
34
|
* @param raw Raw input to parse.
|
|
28
35
|
* @param options Global parser options.
|
|
29
36
|
* @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
|
|
37
|
+
*
|
|
30
38
|
* @returns Host rule node.
|
|
31
39
|
*
|
|
32
40
|
* @throws If the input contains invalid data.
|
|
@@ -16,7 +16,8 @@ export declare class NetworkRuleParser extends BaseParser {
|
|
|
16
16
|
* @param raw Raw input to parse.
|
|
17
17
|
* @param options Global parser options.
|
|
18
18
|
* @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
|
|
19
|
-
*
|
|
19
|
+
*
|
|
20
|
+
* @returns Network rule AST.
|
|
20
21
|
*
|
|
21
22
|
* @throws If the rule is syntactically incorrect.
|
|
22
23
|
*/
|
|
@@ -24,8 +25,9 @@ export declare class NetworkRuleParser extends BaseParser {
|
|
|
24
25
|
/**
|
|
25
26
|
* Finds the index of the separator character in a network rule.
|
|
26
27
|
*
|
|
27
|
-
* @param rule Network rule to check
|
|
28
|
-
*
|
|
28
|
+
* @param rule Network rule to check.
|
|
29
|
+
*
|
|
30
|
+
* @returns The index of the separator character, or -1 if there is no separator.
|
|
29
31
|
*/
|
|
30
32
|
static findNetworkRuleSeparatorIndex(rule: string): number;
|
|
31
33
|
}
|
|
@@ -13,6 +13,7 @@ export declare class RuleParser extends BaseParser {
|
|
|
13
13
|
* @param raw Raw input to parse.
|
|
14
14
|
* @param options Global parser options.
|
|
15
15
|
* @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
|
|
16
|
+
*
|
|
16
17
|
* @returns Host rule or network rule node.
|
|
17
18
|
*/
|
|
18
19
|
private static parseHostOrNetworkRule;
|
|
@@ -44,8 +45,11 @@ export declare class RuleParser extends BaseParser {
|
|
|
44
45
|
* @param raw Raw input to parse.
|
|
45
46
|
* @param options Global parser options.
|
|
46
47
|
* @param baseOffset Starting offset of the input. Node locations are calculated relative to this offset.
|
|
47
|
-
*
|
|
48
|
-
* @
|
|
48
|
+
*
|
|
49
|
+
* @returns Adblock rule node.
|
|
50
|
+
*
|
|
51
|
+
* @throws If the input matches a pattern but syntactically invalid.
|
|
52
|
+
*
|
|
49
53
|
* @example
|
|
50
54
|
* Take a look at the following example:
|
|
51
55
|
* ```js
|
|
@@ -11,7 +11,7 @@ export declare const enum TokenType {
|
|
|
11
11
|
*/
|
|
12
12
|
Whitespace = 1,
|
|
13
13
|
/**
|
|
14
|
-
* Line break (`\r\n` or just `\n`)
|
|
14
|
+
* Line break (`\r\n` or just `\n`).
|
|
15
15
|
*/
|
|
16
16
|
LineBreak = 2,
|
|
17
17
|
/**
|
|
@@ -33,7 +33,7 @@ export declare const enum TokenType {
|
|
|
33
33
|
AllowlistCosmeticSeparator = 6,
|
|
34
34
|
/**
|
|
35
35
|
* Raw content after cosmetic rule separator.
|
|
36
|
-
* For example, no need to tokenize CSS with this tokenizer after the `##`, `#?#`, etc.
|
|
36
|
+
* For example, no need to tokenize CSS with this tokenizer after the `##`, `#?#`, etc. Separators,
|
|
37
37
|
* so we use this token type as an optimization strategy.
|
|
38
38
|
*/
|
|
39
39
|
RawContent = 7,
|
|
@@ -12,7 +12,7 @@ export declare const AdblockProduct: {
|
|
|
12
12
|
*/
|
|
13
13
|
readonly Abp: "AdblockPlus";
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* UBlock Origin..
|
|
16
16
|
*
|
|
17
17
|
* @see {@link https://github.com/gorhill/uBlock}
|
|
18
18
|
*/
|
|
@@ -26,7 +26,7 @@ export declare const AdblockProduct: {
|
|
|
26
26
|
};
|
|
27
27
|
export type AdblockProduct = typeof AdblockProduct[keyof typeof AdblockProduct];
|
|
28
28
|
/**
|
|
29
|
-
* Possible adblock syntaxes (supported by this library)
|
|
29
|
+
* Possible adblock syntaxes (supported by this library).
|
|
30
30
|
*/
|
|
31
31
|
export declare const AdblockSyntax: {
|
|
32
32
|
/**
|
|
@@ -44,29 +44,32 @@ export declare const AdblockSyntax: {
|
|
|
44
44
|
/**
|
|
45
45
|
* Adblock Plus syntax.
|
|
46
46
|
*
|
|
47
|
+
* @see {@link https://adblockplus.org/}
|
|
48
|
+
*
|
|
47
49
|
* @example
|
|
48
50
|
* - `example.org#$#abort-on-property-read alert` is an Adblock Plus syntax, since it is not used by any other
|
|
49
51
|
* adblockers directly (probably supported by some on-the-fly conversion, but this is not the native syntax).
|
|
50
|
-
* @see {@link https://adblockplus.org/}
|
|
51
52
|
*/
|
|
52
53
|
readonly Abp: "AdblockPlus";
|
|
53
54
|
/**
|
|
54
|
-
*
|
|
55
|
+
* UBlock Origin syntax..
|
|
56
|
+
*
|
|
57
|
+
* @see {@link https://github.com/gorhill/uBlock}
|
|
55
58
|
*
|
|
56
59
|
* @example
|
|
57
60
|
* - `example.com##+js(set, atob, noopFunc)` is an uBlock Origin syntax, since it is not used by any other
|
|
58
61
|
* adblockers directly (probably supported by some on-the-fly conversion, but this is not the native syntax).
|
|
59
|
-
* @see {@link https://github.com/gorhill/uBlock}
|
|
60
62
|
*/
|
|
61
63
|
readonly Ubo: "UblockOrigin";
|
|
62
64
|
/**
|
|
63
65
|
* AdGuard syntax.
|
|
64
66
|
*
|
|
67
|
+
* @see {@link https://adguard.com/}
|
|
68
|
+
*
|
|
65
69
|
* @example
|
|
66
70
|
* - `example.org#%#//scriptlet("abort-on-property-read", "alert")` is an AdGuard syntax, since it is not used
|
|
67
71
|
* by any other adblockers directly (probably supported by some on-the-fly conversion, but this is not the native
|
|
68
72
|
* syntax).
|
|
69
|
-
* @see {@link https://adguard.com/}
|
|
70
73
|
*/
|
|
71
74
|
readonly Adg: "AdGuard";
|
|
72
75
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @file Clone related utilities
|
|
2
|
+
* @file Clone related utilities.
|
|
3
3
|
*
|
|
4
4
|
* We should keep clone related functions in this file. Thus, we just provide
|
|
5
5
|
* a simple interface for cloning values, we use it across the AGTree project,
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
* Clones an input value to avoid side effects. Use it only in justified cases,
|
|
10
10
|
* because it can impact performance negatively.
|
|
11
11
|
*
|
|
12
|
-
* @param value Value to clone
|
|
13
|
-
*
|
|
12
|
+
* @param value Value to clone.
|
|
13
|
+
*
|
|
14
|
+
* @returns Cloned value.
|
|
14
15
|
*/
|
|
15
16
|
export declare function clone<T>(value: T): T;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @file Cosmetic rule separator finder and categorizer
|
|
2
|
+
* @file Cosmetic rule separator finder and categorizer.
|
|
3
3
|
*/
|
|
4
4
|
import { CosmeticRuleSeparator } from '../nodes/index.js';
|
|
5
5
|
export interface CosmeticRuleSeparatorFinderResult {
|
|
6
6
|
/**
|
|
7
|
-
* Separator type
|
|
7
|
+
* Separator type.
|
|
8
8
|
*/
|
|
9
9
|
separator: CosmeticRuleSeparator;
|
|
10
10
|
/**
|
|
11
|
-
* Separator start position
|
|
11
|
+
* Separator start position.
|
|
12
12
|
*/
|
|
13
13
|
start: number;
|
|
14
14
|
/**
|
|
15
|
-
* Separator end position
|
|
15
|
+
* Separator end position.
|
|
16
16
|
*/
|
|
17
17
|
end: number;
|
|
18
18
|
}
|
|
@@ -23,23 +23,26 @@ export declare class CosmeticRuleSeparatorUtils {
|
|
|
23
23
|
/**
|
|
24
24
|
* Checks whether the specified separator is an exception.
|
|
25
25
|
*
|
|
26
|
-
* @param separator Separator to check
|
|
27
|
-
*
|
|
26
|
+
* @param separator Separator to check.
|
|
27
|
+
*
|
|
28
|
+
* @returns `true` if the separator is an exception, `false` otherwise.
|
|
28
29
|
*/
|
|
29
30
|
static isException(separator: CosmeticRuleSeparator): boolean;
|
|
30
31
|
/**
|
|
31
32
|
* Checks whether the specified separator is marks an Extended CSS cosmetic rule.
|
|
32
33
|
*
|
|
33
|
-
* @param separator Separator to check
|
|
34
|
-
*
|
|
34
|
+
* @param separator Separator to check.
|
|
35
|
+
*
|
|
36
|
+
* @returns `true` if the separator is marks an Extended CSS cosmetic rule, `false` otherwise.
|
|
35
37
|
*/
|
|
36
38
|
static isExtendedCssMarker(separator: CosmeticRuleSeparator): boolean;
|
|
37
39
|
/**
|
|
38
40
|
* Looks for the cosmetic rule separator in the rule. This is a simplified version that
|
|
39
41
|
* masks the recursive function.
|
|
40
42
|
*
|
|
41
|
-
* @param rule Raw rule
|
|
42
|
-
*
|
|
43
|
+
* @param rule Raw rule.
|
|
44
|
+
*
|
|
45
|
+
* @returns Separator result or null if no separator was found.
|
|
43
46
|
*/
|
|
44
47
|
static find(rule: string): CosmeticRuleSeparatorFinderResult | null;
|
|
45
48
|
}
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
* Simple deep freeze implementation.
|
|
3
3
|
* It freezes the object and all its properties recursively.
|
|
4
4
|
*
|
|
5
|
-
* @param object Object to freeze.
|
|
6
|
-
*
|
|
7
|
-
* @returns Frozen object.
|
|
8
|
-
*
|
|
9
5
|
* @template T Type of the object to freeze.
|
|
10
6
|
*
|
|
11
7
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze#deep_freezing}
|
|
8
|
+
*
|
|
9
|
+
* @param object Object to freeze.
|
|
10
|
+
*
|
|
11
|
+
* @returns Frozen object.
|
|
12
12
|
*/
|
|
13
13
|
export declare const deepFreeze: <T extends object>(object: T) => Readonly<T>;
|
|
@@ -22,8 +22,9 @@ export declare class DomainUtils {
|
|
|
22
22
|
/**
|
|
23
23
|
* Check if the input is a valid domain or hostname.
|
|
24
24
|
*
|
|
25
|
-
* @param domain Domain to check
|
|
26
|
-
*
|
|
25
|
+
* @param domain Domain to check.
|
|
26
|
+
*
|
|
27
|
+
* @returns `true` if the domain is valid, `false` otherwise.
|
|
27
28
|
*/
|
|
28
29
|
static isValidDomainOrHostname(domain: string): boolean;
|
|
29
30
|
}
|
|
@@ -15,8 +15,10 @@ export declare class LogicalExpressionUtils {
|
|
|
15
15
|
/**
|
|
16
16
|
* Get all variables in the expression.
|
|
17
17
|
*
|
|
18
|
-
* @param node Logical expression node
|
|
19
|
-
*
|
|
18
|
+
* @param node Logical expression node.
|
|
19
|
+
*
|
|
20
|
+
* @returns List of variables in the expression (nodes).
|
|
21
|
+
*
|
|
20
22
|
* @example
|
|
21
23
|
* If the expression is `a && b || c`, the returned list will be
|
|
22
24
|
* nodes for `a`, `b`, and `c`.
|
|
@@ -26,9 +28,11 @@ export declare class LogicalExpressionUtils {
|
|
|
26
28
|
* Evaluate the parsed logical expression. You'll need to provide a
|
|
27
29
|
* variable table.
|
|
28
30
|
*
|
|
29
|
-
* @param node Logical expression node
|
|
30
|
-
* @param table Variable table (key: variable name, value: boolean)
|
|
31
|
-
*
|
|
31
|
+
* @param node Logical expression node.
|
|
32
|
+
* @param table Variable table (key: variable name, value: boolean).
|
|
33
|
+
*
|
|
34
|
+
* @returns Evaluation result.
|
|
35
|
+
*
|
|
32
36
|
* @example
|
|
33
37
|
* If the expression is `a && b`, and the variable table is
|
|
34
38
|
* `{ a: true, b: false }`, the result will be `false`.
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
* A very simple map extension that allows to store multiple values for the same key
|
|
3
3
|
* by storing them in an array.
|
|
4
4
|
*
|
|
5
|
-
* @todo Add more methods if needed
|
|
5
|
+
* @todo Add more methods if needed.
|
|
6
6
|
*/
|
|
7
7
|
export declare class MultiValueMap<K, V> extends Map<K, V[]> {
|
|
8
8
|
/**
|
|
9
9
|
* Adds a value to the map. If the key already exists, the value will be appended to the existing array,
|
|
10
10
|
* otherwise a new array will be created for the key.
|
|
11
11
|
*
|
|
12
|
-
* @param key Key to add
|
|
13
|
-
* @param values Value(s) to add
|
|
12
|
+
* @param key Key to add.
|
|
13
|
+
* @param values Value(s) to add.
|
|
14
14
|
*/
|
|
15
15
|
add(key: K, ...values: V[]): void;
|
|
16
16
|
}
|
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export interface Position {
|
|
8
8
|
/**
|
|
9
|
-
* 1-based line number
|
|
9
|
+
* 1-based line number.
|
|
10
10
|
*/
|
|
11
11
|
line: number;
|
|
12
12
|
/**
|
|
13
|
-
* 1-based column number
|
|
13
|
+
* 1-based column number.
|
|
14
14
|
*/
|
|
15
15
|
column: number;
|
|
16
16
|
}
|
|
@@ -40,6 +40,7 @@ export declare class PositionProvider {
|
|
|
40
40
|
* Converts a character offset to a line and column position.
|
|
41
41
|
*
|
|
42
42
|
* @param offset The zero-based character offset in the source code.
|
|
43
|
+
*
|
|
43
44
|
* @returns A Position object containing the 1-based line and column number, or null if the offset is out of range.
|
|
44
45
|
*/
|
|
45
46
|
convertOffsetToPosition(offset: number): Position | null;
|
|
@@ -1,80 +1,86 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @file Utility functions for working with quotes
|
|
2
|
+
* @file Utility functions for working with quotes.
|
|
3
3
|
*/
|
|
4
4
|
/**
|
|
5
|
-
* Set of all possible quote characters supported by the library
|
|
5
|
+
* Set of all possible quote characters supported by the library.
|
|
6
6
|
*/
|
|
7
7
|
export declare const QUOTE_SET: Set<string>;
|
|
8
8
|
/**
|
|
9
|
-
* Possible quote types for scriptlet parameters
|
|
9
|
+
* Possible quote types for scriptlet parameters.
|
|
10
10
|
*/
|
|
11
11
|
export declare const QuoteType: {
|
|
12
12
|
/**
|
|
13
|
-
* No quotes at all
|
|
13
|
+
* No quotes at all.
|
|
14
14
|
*/
|
|
15
15
|
readonly None: "none";
|
|
16
16
|
/**
|
|
17
|
-
* Single quotes (`'`)
|
|
17
|
+
* Single quotes (`'`).
|
|
18
18
|
*/
|
|
19
19
|
readonly Single: "single";
|
|
20
20
|
/**
|
|
21
|
-
* Double quotes (`"`)
|
|
21
|
+
* Double quotes (`"`).
|
|
22
22
|
*/
|
|
23
23
|
readonly Double: "double";
|
|
24
24
|
/**
|
|
25
|
-
* Backtick quotes (`` ` ``)
|
|
25
|
+
* Backtick quotes (`` ` ``).
|
|
26
26
|
*/
|
|
27
27
|
readonly Backtick: "backtick";
|
|
28
28
|
};
|
|
29
29
|
export type QuoteType = typeof QuoteType[keyof typeof QuoteType];
|
|
30
30
|
/**
|
|
31
|
-
* Utility functions for working with quotes
|
|
31
|
+
* Utility functions for working with quotes.
|
|
32
32
|
*/
|
|
33
33
|
export declare class QuoteUtils {
|
|
34
34
|
/**
|
|
35
|
-
* Escape all unescaped occurrences of the character
|
|
35
|
+
* Escape all unescaped occurrences of the character.
|
|
36
36
|
*
|
|
37
|
-
* @param string String to escape
|
|
38
|
-
* @param char Character to escape
|
|
39
|
-
*
|
|
37
|
+
* @param string String to escape.
|
|
38
|
+
* @param char Character to escape.
|
|
39
|
+
*
|
|
40
|
+
* @returns Escaped string.
|
|
40
41
|
*/
|
|
41
42
|
static escapeUnescapedOccurrences(string: string, char: string): string;
|
|
42
43
|
/**
|
|
43
|
-
* Unescape all single escaped occurrences of the character
|
|
44
|
+
* Unescape all single escaped occurrences of the character.
|
|
45
|
+
*
|
|
46
|
+
* @param string String to unescape.
|
|
47
|
+
* @param char Character to unescape.
|
|
44
48
|
*
|
|
45
|
-
* @
|
|
46
|
-
* @param char Character to unescape
|
|
47
|
-
* @returns Unescaped string
|
|
49
|
+
* @returns Unescaped string.
|
|
48
50
|
*/
|
|
49
51
|
static unescapeSingleEscapedOccurrences(string: string, char: string): string;
|
|
50
52
|
/**
|
|
51
|
-
* Get quote type of the string
|
|
53
|
+
* Get quote type of the string.
|
|
54
|
+
*
|
|
55
|
+
* @param string String to check.
|
|
52
56
|
*
|
|
53
|
-
* @
|
|
54
|
-
* @returns Quote type of the string
|
|
57
|
+
* @returns Quote type of the string.
|
|
55
58
|
*/
|
|
56
59
|
static getStringQuoteType(string: string): QuoteType;
|
|
57
60
|
/**
|
|
58
|
-
* Set quote type of the string
|
|
61
|
+
* Set quote type of the string.
|
|
59
62
|
*
|
|
60
|
-
* @param string String to set quote type of
|
|
61
|
-
* @param quoteType Quote type to set
|
|
62
|
-
*
|
|
63
|
+
* @param string String to set quote type of.
|
|
64
|
+
* @param quoteType Quote type to set.
|
|
65
|
+
*
|
|
66
|
+
* @returns String with the specified quote type.
|
|
63
67
|
*/
|
|
64
68
|
static setStringQuoteType(string: string, quoteType: QuoteType): string;
|
|
65
69
|
/**
|
|
66
|
-
* Removes bounding quotes from a string, if any
|
|
70
|
+
* Removes bounding quotes from a string, if any.
|
|
71
|
+
*
|
|
72
|
+
* @param string Input string.
|
|
67
73
|
*
|
|
68
|
-
* @
|
|
69
|
-
* @returns String without quotes
|
|
74
|
+
* @returns String without quotes.
|
|
70
75
|
*/
|
|
71
76
|
static removeQuotes(string: string): string;
|
|
72
77
|
/**
|
|
73
78
|
* Removes bounding quotes from a string, if any, and unescapes the escaped quotes,
|
|
74
79
|
* like transforming `'abc\'def'` to `abc'def`.
|
|
75
80
|
*
|
|
76
|
-
* @param string Input string
|
|
77
|
-
*
|
|
81
|
+
* @param string Input string.
|
|
82
|
+
*
|
|
83
|
+
* @returns String without quotes.
|
|
78
84
|
*/
|
|
79
85
|
static removeQuotesAndUnescape(string: string): string;
|
|
80
86
|
/**
|
|
@@ -95,44 +101,44 @@ export declare class QuoteUtils {
|
|
|
95
101
|
* Convert `""` to `\"` within strings inside of attribute selectors,
|
|
96
102
|
* because it is not compatible with the standard CSS syntax.
|
|
97
103
|
*
|
|
104
|
+
* @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#tag-content}
|
|
105
|
+
* @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#wildcard}
|
|
106
|
+
*
|
|
98
107
|
* @param selector CSS selector string.
|
|
99
108
|
*
|
|
100
109
|
* @returns Escaped CSS selector.
|
|
101
110
|
*
|
|
102
|
-
* @note In the legacy syntax, `""` is used to escape double quotes, but it cannot be used
|
|
103
|
-
* in the standard CSS syntax, so we use conversion functions to handle this.
|
|
104
|
-
* @note This function is intended to be used on whole attribute selector or whole selector strings.
|
|
105
|
-
*
|
|
106
|
-
* @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#tag-content}
|
|
107
|
-
* @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#wildcard}
|
|
108
|
-
*
|
|
109
111
|
* @example
|
|
110
112
|
* ```ts
|
|
111
113
|
* QuoteUtils.escapeAttributeDoubleQuotes('[attr="value with "" quotes"]');
|
|
112
114
|
* QuoteUtils.escapeAttributeDoubleQuotes('div[attr="value with "" quotes"] > span');
|
|
113
115
|
* ```
|
|
116
|
+
*
|
|
117
|
+
* @note In the legacy syntax, `""` is used to escape double quotes, but it cannot be used
|
|
118
|
+
* in the standard CSS syntax, so we use conversion functions to handle this.
|
|
119
|
+
* @note This function is intended to be used on whole attribute selector or whole selector strings.
|
|
114
120
|
*/
|
|
115
121
|
static escapeAttributeDoubleQuotes(selector: string): string;
|
|
116
122
|
/**
|
|
117
123
|
* Convert escaped double quotes `\"` to `""` within strings inside of attribute selectors,
|
|
118
124
|
* because it is not compatible with the standard CSS syntax.
|
|
119
125
|
*
|
|
126
|
+
* @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#tag-content}
|
|
127
|
+
* @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#wildcard}
|
|
128
|
+
*
|
|
120
129
|
* @param selector CSS selector string.
|
|
121
130
|
*
|
|
122
131
|
* @returns Unescaped CSS selector.
|
|
123
132
|
*
|
|
124
|
-
* @note In the legacy syntax, `""` is used to escape double quotes, but it cannot be used
|
|
125
|
-
* in the standard CSS syntax, so we use conversion functions to handle this.
|
|
126
|
-
* @note This function is intended to be used on whole attribute selector or whole selector strings.
|
|
127
|
-
*
|
|
128
|
-
* @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#tag-content}
|
|
129
|
-
* @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#wildcard}
|
|
130
|
-
*
|
|
131
133
|
* @example
|
|
132
134
|
* ```ts
|
|
133
135
|
* QuoteUtils.unescapeAttributeDoubleQuotes('[attr="value with \\" quotes"]');
|
|
134
136
|
* QuoteUtils.unescapeAttributeDoubleQuotes('div[attr="value with \\" quotes"] > span');
|
|
135
137
|
* ```
|
|
138
|
+
*
|
|
139
|
+
* @note In the legacy syntax, `""` is used to escape double quotes, but it cannot be used
|
|
140
|
+
* in the standard CSS syntax, so we use conversion functions to handle this.
|
|
141
|
+
* @note This function is intended to be used on whole attribute selector or whole selector strings.
|
|
136
142
|
*/
|
|
137
143
|
static unescapeAttributeDoubleQuotes(selector: string): string;
|
|
138
144
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @file Regular expression utilities
|
|
2
|
+
* @file Regular expression utilities.
|
|
3
3
|
*/
|
|
4
4
|
export declare const REGEX_START = "^";
|
|
5
5
|
export declare const REGEX_END = "$";
|
|
@@ -13,13 +13,13 @@ export declare const ADBLOCK_WILDCARD_REGEX: string;
|
|
|
13
13
|
export declare const REGEX_NEGATION_PREFIX = "^((?!";
|
|
14
14
|
export declare const REGEX_NEGATION_SUFFIX = ").)*$";
|
|
15
15
|
/**
|
|
16
|
-
* Special RegExp symbols
|
|
16
|
+
* Special RegExp symbols.
|
|
17
17
|
*
|
|
18
18
|
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#special-escape
|
|
19
19
|
*/
|
|
20
20
|
export declare const SPECIAL_REGEX_SYMBOLS: Set<string>;
|
|
21
21
|
/**
|
|
22
|
-
* Utility functions for working with RegExp patterns
|
|
22
|
+
* Utility functions for working with RegExp patterns.
|
|
23
23
|
*/
|
|
24
24
|
export declare class RegExpUtils {
|
|
25
25
|
/**
|
|
@@ -29,22 +29,25 @@ export declare class RegExpUtils {
|
|
|
29
29
|
* Note: it does not perform a full validation of the pattern,
|
|
30
30
|
* it just checks if the string starts and ends with a slash.
|
|
31
31
|
*
|
|
32
|
-
* @param pattern
|
|
33
|
-
*
|
|
32
|
+
* @param pattern Pattern to check.
|
|
33
|
+
*
|
|
34
|
+
* @returns `true` if the string is a RegExp pattern, `false` otherwise.
|
|
34
35
|
*/
|
|
35
36
|
static isRegexPattern(pattern: string): boolean;
|
|
36
37
|
/**
|
|
37
38
|
* Checks whether a string is a negated RegExp pattern.
|
|
38
39
|
*
|
|
39
|
-
* @param pattern
|
|
40
|
-
*
|
|
40
|
+
* @param pattern Pattern to check.
|
|
41
|
+
*
|
|
42
|
+
* @returns `true` if the string is a negated RegExp pattern, `false` otherwise.
|
|
41
43
|
*/
|
|
42
44
|
static isNegatedRegexPattern(pattern: string): boolean;
|
|
43
45
|
/**
|
|
44
46
|
* Removes negation from a RegExp pattern.
|
|
45
47
|
*
|
|
46
|
-
* @param pattern
|
|
47
|
-
*
|
|
48
|
+
* @param pattern RegExp pattern to remove negation from.
|
|
49
|
+
*
|
|
50
|
+
* @returns RegExp pattern without negation.
|
|
48
51
|
*/
|
|
49
52
|
static removeNegationFromRegexPattern(pattern: string): string;
|
|
50
53
|
/**
|
|
@@ -52,31 +55,35 @@ export declare class RegExpUtils {
|
|
|
52
55
|
*
|
|
53
56
|
* RegExp modifiers are not supported.
|
|
54
57
|
*
|
|
55
|
-
* @param pattern Pattern to negate (can be wrapped in slashes or not)
|
|
56
|
-
*
|
|
58
|
+
* @param pattern Pattern to negate (can be wrapped in slashes or not).
|
|
59
|
+
*
|
|
60
|
+
* @returns Negated RegExp pattern.
|
|
57
61
|
*/
|
|
58
62
|
static negateRegexPattern(pattern: string): string;
|
|
59
63
|
/**
|
|
60
64
|
* Ensures that a pattern is wrapped in slashes.
|
|
61
65
|
*
|
|
62
|
-
* @param pattern Pattern to ensure slashes for
|
|
63
|
-
*
|
|
66
|
+
* @param pattern Pattern to ensure slashes for.
|
|
67
|
+
*
|
|
68
|
+
* @returns Pattern with slashes.
|
|
64
69
|
*/
|
|
65
70
|
static ensureSlashes(pattern: string): string;
|
|
66
71
|
/**
|
|
67
72
|
* Converts a basic adblock rule pattern to a RegExp pattern. Based on
|
|
68
|
-
* https://github.com/AdguardTeam/tsurlfilter/blob/9b26e0b4a0e30b87690bc60f7cf377d112c3085c/packages/tsurlfilter/src/rules/simple-regex.ts#L219
|
|
73
|
+
* https://github.com/AdguardTeam/tsurlfilter/blob/9b26e0b4a0e30b87690bc60f7cf377d112c3085c/packages/tsurlfilter/src/rules/simple-regex.ts#L219.
|
|
69
74
|
*
|
|
70
|
-
* @param pattern Pattern to convert
|
|
71
|
-
* @returns RegExp equivalent of the pattern
|
|
72
75
|
* @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#basic-rules}
|
|
76
|
+
*
|
|
77
|
+
* @param pattern Pattern to convert.
|
|
78
|
+
*
|
|
79
|
+
* @returns RegExp equivalent of the pattern.
|
|
73
80
|
*/
|
|
74
81
|
static patternToRegexp(pattern: string): string;
|
|
75
82
|
/**
|
|
76
83
|
* Creates a length-matching regular expression string: /^(?=.{min,max}$).*\/s
|
|
77
84
|
* Where:
|
|
78
85
|
* - (?=.{min,max}$) is a lookahead that ensures the string length is between min and max
|
|
79
|
-
* - .* matches any character (including newlines, due to the 's' flag)
|
|
86
|
+
* - .* matches any character (including newlines, due to the 's' flag).
|
|
80
87
|
*
|
|
81
88
|
* @param min Minimum length or `null` for no minimum (default to `0`).
|
|
82
89
|
* @param max Maximum length or `null` for no maximum (default to no maximum).
|