@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.
Files changed (495) hide show
  1. package/README.md +1 -1
  2. package/dist/ast-utils/clone.js +61 -0
  3. package/dist/ast-utils/modifiers.js +53 -0
  4. package/dist/ast-utils/network-rules.js +41 -0
  5. package/dist/ast-utils/scriptlets.js +87 -0
  6. package/dist/common/abp-snippet-injection-body-common.js +23 -0
  7. package/dist/common/agent-common.js +56 -0
  8. package/dist/common/ubo-selector-common.js +17 -0
  9. package/dist/compatibility-tables/base.js +262 -0
  10. package/dist/compatibility-tables/compatibility-table-data.js +11 -0
  11. package/dist/compatibility-tables/modifiers.js +55 -0
  12. package/dist/compatibility-tables/platforms.js +76 -0
  13. package/dist/compatibility-tables/redirects.js +100 -0
  14. package/dist/compatibility-tables/schemas/base.js +111 -0
  15. package/dist/compatibility-tables/schemas/modifier.js +129 -0
  16. package/dist/compatibility-tables/schemas/platform.js +69 -0
  17. package/dist/compatibility-tables/schemas/redirect.js +29 -0
  18. package/dist/compatibility-tables/schemas/resource-type.js +36 -0
  19. package/dist/compatibility-tables/schemas/scriptlet.js +79 -0
  20. package/dist/compatibility-tables/scriptlets.js +28 -0
  21. package/dist/compatibility-tables/utils/platform-helpers.js +105 -0
  22. package/dist/compatibility-tables/utils/resource-type-helpers.js +61 -0
  23. package/dist/compatibility-tables/utils/zod-camelcase.js +25 -0
  24. package/dist/converter/base-interfaces/base-converter.js +59 -0
  25. package/dist/converter/base-interfaces/conversion-result.js +38 -0
  26. package/dist/converter/base-interfaces/rule-converter-base.js +60 -0
  27. package/dist/converter/comment/index.js +54 -0
  28. package/dist/converter/cosmetic/css.js +69 -0
  29. package/dist/converter/cosmetic/element-hiding.js +62 -0
  30. package/dist/converter/cosmetic/header-removal.js +123 -0
  31. package/dist/converter/cosmetic/html.js +379 -0
  32. package/dist/converter/cosmetic/index.js +118 -0
  33. package/dist/converter/cosmetic/rule-modifiers/adg.js +79 -0
  34. package/dist/converter/cosmetic/scriptlet.js +354 -0
  35. package/dist/converter/css/index.js +188 -0
  36. package/dist/converter/data/css.js +126 -0
  37. package/dist/converter/filter-list.js +88 -0
  38. package/dist/converter/index.js +8 -0
  39. package/dist/converter/misc/network-rule-modifier.js +311 -0
  40. package/dist/converter/network/index.js +99 -0
  41. package/dist/converter/raw-filter-list.js +56 -0
  42. package/dist/converter/rule.js +81 -0
  43. package/dist/deserializer/base-deserializer.js +29 -0
  44. package/dist/deserializer/comment/agent-comment-deserializer.js +79 -0
  45. package/dist/deserializer/comment/agent-deserializer.js +65 -0
  46. package/dist/deserializer/comment/comment-rule-deserializer.js +54 -0
  47. package/dist/deserializer/comment/config-comment-deserializer.js +111 -0
  48. package/dist/deserializer/comment/hint-comment-deserializer.js +72 -0
  49. package/dist/deserializer/comment/hint-deserializer.js +85 -0
  50. package/dist/deserializer/comment/metadata-comment-deserializer.js +69 -0
  51. package/dist/deserializer/comment/pre-processor-comment-deserializer.js +112 -0
  52. package/dist/deserializer/comment/simple-comment-deserializer.js +65 -0
  53. package/dist/deserializer/cosmetic/cosmetic-rule-deserializer.js +131 -0
  54. package/dist/deserializer/cosmetic/css-injection-body-deserializer.js +56 -0
  55. package/dist/deserializer/cosmetic/element-hiding-body-deserializer.js +48 -0
  56. package/dist/deserializer/cosmetic/scriptlet-body/abp-snippet-injection-body-deserializer.js +39 -0
  57. package/dist/deserializer/cosmetic/scriptlet-body/adg-scriptlet-injection-body-deserializer.js +40 -0
  58. package/dist/deserializer/cosmetic/scriptlet-body/scriptlet-body-deserializer.js +54 -0
  59. package/dist/deserializer/cosmetic/scriptlet-body/ubo-scriptlet-injection-body-deserializer.js +38 -0
  60. package/dist/deserializer/empty-rule-deserializer.js +48 -0
  61. package/dist/deserializer/filterlist-deserializer.js +85 -0
  62. package/dist/deserializer/index.js +8 -0
  63. package/dist/deserializer/invalid-rule-deserializer.js +50 -0
  64. package/dist/deserializer/invalid-rule-error-node-deserializer.js +50 -0
  65. package/dist/deserializer/misc/domain-list-deserializer.js +64 -0
  66. package/dist/deserializer/misc/list-item-deserializer.js +69 -0
  67. package/dist/deserializer/misc/list-items-deserializer.js +30 -0
  68. package/dist/deserializer/misc/logical-expression-deserializer.js +196 -0
  69. package/dist/deserializer/misc/modifier-deserializer.js +87 -0
  70. package/dist/deserializer/misc/modifier-list-deserializer.js +61 -0
  71. package/dist/deserializer/misc/parameter-list-deserializer.js +64 -0
  72. package/dist/deserializer/misc/value-deserializer.js +50 -0
  73. package/dist/deserializer/network/host-rule-deserializer.js +67 -0
  74. package/dist/deserializer/network/hostname-list-deserializer.js +56 -0
  75. package/dist/deserializer/network/network-rule-deserializer.js +65 -0
  76. package/dist/deserializer/rule-deserializer.js +65 -0
  77. package/dist/deserializer/syntax-deserialization-map.js +21 -0
  78. package/dist/errors/adblock-syntax-error.js +39 -0
  79. package/dist/errors/binary-schema-mismatch-error.js +37 -0
  80. package/dist/errors/not-implemented-error.js +31 -0
  81. package/dist/errors/rule-conversion-error.js +26 -0
  82. package/dist/generator/base-generator.js +27 -0
  83. package/dist/generator/comment/agent-comment-generator.js +31 -0
  84. package/dist/generator/comment/agent-generator.js +36 -0
  85. package/dist/generator/comment/comment-rule-generator.js +47 -0
  86. package/dist/generator/comment/config-comment-generator.js +45 -0
  87. package/dist/generator/comment/hint-comment-generator.js +28 -0
  88. package/dist/generator/comment/hint-generator.js +33 -0
  89. package/dist/generator/comment/metadata-comment-generator.js +33 -0
  90. package/dist/generator/comment/pre-processor-comment-generator.js +48 -0
  91. package/dist/generator/comment/simple-comment-generator.js +29 -0
  92. package/dist/generator/cosmetic/body/abp-snippet-injection-body-generator.js +38 -0
  93. package/dist/generator/cosmetic/body/adg-scriptlet-injection-body-generator.js +43 -0
  94. package/dist/generator/cosmetic/body/ubo-scriptlet-injection-body-generator.js +45 -0
  95. package/dist/generator/cosmetic/cosmetic-rule-body-generator.js +94 -0
  96. package/dist/generator/cosmetic/cosmetic-rule-generator.js +54 -0
  97. package/dist/generator/cosmetic/cosmetic-rule-pattern-generator.js +42 -0
  98. package/dist/generator/css/adg-css-injection-generator.js +42 -0
  99. package/dist/generator/filterlist-generator.js +67 -0
  100. package/dist/generator/index.js +9 -0
  101. package/dist/generator/misc/domain-list-generator.js +26 -0
  102. package/dist/generator/misc/list-items-generator.js +39 -0
  103. package/dist/generator/misc/logical-expression-generator.js +48 -0
  104. package/dist/generator/misc/modifier-generator.js +34 -0
  105. package/dist/generator/misc/modifier-list-generator.js +29 -0
  106. package/dist/generator/misc/parameter-list-generator.js +41 -0
  107. package/dist/generator/misc/value-generator.js +24 -0
  108. package/dist/generator/network/host-rule-generator.js +39 -0
  109. package/dist/generator/network/network-rule-generator.js +38 -0
  110. package/dist/generator/rule-generator.js +65 -0
  111. package/dist/index.js +70 -0
  112. package/dist/marshalling-utils/comment/agent-comment-common.js +21 -0
  113. package/dist/marshalling-utils/comment/agent-common.js +40 -0
  114. package/dist/marshalling-utils/comment/config-comment-common.js +54 -0
  115. package/dist/marshalling-utils/comment/hint-comment-common.js +22 -0
  116. package/dist/marshalling-utils/comment/hint-common.js +56 -0
  117. package/dist/marshalling-utils/comment/metadata-comment-common.js +41 -0
  118. package/dist/marshalling-utils/comment/pre-processor-comment-common.js +59 -0
  119. package/dist/marshalling-utils/comment/simple-comment-common.js +22 -0
  120. package/dist/marshalling-utils/cosmetic/body/abp-snippet-injection-body-common.js +61 -0
  121. package/dist/marshalling-utils/cosmetic/body/adg-scriptlet-injection-body-common.js +66 -0
  122. package/dist/marshalling-utils/cosmetic/body/css-injection-body-common.js +24 -0
  123. package/dist/marshalling-utils/cosmetic/body/element-hiding-body-common.js +21 -0
  124. package/dist/marshalling-utils/cosmetic/body/ubo-scriptlet-injection-body-common.js +114 -0
  125. package/dist/marshalling-utils/cosmetic/cosmetic-rule-common.js +48 -0
  126. package/dist/marshalling-utils/empty-rule-common.js +20 -0
  127. package/dist/marshalling-utils/filter-list-common.js +21 -0
  128. package/dist/marshalling-utils/invalid-rule-common.js +21 -0
  129. package/dist/marshalling-utils/invalid-rule-error-node-common.js +22 -0
  130. package/dist/marshalling-utils/misc/binary-type-common.js +66 -0
  131. package/dist/marshalling-utils/misc/domain-list-common.js +36 -0
  132. package/dist/marshalling-utils/misc/host-rule-common.js +25 -0
  133. package/dist/marshalling-utils/misc/hostname-list-common.js +21 -0
  134. package/dist/marshalling-utils/misc/list-item-common.js +22 -0
  135. package/dist/marshalling-utils/misc/logical-expression-common.js +83 -0
  136. package/dist/marshalling-utils/misc/modifier-common.js +231 -0
  137. package/dist/marshalling-utils/misc/modifier-list-common.js +21 -0
  138. package/dist/marshalling-utils/misc/parameter-list-common.js +21 -0
  139. package/dist/marshalling-utils/misc/value-common.js +22 -0
  140. package/dist/marshalling-utils/network/network-rule-common.js +25 -0
  141. package/dist/marshalling-utils/syntax-serialization-map.js +30 -0
  142. package/dist/nodes/index.js +168 -0
  143. package/dist/package.json.js +9 -0
  144. package/dist/parser/base-parser.js +30 -0
  145. package/dist/parser/comment/agent-comment-parser.js +119 -0
  146. package/dist/parser/comment/agent-parser.js +110 -0
  147. package/dist/parser/comment/comment-parser.js +108 -0
  148. package/dist/parser/comment/config-comment-parser.js +137 -0
  149. package/dist/parser/comment/hint-comment-parser.js +117 -0
  150. package/dist/parser/comment/hint-parser.js +129 -0
  151. package/dist/parser/comment/metadata-comment-parser.js +129 -0
  152. package/dist/parser/comment/preprocessor-parser.js +199 -0
  153. package/dist/parser/comment/simple-comment-parser.js +106 -0
  154. package/dist/parser/cosmetic/body/abp-snippet-injection-body-parser.js +79 -0
  155. package/dist/parser/cosmetic/body/adg-scriptlet-injection-body-parser.js +149 -0
  156. package/dist/parser/cosmetic/body/ubo-scriptlet-injection-body-parser.js +110 -0
  157. package/dist/parser/cosmetic/cosmetic-rule-parser.js +453 -0
  158. package/dist/parser/css/adg-css-injection-parser.js +208 -0
  159. package/dist/parser/css/balancing.js +94 -0
  160. package/dist/parser/css/constants.js +18 -0
  161. package/dist/parser/css/css-token-stream.js +343 -0
  162. package/dist/parser/css/ubo-selector-parser.js +369 -0
  163. package/dist/parser/filterlist-parser.js +102 -0
  164. package/dist/parser/index.js +12 -0
  165. package/dist/parser/misc/app-list-parser.js +45 -0
  166. package/dist/parser/misc/domain-list-parser.js +52 -0
  167. package/dist/parser/misc/list-items-parser.js +116 -0
  168. package/dist/parser/misc/logical-expression-parser.js +279 -0
  169. package/dist/parser/misc/method-list-parser.js +46 -0
  170. package/dist/parser/misc/modifier-list.js +70 -0
  171. package/dist/parser/misc/modifier-parser.js +89 -0
  172. package/dist/parser/misc/parameter-list-parser.js +75 -0
  173. package/dist/parser/misc/stealth-option-list-parser.js +46 -0
  174. package/dist/parser/misc/ubo-parameter-list-parser.js +149 -0
  175. package/dist/parser/misc/value-parser.js +37 -0
  176. package/dist/parser/network/host-rule-parser.js +130 -0
  177. package/dist/parser/network/network-rule-parser.js +117 -0
  178. package/dist/parser/options.js +23 -0
  179. package/dist/parser/rule-parser.js +192 -0
  180. package/dist/serializer/base-serializer.js +29 -0
  181. package/dist/serializer/comment/agent-comment-serializer.js +74 -0
  182. package/dist/serializer/comment/agent-serializer.js +59 -0
  183. package/dist/serializer/comment/comment-rule-serializer.js +105 -0
  184. package/dist/serializer/comment/config-comment-serializer.js +82 -0
  185. package/dist/serializer/comment/hint-comment-serializer.js +65 -0
  186. package/dist/serializer/comment/hint-serializer.js +54 -0
  187. package/dist/serializer/comment/metadata-comment-serializer.js +73 -0
  188. package/dist/serializer/comment/pre-processor-comment-serializer.js +71 -0
  189. package/dist/serializer/comment/simple-comment-serializer.js +52 -0
  190. package/dist/serializer/cosmetic/body/abp-snippet-injection-body-serializer.js +36 -0
  191. package/dist/serializer/cosmetic/body/adg-scriptlet-injection-body-serializer.js +36 -0
  192. package/dist/serializer/cosmetic/body/scriptlet-body-serializer.js +50 -0
  193. package/dist/serializer/cosmetic/body/ubo-scriptlet-injection-body-serializer.js +36 -0
  194. package/dist/serializer/cosmetic/cosmetic-rule-serializer.js +120 -0
  195. package/dist/serializer/cosmetic/css-injection-body-serializer.js +51 -0
  196. package/dist/serializer/cosmetic/element-hiding-body-serializer.js +40 -0
  197. package/dist/serializer/empty-rule-serializer.js +37 -0
  198. package/dist/serializer/filterlist-serializer.js +45 -0
  199. package/dist/serializer/index.js +7 -0
  200. package/dist/serializer/invalid-rule-error-node-serializer.js +41 -0
  201. package/dist/serializer/invalid-rule-serializer.js +40 -0
  202. package/dist/serializer/misc/domain-list-serializer.js +64 -0
  203. package/dist/serializer/misc/list-item-serializer.js +58 -0
  204. package/dist/serializer/misc/list-items-serializer.js +29 -0
  205. package/dist/serializer/misc/logical-expression-serializer.js +136 -0
  206. package/dist/serializer/misc/modifier-list-serializer.js +58 -0
  207. package/dist/serializer/misc/modifier-serializer.js +49 -0
  208. package/dist/serializer/misc/parameter-list-serializer.js +52 -0
  209. package/dist/serializer/misc/value-serializer.js +50 -0
  210. package/dist/serializer/network/host-rule-serializer.js +70 -0
  211. package/dist/serializer/network/hostname-list-serializer.js +53 -0
  212. package/dist/serializer/network/network-rule-serializer.js +54 -0
  213. package/dist/serializer/rule-serializer.js +61 -0
  214. package/dist/types/ast-utils/clone.d.ts +26 -0
  215. package/dist/types/ast-utils/filter-list.d.ts +11 -0
  216. package/dist/types/ast-utils/modifiers.d.ts +20 -0
  217. package/dist/types/ast-utils/network-rules.d.ts +15 -0
  218. package/dist/types/ast-utils/scriptlets.d.ts +52 -0
  219. package/dist/types/common/abp-snippet-injection-body-common.d.ts +15 -0
  220. package/dist/types/common/agent-common.d.ts +10 -0
  221. package/dist/types/common/ubo-selector-common.d.ts +10 -0
  222. package/dist/types/compatibility-tables/base.d.ts +157 -0
  223. package/dist/types/compatibility-tables/compatibility-table-data.d.ts +68 -0
  224. package/dist/types/compatibility-tables/index.d.ts +13 -0
  225. package/dist/types/compatibility-tables/modifiers.d.ts +22 -0
  226. package/dist/types/compatibility-tables/platforms.d.ts +49 -0
  227. package/dist/types/compatibility-tables/redirects.d.ts +33 -0
  228. package/dist/types/compatibility-tables/schemas/base.d.ts +124 -0
  229. package/dist/types/compatibility-tables/schemas/index.d.ts +8 -0
  230. package/dist/types/compatibility-tables/schemas/modifier.d.ts +36 -0
  231. package/dist/types/compatibility-tables/schemas/platform.d.ts +16 -0
  232. package/dist/types/compatibility-tables/schemas/redirect.d.ts +25 -0
  233. package/dist/types/compatibility-tables/schemas/resource-type.d.ts +41 -0
  234. package/dist/types/compatibility-tables/schemas/scriptlet.d.ts +31 -0
  235. package/dist/types/compatibility-tables/scriptlets.d.ts +15 -0
  236. package/dist/types/compatibility-tables/types.d.ts +34 -0
  237. package/dist/types/compatibility-tables/utils/platform-helpers.d.ts +44 -0
  238. package/dist/types/compatibility-tables/utils/resource-type-helpers.d.ts +20 -0
  239. package/dist/types/compatibility-tables/utils/zod-camelcase.d.ts +15 -0
  240. package/dist/types/converter/base-interfaces/base-converter.d.ts +42 -0
  241. package/dist/types/converter/base-interfaces/conversion-result.d.ts +43 -0
  242. package/dist/types/converter/base-interfaces/rule-converter-base.d.ts +44 -0
  243. package/dist/types/converter/comment/index.d.ts +23 -0
  244. package/dist/types/converter/cosmetic/css.d.ts +23 -0
  245. package/dist/types/converter/cosmetic/element-hiding.d.ts +23 -0
  246. package/dist/types/converter/cosmetic/header-removal.d.ts +37 -0
  247. package/dist/types/converter/cosmetic/html.d.ts +54 -0
  248. package/dist/types/converter/cosmetic/index.d.ts +33 -0
  249. package/dist/types/converter/cosmetic/rule-modifiers/adg.d.ts +21 -0
  250. package/dist/types/converter/cosmetic/scriptlet.d.ts +33 -0
  251. package/dist/types/converter/css/index.d.ts +40 -0
  252. package/dist/types/converter/data/css.d.ts +48 -0
  253. package/dist/types/converter/filter-list.d.ts +31 -0
  254. package/dist/types/converter/index.d.ts +5 -0
  255. package/dist/types/converter/misc/network-rule-modifier.d.ts +35 -0
  256. package/dist/types/converter/network/index.d.ts +33 -0
  257. package/dist/types/converter/raw-filter-list.d.ts +31 -0
  258. package/dist/types/converter/raw-rule.d.ts +28 -0
  259. package/dist/types/converter/rule.d.ts +37 -0
  260. package/dist/types/deserializer/base-deserializer.d.ts +15 -0
  261. package/dist/types/deserializer/comment/agent-comment-deserializer.d.ts +34 -0
  262. package/dist/types/deserializer/comment/agent-deserializer.d.ts +25 -0
  263. package/dist/types/deserializer/comment/comment-rule-deserializer.d.ts +16 -0
  264. package/dist/types/deserializer/comment/config-comment-deserializer.d.ts +27 -0
  265. package/dist/types/deserializer/comment/hint-comment-deserializer.d.ts +24 -0
  266. package/dist/types/deserializer/comment/hint-deserializer.d.ts +26 -0
  267. package/dist/types/deserializer/comment/metadata-comment-deserializer.d.ts +26 -0
  268. package/dist/types/deserializer/comment/pre-processor-comment-deserializer.d.ts +29 -0
  269. package/dist/types/deserializer/comment/simple-comment-deserializer.d.ts +26 -0
  270. package/dist/types/deserializer/cosmetic/cosmetic-rule-deserializer.d.ts +18 -0
  271. package/dist/types/deserializer/cosmetic/css-injection-body-deserializer.d.ts +15 -0
  272. package/dist/types/deserializer/cosmetic/element-hiding-body-deserializer.d.ts +16 -0
  273. package/dist/types/deserializer/cosmetic/scriptlet-body/abp-snippet-injection-body-deserializer.d.ts +17 -0
  274. package/dist/types/deserializer/cosmetic/scriptlet-body/adg-scriptlet-injection-body-deserializer.d.ts +18 -0
  275. package/dist/types/deserializer/cosmetic/scriptlet-body/scriptlet-body-deserializer.d.ts +19 -0
  276. package/dist/types/deserializer/cosmetic/scriptlet-body/ubo-scriptlet-injection-body-deserializer.d.ts +17 -0
  277. package/dist/types/deserializer/empty-rule-deserializer.d.ts +16 -0
  278. package/dist/types/deserializer/filterlist-deserializer.d.ts +34 -0
  279. package/dist/types/deserializer/index.d.ts +2 -0
  280. package/dist/types/deserializer/invalid-rule-deserializer.d.ts +16 -0
  281. package/dist/types/deserializer/invalid-rule-error-node-deserializer.d.ts +16 -0
  282. package/dist/types/deserializer/misc/domain-list-deserializer.d.ts +15 -0
  283. package/dist/types/deserializer/misc/list-item-deserializer.d.ts +19 -0
  284. package/dist/types/deserializer/misc/list-items-deserializer.d.ts +16 -0
  285. package/dist/types/deserializer/misc/logical-expression-deserializer.d.ts +55 -0
  286. package/dist/types/deserializer/misc/modifier-deserializer.d.ts +18 -0
  287. package/dist/types/deserializer/misc/modifier-list-deserializer.d.ts +20 -0
  288. package/dist/types/deserializer/misc/parameter-list-deserializer.d.ts +18 -0
  289. package/dist/types/deserializer/misc/value-deserializer.d.ts +17 -0
  290. package/dist/types/deserializer/network/host-rule-deserializer.d.ts +18 -0
  291. package/dist/types/deserializer/network/hostname-list-deserializer.d.ts +15 -0
  292. package/dist/types/deserializer/network/network-rule-deserializer.d.ts +18 -0
  293. package/dist/types/deserializer/rule-deserializer.d.ts +17 -0
  294. package/dist/types/deserializer/syntax-deserialization-map.d.ts +2 -0
  295. package/dist/types/errors/adblock-syntax-error.d.ts +25 -0
  296. package/dist/types/errors/binary-schema-mismatch-error.d.ts +23 -0
  297. package/dist/types/errors/not-implemented-error.d.ts +14 -0
  298. package/dist/types/errors/rule-conversion-error.d.ts +14 -0
  299. package/dist/types/generator/base-generator.d.ts +12 -0
  300. package/dist/types/generator/comment/agent-comment-generator.d.ts +14 -0
  301. package/dist/types/generator/comment/agent-generator.d.ts +15 -0
  302. package/dist/types/generator/comment/comment-rule-generator.d.ts +14 -0
  303. package/dist/types/generator/comment/config-comment-generator.d.ts +14 -0
  304. package/dist/types/generator/comment/hint-comment-generator.d.ts +14 -0
  305. package/dist/types/generator/comment/hint-generator.d.ts +14 -0
  306. package/dist/types/generator/comment/index.d.ts +1 -0
  307. package/dist/types/generator/comment/metadata-comment-generator.d.ts +14 -0
  308. package/dist/types/generator/comment/pre-processor-comment-generator.d.ts +14 -0
  309. package/dist/types/generator/comment/simple-comment-generator.d.ts +14 -0
  310. package/dist/types/generator/cosmetic/body/abp-snippet-injection-body-generator.d.ts +15 -0
  311. package/dist/types/generator/cosmetic/body/adg-scriptlet-injection-body-generator.d.ts +21 -0
  312. package/dist/types/generator/cosmetic/body/ubo-scriptlet-injection-body-generator.d.ts +21 -0
  313. package/dist/types/generator/cosmetic/cosmetic-rule-body-generator.d.ts +20 -0
  314. package/dist/types/generator/cosmetic/cosmetic-rule-generator.d.ts +28 -0
  315. package/dist/types/generator/cosmetic/cosmetic-rule-pattern-generator.d.ts +18 -0
  316. package/dist/types/generator/cosmetic/index.d.ts +1 -0
  317. package/dist/types/generator/css/adg-css-injection-generator.d.ts +15 -0
  318. package/dist/types/generator/css/ubo-selector-generator.d.ts +14 -0
  319. package/dist/types/generator/filterlist-generator.d.ts +18 -0
  320. package/dist/types/generator/index.d.ts +3 -0
  321. package/dist/types/generator/misc/domain-list-generator.d.ts +15 -0
  322. package/dist/types/generator/misc/list-items-generator.d.ts +25 -0
  323. package/dist/types/generator/misc/logical-expression-generator.d.ts +14 -0
  324. package/dist/types/generator/misc/modifier-generator.d.ts +14 -0
  325. package/dist/types/generator/misc/modifier-list-generator.d.ts +14 -0
  326. package/dist/types/generator/misc/parameter-list-generator.d.ts +15 -0
  327. package/dist/types/generator/misc/value-generator.d.ts +14 -0
  328. package/dist/types/generator/network/host-rule-generator.d.ts +14 -0
  329. package/dist/types/generator/network/index.d.ts +2 -0
  330. package/dist/types/generator/network/network-rule-generator.d.ts +14 -0
  331. package/dist/types/generator/rule-generator.d.ts +24 -0
  332. package/dist/types/index.d.ts +55 -0
  333. package/dist/types/marshalling-utils/comment/agent-comment-common.d.ts +14 -0
  334. package/dist/types/marshalling-utils/comment/agent-common.d.ts +20 -0
  335. package/dist/types/marshalling-utils/comment/config-comment-common.d.ts +42 -0
  336. package/dist/types/marshalling-utils/comment/hint-comment-common.d.ts +15 -0
  337. package/dist/types/marshalling-utils/comment/hint-common.d.ts +33 -0
  338. package/dist/types/marshalling-utils/comment/metadata-comment-common.d.ts +21 -0
  339. package/dist/types/marshalling-utils/comment/pre-processor-comment-common.d.ts +37 -0
  340. package/dist/types/marshalling-utils/comment/simple-comment-common.d.ts +15 -0
  341. package/dist/types/marshalling-utils/cosmetic/body/abp-snippet-injection-body-common.d.ts +23 -0
  342. package/dist/types/marshalling-utils/cosmetic/body/adg-scriptlet-injection-body-common.d.ts +9 -0
  343. package/dist/types/marshalling-utils/cosmetic/body/css-injection-body-common.d.ts +17 -0
  344. package/dist/types/marshalling-utils/cosmetic/body/element-hiding-body-common.d.ts +14 -0
  345. package/dist/types/marshalling-utils/cosmetic/body/ubo-scriptlet-injection-body-common.d.ts +9 -0
  346. package/dist/types/marshalling-utils/cosmetic/cosmetic-rule-common.d.ts +28 -0
  347. package/dist/types/marshalling-utils/empty-rule-common.d.ts +13 -0
  348. package/dist/types/marshalling-utils/filter-list-common.d.ts +14 -0
  349. package/dist/types/marshalling-utils/invalid-rule-common.d.ts +14 -0
  350. package/dist/types/marshalling-utils/invalid-rule-error-node-common.d.ts +15 -0
  351. package/dist/types/marshalling-utils/misc/binary-type-common.d.ts +57 -0
  352. package/dist/types/marshalling-utils/misc/domain-list-common.d.ts +24 -0
  353. package/dist/types/marshalling-utils/misc/host-rule-common.d.ts +18 -0
  354. package/dist/types/marshalling-utils/misc/hostname-list-common.d.ts +14 -0
  355. package/dist/types/marshalling-utils/misc/list-item-common.d.ts +15 -0
  356. package/dist/types/marshalling-utils/misc/logical-expression-common.d.ts +47 -0
  357. package/dist/types/marshalling-utils/misc/modifier-common.d.ts +41 -0
  358. package/dist/types/marshalling-utils/misc/modifier-list-common.d.ts +14 -0
  359. package/dist/types/marshalling-utils/misc/parameter-list-common.d.ts +14 -0
  360. package/dist/types/marshalling-utils/misc/value-common.d.ts +15 -0
  361. package/dist/types/marshalling-utils/network/network-rule-common.d.ts +18 -0
  362. package/dist/types/marshalling-utils/syntax-serialization-map.d.ts +2 -0
  363. package/dist/types/nodes/index.d.ts +1183 -0
  364. package/dist/types/parser/base-parser.d.ts +16 -0
  365. package/dist/types/parser/comment/agent-comment-parser.d.ts +42 -0
  366. package/dist/types/parser/comment/agent-parser.d.ts +33 -0
  367. package/dist/types/parser/comment/comment-parser.d.ts +76 -0
  368. package/dist/types/parser/comment/config-comment-parser.d.ts +31 -0
  369. package/dist/types/parser/comment/hint-comment-parser.d.ts +33 -0
  370. package/dist/types/parser/comment/hint-parser.d.ts +30 -0
  371. package/dist/types/parser/comment/metadata-comment-parser.d.ts +29 -0
  372. package/dist/types/parser/comment/preprocessor-parser.d.ts +43 -0
  373. package/dist/types/parser/comment/simple-comment-parser.d.ts +33 -0
  374. package/dist/types/parser/cosmetic/body/abp-snippet-injection-body-parser.d.ts +34 -0
  375. package/dist/types/parser/cosmetic/body/adg-scriptlet-injection-body-parser.d.ts +47 -0
  376. package/dist/types/parser/cosmetic/body/ubo-scriptlet-injection-body-parser.d.ts +44 -0
  377. package/dist/types/parser/cosmetic/cosmetic-rule-parser.d.ts +51 -0
  378. package/dist/types/parser/css/adg-css-injection-parser.d.ts +28 -0
  379. package/dist/types/parser/css/balancing.d.ts +36 -0
  380. package/dist/types/parser/css/constants.d.ts +10 -0
  381. package/dist/types/parser/css/css-token-stream.d.ts +210 -0
  382. package/dist/types/parser/css/ubo-selector-parser.d.ts +46 -0
  383. package/dist/types/parser/filterlist-parser.d.ts +29 -0
  384. package/dist/types/parser/index.d.ts +6 -0
  385. package/dist/types/parser/misc/app-list-parser.d.ts +22 -0
  386. package/dist/types/parser/misc/domain-list-parser.d.ts +26 -0
  387. package/dist/types/parser/misc/list-items-parser.d.ts +37 -0
  388. package/dist/types/parser/misc/logical-expression-parser.d.ts +42 -0
  389. package/dist/types/parser/misc/method-list-parser.d.ts +22 -0
  390. package/dist/types/parser/misc/modifier-list.d.ts +24 -0
  391. package/dist/types/parser/misc/modifier-parser.d.ts +21 -0
  392. package/dist/types/parser/misc/parameter-list-parser.d.ts +17 -0
  393. package/dist/types/parser/misc/stealth-option-list-parser.d.ts +22 -0
  394. package/dist/types/parser/misc/ubo-parameter-list-parser.d.ts +21 -0
  395. package/dist/types/parser/misc/value-parser.d.ts +18 -0
  396. package/dist/types/parser/network/host-rule-parser.d.ts +35 -0
  397. package/dist/types/parser/network/network-rule-parser.d.ts +31 -0
  398. package/dist/types/parser/options.d.ts +41 -0
  399. package/dist/types/parser/rule-parser.d.ts +78 -0
  400. package/dist/types/serializer/base-serializer.d.ts +15 -0
  401. package/dist/types/serializer/comment/agent-comment-serializer.d.ts +34 -0
  402. package/dist/types/serializer/comment/agent-serializer.d.ts +15 -0
  403. package/dist/types/serializer/comment/comment-rule-serializer.d.ts +68 -0
  404. package/dist/types/serializer/comment/config-comment-serializer.d.ts +25 -0
  405. package/dist/types/serializer/comment/hint-comment-serializer.d.ts +23 -0
  406. package/dist/types/serializer/comment/hint-serializer.d.ts +24 -0
  407. package/dist/types/serializer/comment/metadata-comment-serializer.d.ts +25 -0
  408. package/dist/types/serializer/comment/pre-processor-comment-serializer.d.ts +28 -0
  409. package/dist/types/serializer/comment/simple-comment-serializer.d.ts +24 -0
  410. package/dist/types/serializer/cosmetic/body/abp-snippet-injection-body-serializer.d.ts +25 -0
  411. package/dist/types/serializer/cosmetic/body/adg-scriptlet-injection-body-serializer.d.ts +25 -0
  412. package/dist/types/serializer/cosmetic/body/scriptlet-body-serializer.d.ts +17 -0
  413. package/dist/types/serializer/cosmetic/body/ubo-scriptlet-injection-body-serializer.d.ts +25 -0
  414. package/dist/types/serializer/cosmetic/cosmetic-rule-serializer.d.ts +19 -0
  415. package/dist/types/serializer/cosmetic/css-injection-body-serializer.d.ts +15 -0
  416. package/dist/types/serializer/cosmetic/element-hiding-body-serializer.d.ts +15 -0
  417. package/dist/types/serializer/empty-rule-serializer.d.ts +15 -0
  418. package/dist/types/serializer/filterlist-serializer.d.ts +15 -0
  419. package/dist/types/serializer/index.d.ts +1 -0
  420. package/dist/types/serializer/invalid-rule-error-node-serializer.d.ts +15 -0
  421. package/dist/types/serializer/invalid-rule-serializer.d.ts +15 -0
  422. package/dist/types/serializer/misc/domain-list-serializer.d.ts +21 -0
  423. package/dist/types/serializer/misc/list-item-serializer.d.ts +16 -0
  424. package/dist/types/serializer/misc/list-items-serializer.d.ts +15 -0
  425. package/dist/types/serializer/misc/logical-expression-serializer.d.ts +52 -0
  426. package/dist/types/serializer/misc/modifier-list-serializer.d.ts +20 -0
  427. package/dist/types/serializer/misc/modifier-serializer.d.ts +18 -0
  428. package/dist/types/serializer/misc/parameter-list-serializer.d.ts +17 -0
  429. package/dist/types/serializer/misc/value-serializer.d.ts +17 -0
  430. package/dist/types/serializer/network/host-rule-serializer.d.ts +30 -0
  431. package/dist/types/serializer/network/hostname-list-serializer.d.ts +15 -0
  432. package/dist/types/serializer/network/network-rule-serializer.d.ts +18 -0
  433. package/dist/types/serializer/rule-serializer.d.ts +17 -0
  434. package/dist/types/utils/adblockers.d.ts +49 -0
  435. package/dist/types/utils/binary-schema-version.d.ts +9 -0
  436. package/dist/types/utils/byte-buffer.d.ts +54 -0
  437. package/dist/types/utils/categorizer.d.ts +14 -0
  438. package/dist/types/utils/clone.d.ts +15 -0
  439. package/dist/types/utils/constants.d.ts +188 -0
  440. package/dist/types/utils/cosmetic-rule-separator.d.ts +45 -0
  441. package/dist/types/utils/deep-freeze.d.ts +13 -0
  442. package/dist/types/utils/domain.d.ts +29 -0
  443. package/dist/types/utils/error.d.ts +8 -0
  444. package/dist/types/utils/index.d.ts +15 -0
  445. package/dist/types/utils/input-byte-buffer.d.ts +146 -0
  446. package/dist/types/utils/is-chromium.d.ts +7 -0
  447. package/dist/types/utils/logical-expression.d.ts +45 -0
  448. package/dist/types/utils/multi-value-map.d.ts +16 -0
  449. package/dist/types/utils/output-byte-buffer.d.ts +132 -0
  450. package/dist/types/utils/position-provider.d.ts +46 -0
  451. package/dist/types/utils/quotes.d.ts +94 -0
  452. package/dist/types/utils/regexp.d.ts +54 -0
  453. package/dist/types/utils/storage-interface.d.ts +23 -0
  454. package/dist/types/utils/string.d.ts +280 -0
  455. package/dist/types/utils/text-decoder-polyfill.d.ts +14 -0
  456. package/dist/types/utils/text-encoder-polyfill.d.ts +18 -0
  457. package/dist/types/utils/type-guards.d.ts +47 -0
  458. package/dist/types/validator/constants.d.ts +89 -0
  459. package/dist/types/validator/helpers.d.ts +37 -0
  460. package/dist/types/validator/index.d.ts +38 -0
  461. package/dist/types/validator/value.d.ts +12 -0
  462. package/dist/types/version.d.ts +5 -0
  463. package/dist/utils/adblockers.js +56 -0
  464. package/dist/utils/binary-schema-version.js +17 -0
  465. package/dist/utils/byte-buffer.js +91 -0
  466. package/dist/utils/categorizer.js +44 -0
  467. package/dist/utils/clone.js +28 -0
  468. package/dist/utils/constants.js +249 -0
  469. package/dist/utils/cosmetic-rule-separator.js +127 -0
  470. package/dist/utils/deep-freeze.js +32 -0
  471. package/dist/utils/domain.js +59 -0
  472. package/dist/utils/error.js +49 -0
  473. package/dist/utils/index.js +21 -0
  474. package/dist/utils/input-byte-buffer.js +265 -0
  475. package/dist/utils/is-chromium.js +20 -0
  476. package/dist/utils/logical-expression.js +92 -0
  477. package/dist/utils/multi-value-map.js +33 -0
  478. package/dist/utils/output-byte-buffer.js +231 -0
  479. package/dist/utils/position-provider.js +73 -0
  480. package/dist/utils/quotes.js +214 -0
  481. package/dist/utils/regexp.js +176 -0
  482. package/dist/utils/string.js +559 -0
  483. package/dist/utils/text-decoder-polyfill.js +107 -0
  484. package/dist/utils/text-encoder-polyfill.js +78 -0
  485. package/dist/utils/type-guards.js +47 -0
  486. package/dist/validator/constants.js +210 -0
  487. package/dist/validator/helpers.js +45 -0
  488. package/dist/validator/index.js +174 -0
  489. package/dist/validator/value.js +568 -0
  490. package/dist/version.js +18 -0
  491. package/package.json +61 -39
  492. package/dist/agtree.d.ts +0 -4155
  493. package/dist/agtree.js +0 -15819
  494. package/dist/agtree.mjs +0 -15720
  495. package/dist/compatibility-table-data.js +0 -12782
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @file Utility functions for domain and hostname validation.
3
+ */
4
+ /**
5
+ * Marker for a wildcard top-level domain — `.*`.
6
+ *
7
+ * @example
8
+ * `example.*` — matches with any TLD, e.g. `example.org`, `example.com`, etc.
9
+ */
10
+ export declare const WILDCARD_TLD: string;
11
+ /**
12
+ * Marker for a wildcard subdomain — `*.`.
13
+ *
14
+ * @example
15
+ * `*.example.org` — matches with any subdomain, e.g. `foo.example.org` or `bar.example.org`
16
+ */
17
+ export declare const WILDCARD_SUBDOMAIN: string;
18
+ /**
19
+ * Utility functions for domain and hostname validation.
20
+ */
21
+ export declare class DomainUtils {
22
+ /**
23
+ * Check if the input is a valid domain or hostname.
24
+ *
25
+ * @param domain Domain to check
26
+ * @returns `true` if the domain is valid, `false` otherwise
27
+ */
28
+ static isValidDomainOrHostname(domain: string): boolean;
29
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Converts error object to error with message. This method might be helpful to handle thrown errors.
3
+ *
4
+ * @param error Error object.
5
+ *
6
+ * @returns Message of the error.
7
+ */
8
+ export declare function getErrorMessage(error: unknown): string;
@@ -0,0 +1,15 @@
1
+ export { ADG_SCRIPTLET_MASK, AGLINT_COMMAND_PREFIX, COMMA_DOMAIN_LIST_SEPARATOR, NEGATION_MARKER, HINT_MARKER, IF, INCLUDE, MODIFIERS_SEPARATOR, MODIFIER_ASSIGN_OPERATOR, PIPE_MODIFIER_SEPARATOR, NETWORK_RULE_EXCEPTION_MARKER, NETWORK_RULE_SEPARATOR, PREPROCESSOR_MARKER, SAFARI_CB_AFFINITY, UBO_SCRIPTLET_MASK, } from './constants';
2
+ export { BINARY_SCHEMA_VERSION } from './binary-schema-version';
3
+ export { AdblockSyntax } from './adblockers';
4
+ export { type CosmeticRuleSeparatorFinderResult, CosmeticRuleSeparatorUtils } from './cosmetic-rule-separator';
5
+ export { DomainUtils } from './domain';
6
+ export { type VariableTable, LogicalExpressionUtils } from './logical-expression';
7
+ export { ADBLOCK_URL_START, ADBLOCK_URL_START_REGEX, ADBLOCK_URL_SEPARATOR, ADBLOCK_URL_SEPARATOR_REGEX, ADBLOCK_WILDCARD, ADBLOCK_WILDCARD_REGEX, SPECIAL_REGEX_SYMBOLS, RegExpUtils, } from './regexp';
8
+ export { QuoteType, QuoteUtils, } from './quotes';
9
+ export { type Position, PositionProvider } from './position-provider';
10
+ export { OutputByteBuffer } from './output-byte-buffer';
11
+ export { InputByteBuffer } from './input-byte-buffer';
12
+ export { ByteBuffer } from './byte-buffer';
13
+ export { encodeIntoPolyfill, type TextEncoderPolyfillResult } from './text-encoder-polyfill';
14
+ export { decodeTextPolyfill } from './text-decoder-polyfill';
15
+ export { RuleCategorizer } from './categorizer';
@@ -0,0 +1,146 @@
1
+ /**
2
+ * @file Input byte buffer for reading binary data.
3
+ */
4
+ import { ByteBuffer } from './byte-buffer';
5
+ import { type Storage } from './storage-interface';
6
+ /**
7
+ * Input byte buffer for reading binary data.
8
+ *
9
+ * @note Internally, this class uses a {@link ByteBuffer} instance, just providing a convenient API for reading data.
10
+ */
11
+ export declare class InputByteBuffer extends ByteBuffer {
12
+ /**
13
+ * Current offset in the buffer for reading.
14
+ */
15
+ private offset;
16
+ /**
17
+ * Shared native decoder for decoding strings.
18
+ */
19
+ private readonly sharedNativeDecoder;
20
+ /**
21
+ * Flag indicating if the current environment is Chromium.
22
+ * This is used for performance optimizations, because Chromium's TextEncoder/TextDecoder has a relatively
23
+ * large marshalling overhead for small strings.
24
+ */
25
+ private readonly isChromium;
26
+ /**
27
+ * Constructs a new `InputByteBuffer` instance.
28
+ *
29
+ * @param chunks Array of chunks to initialize the ByteBuffer with.
30
+ * @param cloneChunks Flag indicating if the chunks should be cloned. For performance reasons,
31
+ * its default value is `false`. If the original chunks are guaranteed not to change,
32
+ * leave this flag as `false` to avoid unnecessary copying.
33
+ * @param initialOffset Initial offset in the buffer for reading.
34
+ *
35
+ * @throws If the specified chunks array is empty.
36
+ * @throws If the binary schema version in the buffer is not equal to the expected version.
37
+ * @throws If the initial offset is out of bounds.
38
+ */
39
+ constructor(chunks: Uint8Array[], cloneChunks?: boolean, initialOffset?: number);
40
+ /**
41
+ * Creates a new InputByteBuffer instance from a Storage instance by reading chunks from the storage.
42
+ *
43
+ * @param storage Storage instance.
44
+ * @param key Key to read from the storage.
45
+ * @returns New InputByteBuffer instance.
46
+ * @note For performance reasons, chunks are passed by reference and not copied.
47
+ */
48
+ static createFromStorage(storage: Storage, key: string): Promise<InputByteBuffer>;
49
+ /**
50
+ * Reads a 8-bit unsigned integer from the buffer.
51
+ *
52
+ * @returns 8-bit unsigned integer from the buffer.
53
+ */
54
+ readUint8(): number;
55
+ /**
56
+ * Reads a 16-bit unsigned integer from the buffer.
57
+ *
58
+ * @returns 16-bit unsigned integer from the buffer.
59
+ */
60
+ readUint16(): number;
61
+ /**
62
+ * Reads a 32-bit unsigned integer from the buffer at the specified index.
63
+ *
64
+ * @param index Index to read the 32-bit unsigned integer from.
65
+ *
66
+ * @returns 32-bit unsigned integer from the buffer.
67
+ */
68
+ private readUint32FromIndex;
69
+ /**
70
+ * Reads a 32-bit unsigned integer from the buffer.
71
+ *
72
+ * @returns 32-bit unsigned integer from the buffer.
73
+ */
74
+ readUint32(): number;
75
+ /**
76
+ * Reads schema version from the buffer.
77
+ *
78
+ * @returns 32-bit unsigned integer from the buffer.
79
+ * @note Schema version is always stored at the beginning of the buffer.
80
+ */
81
+ readSchemaVersion(): number;
82
+ /**
83
+ * Reads a 32-bit signed integer from the buffer.
84
+ *
85
+ * @returns 32-bit signed integer from the buffer.
86
+ */
87
+ readInt32(): number;
88
+ /**
89
+ * Reads an optimized unsigned integer from the buffer.
90
+ * 'Optimized' means that the integer is stored in a variable number of bytes, depending on its value,
91
+ * so that smaller numbers occupy less space.
92
+ *
93
+ * @returns Decoded unsigned integer from the buffer.
94
+ */
95
+ readOptimizedUint(): number;
96
+ /**
97
+ * Reads a string from the buffer.
98
+ *
99
+ * @returns Decoded string from the buffer.
100
+ */
101
+ readString(): string;
102
+ /**
103
+ * Reads a 8-bit unsigned integer from the buffer without advancing the offset.
104
+ *
105
+ * @returns 8-bit unsigned integer from the buffer.
106
+ */
107
+ peekUint8(): number;
108
+ /**
109
+ * Helper method for asserting the next 8-bit unsigned integer in the buffer.
110
+ *
111
+ * @param value Expected value.
112
+ * @throws If the next value in the buffer is not equal to the expected value.
113
+ */
114
+ assertUint8(value: number): void;
115
+ /**
116
+ * Creates a new `InputByteBuffer` instance with the given initial offset.
117
+ *
118
+ * @param initialOffset Initial offset for the new buffer.
119
+ * @param cloneChunks Flag indicating if the chunks should be cloned. For performance reasons,
120
+ * its default value is `false`. If the original chunks are guaranteed not to change,
121
+ * leave this flag as `false` to avoid unnecessary copying.
122
+ *
123
+ * @returns New `InputByteBuffer` instance with the given initial offset.
124
+ *
125
+ * @note This method is useful if you want to read some data from a specific index.
126
+ */
127
+ createCopyWithOffset(initialOffset: number, cloneChunks?: boolean): InputByteBuffer;
128
+ /**
129
+ * Gets the current offset in the buffer for reading.
130
+ *
131
+ * @returns Current offset in the buffer for reading.
132
+ */
133
+ get currentOffset(): number;
134
+ /**
135
+ * Gets the capacity of the buffer.
136
+ *
137
+ * @returns Capacity of the buffer.
138
+ */
139
+ get capacity(): number;
140
+ /**
141
+ * Gets the chunks of the buffer.
142
+ *
143
+ * @returns Chunks of the buffer.
144
+ */
145
+ getChunks(): Uint8Array[];
146
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * A simple function to check if the current browser is Chromium-based.
3
+ *
4
+ * @returns `true` if the current browser is Chromium-based, `false` otherwise.
5
+ * @see {@link https://stackoverflow.com/a/62797156}
6
+ */
7
+ export declare const isChromium: () => boolean;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @file Utility functions for logical expression node.
3
+ */
4
+ import { type AnyExpressionNode, type ExpressionVariableNode } from '../nodes';
5
+ /**
6
+ * Variable table. Key is variable name, value is boolean.
7
+ */
8
+ export type VariableTable = {
9
+ [key: string]: boolean;
10
+ };
11
+ /**
12
+ * Utility functions for logical expression node.
13
+ */
14
+ export declare class LogicalExpressionUtils {
15
+ /**
16
+ * Get all variables in the expression.
17
+ *
18
+ * @param node Logical expression node
19
+ * @returns List of variables in the expression (nodes)
20
+ * @example
21
+ * If the expression is `a && b || c`, the returned list will be
22
+ * nodes for `a`, `b`, and `c`.
23
+ */
24
+ static getVariables(node: AnyExpressionNode): ExpressionVariableNode[];
25
+ /**
26
+ * Evaluate the parsed logical expression. You'll need to provide a
27
+ * variable table.
28
+ *
29
+ * @param node Logical expression node
30
+ * @param table Variable table (key: variable name, value: boolean)
31
+ * @returns Evaluation result
32
+ * @example
33
+ * If the expression is `a && b`, and the variable table is
34
+ * `{ a: true, b: false }`, the result will be `false`.
35
+ *
36
+ * Example code:
37
+ * ```js
38
+ * LogicalExpressionUtils.evaluate(
39
+ * LogicalExpressionParser.parse('a && b'),
40
+ * { a: true, b: false }
41
+ * );
42
+ * ```
43
+ */
44
+ static evaluate(node: AnyExpressionNode, table: VariableTable): boolean;
45
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * A very simple map extension that allows to store multiple values for the same key
3
+ * by storing them in an array.
4
+ *
5
+ * @todo Add more methods if needed
6
+ */
7
+ export declare class MultiValueMap<K, V> extends Map<K, V[]> {
8
+ /**
9
+ * Adds a value to the map. If the key already exists, the value will be appended to the existing array,
10
+ * otherwise a new array will be created for the key.
11
+ *
12
+ * @param key Key to add
13
+ * @param values Value(s) to add
14
+ */
15
+ add(key: K, ...values: V[]): void;
16
+ }
@@ -0,0 +1,132 @@
1
+ import { ByteBuffer } from './byte-buffer';
2
+ import { type Storage } from './storage-interface';
3
+ /**
4
+ * Output byte buffer for writing binary data.
5
+ *
6
+ * @note Internally, this class uses a {@link ByteBuffer} instance, just providing a convenient API for reading data.
7
+ */
8
+ export declare class OutputByteBuffer extends ByteBuffer {
9
+ /**
10
+ * Current offset in the buffer for writing.
11
+ */
12
+ private offset;
13
+ /**
14
+ * Size of the shared buffer for encoding strings in bytes.
15
+ * This is a divisor of ByteBuffer.CHUNK_SIZE and experience shows that this value works optimally.
16
+ * This is sufficient for most strings that occur in filter lists (we checked average string length in popular
17
+ * filter lists).
18
+ */
19
+ private static readonly ENCODER_BUFFER_SIZE;
20
+ /**
21
+ * Length threshold for using a shared buffer for encoding strings.
22
+ * This temp buffer is needed because we write the short strings in it
23
+ * (so there is no need to constantly allocate a new buffer).
24
+ * The reason for dividing ENCODER_BUFFER_SIZE by 4 is to ensure that the encoded string fits in the buffer,
25
+ * if we also take into account the worst possible case (each character is encoded with 4 bytes).
26
+ */
27
+ private static readonly SHORT_STRING_THRESHOLD;
28
+ /**
29
+ * Represents the maximum value that can be written as a 'storage optimized' unsigned integer.
30
+ * 0x1FFFFFFF means 29 bits — 32 bits minus 3 bits — because the last bit in each byte is a flag indicating
31
+ * if there are more bytes (except for the last byte).
32
+ */
33
+ static MAX_OPTIMIZED_UINT: number;
34
+ /**
35
+ * Shared buffer for encoding strings.
36
+ */
37
+ private readonly sharedBuffer;
38
+ /**
39
+ * Shared native encoder for encoding strings.
40
+ */
41
+ private readonly sharedNativeEncoder;
42
+ /**
43
+ * Flag indicating if the current environment is Chromium.
44
+ * This is used for performance optimizations, because Chromium's TextEncoder/TextDecoder has a relatively
45
+ * large marshalling overhead for small strings.
46
+ */
47
+ private readonly isChromium;
48
+ /**
49
+ * Constructs a new OutputByteBuffer instance.
50
+ */
51
+ constructor();
52
+ /**
53
+ * Writes a 8-bit unsigned integer to the buffer.
54
+ *
55
+ * @param value Value to write.
56
+ * @returns Number of bytes written to the buffer.
57
+ */
58
+ writeUint8(value: number): number;
59
+ /**
60
+ * Writes a 16-bit unsigned integer to the buffer.
61
+ *
62
+ * @param value Value to write.
63
+ * @returns Number of bytes written to the buffer.
64
+ */
65
+ writeUint16(value: number): number;
66
+ /**
67
+ * Writes a 32-bit unsigned integer to the buffer at a specific index.
68
+ *
69
+ * @param value Value to write.
70
+ * @param index Index to write the value to.
71
+ * @returns Number of bytes written to the buffer.
72
+ */
73
+ private writeUint32ToIndex;
74
+ /**
75
+ * Writes a 32-bit unsigned integer to the buffer.
76
+ *
77
+ * @param value Value to write.
78
+ * @returns Number of bytes written to the buffer.
79
+ */
80
+ writeUint32(value: number): number;
81
+ /**
82
+ * Writes a 32-bit signed integer to the buffer.
83
+ *
84
+ * @param value Value to write.
85
+ * @returns Number of bytes written to the buffer.
86
+ */
87
+ writeInt32(value: number): number;
88
+ /**
89
+ * Writes a Uint8Array to the byte buffer.
90
+ *
91
+ * @param buffer Buffer to write.
92
+ */
93
+ private writeBuffer;
94
+ /**
95
+ * Writes a string to the buffer.
96
+ *
97
+ * @param value Value to write.
98
+ * @returns Number of bytes written to the buffer.
99
+ */
100
+ writeString(value: string): number;
101
+ /**
102
+ * Writes chunks to the storage.
103
+ *
104
+ * @param storage Storage to write the chunks to.
105
+ * @param key Key to write the chunks to.
106
+ * @note For performance reasons, chunks are passed by reference and not copied.
107
+ * @throws If the storage write operation throws.
108
+ */
109
+ writeChunksToStorage(storage: Storage, key: string): Promise<void>;
110
+ /**
111
+ * Writes an 'optimized' unsigned integer to the buffer.
112
+ * 'Optimized' means smaller storage usage for smaller numbers.
113
+ * Except for the last byte, each byte's most significant bit is a flag indicating if there are more bytes.
114
+ *
115
+ * @param value Value to write.
116
+ * @returns Number of bytes written to the buffer.
117
+ * @throws If the value exceeds the 29-bit limit.
118
+ */
119
+ writeOptimizedUint(value: number): number;
120
+ /**
121
+ * Gets the current offset in the buffer for writing.
122
+ *
123
+ * @returns Current offset in the buffer for writing.
124
+ */
125
+ get currentOffset(): number;
126
+ /**
127
+ * Gets the chunks of the buffer.
128
+ *
129
+ * @returns Chunks of the buffer.
130
+ */
131
+ getChunks(): Uint8Array[];
132
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @file Position provider class.
3
+ */
4
+ /**
5
+ * Represents a position in the source code.
6
+ */
7
+ export interface Position {
8
+ /**
9
+ * 1-based line number
10
+ */
11
+ line: number;
12
+ /**
13
+ * 1-based column number
14
+ */
15
+ column: number;
16
+ }
17
+ /**
18
+ * Class responsible for converting a character offset in source code into a line and column position.
19
+ * This conversion is particularly needed in linters and VSCode extensions,
20
+ * where line and column numbers are more human-friendly and intuitive than character offsets.
21
+ * Moreover, the VSCode diagnostics API does not directly support character offsets,
22
+ * it also requires line and column numbers.
23
+ */
24
+ export declare class PositionProvider {
25
+ /**
26
+ * Maps a character offset to a line number.
27
+ */
28
+ private offsetToLine;
29
+ /**
30
+ * Maps a line number to the starting character offset of that line.
31
+ */
32
+ private lineStartOffsets;
33
+ /**
34
+ * Constructs a new PositionProvider instance.
35
+ *
36
+ * @param sourceCode The source code as a string.
37
+ */
38
+ constructor(sourceCode: string);
39
+ /**
40
+ * Converts a character offset to a line and column position.
41
+ *
42
+ * @param offset The zero-based character offset in the source code.
43
+ * @returns A Position object containing the 1-based line and column number, or null if the offset is out of range.
44
+ */
45
+ convertOffsetToPosition(offset: number): Position | null;
46
+ }
@@ -0,0 +1,94 @@
1
+ /**
2
+ * @file Utility functions for working with quotes
3
+ */
4
+ /**
5
+ * Set of all possible quote characters supported by the library
6
+ */
7
+ export declare const QUOTE_SET: Set<string>;
8
+ /**
9
+ * Possible quote types for scriptlet parameters
10
+ */
11
+ export declare const QuoteType: {
12
+ /**
13
+ * No quotes at all
14
+ */
15
+ readonly None: "none";
16
+ /**
17
+ * Single quotes (`'`)
18
+ */
19
+ readonly Single: "single";
20
+ /**
21
+ * Double quotes (`"`)
22
+ */
23
+ readonly Double: "double";
24
+ /**
25
+ * Backtick quotes (`` ` ``)
26
+ */
27
+ readonly Backtick: "backtick";
28
+ };
29
+ export type QuoteType = typeof QuoteType[keyof typeof QuoteType];
30
+ /**
31
+ * Utility functions for working with quotes
32
+ */
33
+ export declare class QuoteUtils {
34
+ /**
35
+ * Escape all unescaped occurrences of the character
36
+ *
37
+ * @param string String to escape
38
+ * @param char Character to escape
39
+ * @returns Escaped string
40
+ */
41
+ static escapeUnescapedOccurrences(string: string, char: string): string;
42
+ /**
43
+ * Unescape all single escaped occurrences of the character
44
+ *
45
+ * @param string String to unescape
46
+ * @param char Character to unescape
47
+ * @returns Unescaped string
48
+ */
49
+ static unescapeSingleEscapedOccurrences(string: string, char: string): string;
50
+ /**
51
+ * Get quote type of the string
52
+ *
53
+ * @param string String to check
54
+ * @returns Quote type of the string
55
+ */
56
+ static getStringQuoteType(string: string): QuoteType;
57
+ /**
58
+ * Set quote type of the string
59
+ *
60
+ * @param string String to set quote type of
61
+ * @param quoteType Quote type to set
62
+ * @returns String with the specified quote type
63
+ */
64
+ static setStringQuoteType(string: string, quoteType: QuoteType): string;
65
+ /**
66
+ * Removes bounding quotes from a string, if any
67
+ *
68
+ * @param string Input string
69
+ * @returns String without quotes
70
+ */
71
+ static removeQuotes(string: string): string;
72
+ /**
73
+ * Removes bounding quotes from a string, if any, and unescapes the escaped quotes,
74
+ * like transforming `'abc\'def'` to `abc'def`.
75
+ *
76
+ * @param string Input string
77
+ * @returns String without quotes
78
+ */
79
+ static removeQuotesAndUnescape(string: string): string;
80
+ /**
81
+ * Wraps given `strings` with `quote` (defaults to single quote `'`)
82
+ * and joins them with `separator` (defaults to comma+space `, `).
83
+ *
84
+ * @param strings Strings to quote and join.
85
+ * @param quoteType Quote to use.
86
+ * @param separator Separator to use.
87
+ *
88
+ * @returns String with joined items.
89
+ *
90
+ * @example
91
+ * ['abc', 'def']: strings[] -> "'abc', 'def'": string
92
+ */
93
+ static quoteAndJoinStrings(strings: string[], quoteType?: QuoteType, separator?: string): string;
94
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @file Regular expression utilities
3
+ */
4
+ export declare const REGEX_START = "^";
5
+ export declare const REGEX_END = "$";
6
+ export declare const REGEX_ANY_CHARACTERS: string;
7
+ export declare const ADBLOCK_URL_START: string;
8
+ export declare const ADBLOCK_URL_START_REGEX = "^(http|https|ws|wss)://([a-z0-9-_.]+\\.)?";
9
+ export declare const ADBLOCK_URL_SEPARATOR = "^";
10
+ export declare const ADBLOCK_URL_SEPARATOR_REGEX = "([^ a-zA-Z0-9.%_-]|$)";
11
+ export declare const ADBLOCK_WILDCARD = "*";
12
+ export declare const ADBLOCK_WILDCARD_REGEX: string;
13
+ export declare const REGEX_NEGATION_PREFIX = "^((?!";
14
+ export declare const REGEX_NEGATION_SUFFIX = ").)*$";
15
+ /**
16
+ * Special RegExp symbols
17
+ *
18
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#special-escape
19
+ */
20
+ export declare const SPECIAL_REGEX_SYMBOLS: Set<string>;
21
+ /**
22
+ * Utility functions for working with RegExp patterns
23
+ */
24
+ export declare class RegExpUtils {
25
+ /**
26
+ * Checks whether a string possibly is a RegExp pattern.
27
+ * Flags are not supported.
28
+ *
29
+ * Note: it does not perform a full validation of the pattern,
30
+ * it just checks if the string starts and ends with a slash.
31
+ *
32
+ * @param pattern - Pattern to check
33
+ * @returns `true` if the string is a RegExp pattern, `false` otherwise
34
+ */
35
+ static isRegexPattern(pattern: string): boolean;
36
+ /**
37
+ * Negates a RegExp pattern. Technically, this method wraps the pattern in `^((?!` and `).)*$`.
38
+ *
39
+ * RegExp modifiers are not supported.
40
+ *
41
+ * @param pattern Pattern to negate (can be wrapped in slashes or not)
42
+ * @returns Negated RegExp pattern
43
+ */
44
+ static negateRegexPattern(pattern: string): string;
45
+ /**
46
+ * Converts a basic adblock rule pattern to a RegExp pattern. Based on
47
+ * https://github.com/AdguardTeam/tsurlfilter/blob/9b26e0b4a0e30b87690bc60f7cf377d112c3085c/packages/tsurlfilter/src/rules/simple-regex.ts#L219
48
+ *
49
+ * @param pattern Pattern to convert
50
+ * @returns RegExp equivalent of the pattern
51
+ * @see {@link https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#basic-rules}
52
+ */
53
+ static patternToRegexp(pattern: string): string;
54
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @file Represents a storage interface for reading and writing data.
3
+ */
4
+ /**
5
+ * Represents a storage interface for reading and writing data.
6
+ */
7
+ export interface Storage<K = string, V = unknown> {
8
+ /**
9
+ * Writes the given data to the storage with the specified key.
10
+ *
11
+ * @param key The key to identify the data in the storage.
12
+ * @param chunks The data to write to the storage.
13
+ * @returns A promise that resolves when the write operation is complete.
14
+ */
15
+ set(key: K, data: V): Promise<void>;
16
+ /**
17
+ * Reads the data from the storage with the specified key.
18
+ *
19
+ * @param key The key to identify the data in the storage.
20
+ * @returns A promise that resolves with the data read from the storage.
21
+ */
22
+ get(key: K): Promise<V | undefined>;
23
+ }