Skip to content

Commit 83aa91b

Browse files
committed
AG-29054 Improved docs for json-prune, xml-prune and trusted-prune-inbound-object scriptlets
Squashed commit of the following: commit d381656 Author: jellizaveta <[email protected]> Date: Thu Apr 3 18:21:37 2025 +0300 fix indents commit 95654d7 Author: jellizaveta <[email protected]> Date: Thu Apr 3 17:57:08 2025 +0300 AG-29054 Improved docs for , and scriptlets
1 parent 8c03456 commit 83aa91b

File tree

4 files changed

+399
-15
lines changed

4 files changed

+399
-15
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic
1010
<!-- TODO: change `@added unknown` tag due to the actual version -->
1111
<!-- during new scriptlets or redirects releasing -->
1212

13+
## [Unreleased]
14+
15+
### Changed
16+
17+
- Improved docs for `json-prune`, `xml-prune` and `trusted-prune-inbound-object` scriptlets [#392]
18+
19+
[#392]: https://github.com/AdguardTeam/Scriptlets/issues/392
20+
[Unreleased]: https://github.com/AdguardTeam/Scriptlets/compare/v2.1.7...HEAD
21+
1322
## [v2.1.7] - 2025-04-03
1423

1524
### Changed

src/scriptlets/json-prune.js

+201-5
Original file line numberDiff line numberDiff line change
@@ -51,67 +51,263 @@ import {
5151
* example.org#%#//scriptlet('json-prune', 'example')
5252
* ```
5353
*
54-
* For instance, the following call will return `{ one: 1}`
54+
* JSON.parse call:
5555
*
5656
* ```html
5757
* JSON.parse('{"one":1,"example":true}')
5858
* ```
5959
*
60+
* Input JSON:
61+
*
62+
* ```json
63+
* {
64+
* "one": 1,
65+
* "example": true
66+
* }
67+
* ```
68+
*
69+
* Output:
70+
*
71+
* ```json
72+
* {
73+
* "one": 1
74+
* }
75+
* ```
76+
*
6077
* 1. If there are no specified properties in the result of JSON.parse call, pruning will NOT occur
6178
*
6279
* ```adblock
6380
* example.org#%#//scriptlet('json-prune', 'one', 'obligatoryProp')
6481
* ```
6582
*
66-
* For instance, the following call will return `{ one: 1, two: 2}`
83+
* JSON.parse call:
6784
*
6885
* ```html
6986
* JSON.parse('{"one":1,"two":2}')
7087
* ```
7188
*
89+
* Input JSON:
90+
*
91+
* ```json
92+
* {
93+
* "one": 1,
94+
* "two": 2
95+
* }
96+
* ```
97+
*
98+
* Output:
99+
*
100+
* ```json
101+
* {
102+
* "one": 1,
103+
* "two": 2
104+
* }
105+
* ```
106+
*
72107
* 1. A property in a list of properties can be a chain of properties
73108
*
74109
* ```adblock
75110
* example.org#%#//scriptlet('json-prune', 'a.b', 'ads.url.first')
76111
* ```
77112
*
113+
* JSON.parse call:
114+
*
115+
* ```html
116+
* JSON.parse('{"a":{"b":123},"ads":{"url":{"first":"abc"}}}')
117+
* ```
118+
*
119+
* Input JSON:
120+
*
121+
* ```json
122+
* {
123+
* "a": {
124+
* "b": 123
125+
* },
126+
* "ads": {
127+
* "url": {
128+
* "first": "abc"
129+
* }
130+
* }
131+
* }
132+
* ```
133+
*
134+
* Output:
135+
*
136+
* ```json
137+
* {
138+
* "a": {},
139+
* "ads": {
140+
* "url": {
141+
* "first": "abc"
142+
* }
143+
* }
144+
* }
145+
* ```
146+
*
78147
* 1. Removes property `content.ad` from the results of JSON.parse call if its error stack trace contains `test.js`
79148
*
80149
* ```adblock
81150
* example.org#%#//scriptlet('json-prune', 'content.ad', '', 'test.js')
82151
* ```
83152
*
153+
* JSON.parse call:
154+
*
155+
* ```html
156+
* JSON.parse('{"content":{"ad":{"src":"a.js"}}}')
157+
* ```
158+
*
159+
* Input JSON:
160+
*
161+
* ```json
162+
* {
163+
* "content": {
164+
* "ad": {
165+
* "src": "a.js"
166+
* }
167+
* }
168+
* }
169+
* ```
170+
*
171+
* Output:
172+
*
173+
* ```json
174+
* {
175+
* "content": {}
176+
* }
177+
* ```
178+
*
84179
* 1. A property in a list of properties can be a chain of properties with wildcard in it
85180
*
86181
* ```adblock
87182
* example.org#%#//scriptlet('json-prune', 'content.*.media.src', 'content.*.media.ad')
88183
* ```
89184
*
185+
* JSON.parse call:
186+
*
187+
* ```html
188+
* JSON.parse('{"content":{"block1":{"media":{"src":"1.jpg","ad":true}},"block2":{"media":{"src":"2.jpg"}}}}')
189+
* ```
190+
*
191+
* Input JSON:
192+
*
193+
* ```json
194+
* {
195+
* "content": {
196+
* "block1": {
197+
* "media": {
198+
* "src": "1.jpg",
199+
* "ad": true
200+
* }
201+
* },
202+
* "block2": {
203+
* "media": {
204+
* "src": "2.jpg"
205+
* }
206+
* }
207+
* }
208+
* }
209+
* ```
210+
*
211+
* Output:
212+
*
213+
* ```json
214+
* {
215+
* "content": {
216+
* "block1": {
217+
* "media": {
218+
* "ad": true
219+
* }
220+
* },
221+
* "block2": {
222+
* "media": {}
223+
* }
224+
* }
225+
* }
226+
* ```
227+
*
90228
* 1. Removes every property from `videos` object if it has `isAd` key
91229
*
92230
* ```adblock
93231
* example.org#%#//scriptlet('json-prune', 'videos.{-}.isAd')
94232
* ```
95233
*
96-
* For instance, the following call will return `{ videos: { video2: { src: 'video1.mp4' } } }`
234+
* JSON.parse call:
97235
*
98236
* ```html
99237
* JSON.parse('{"videos":{"video1":{"isAd":true,"src":"video1.mp4"},"video2":{"src":"video1.mp4"}}}')
100238
* ```
101239
*
240+
* Input JSON:
241+
*
242+
* ```json
243+
* {
244+
* "videos": {
245+
* "video1": {
246+
* "isAd": true,
247+
* "src": "video1.mp4"
248+
* },
249+
* "video2": {
250+
* "src": "video1.mp4"
251+
* }
252+
* }
253+
* }
254+
* ```
255+
*
256+
* Output:
257+
*
258+
* ```json
259+
* {
260+
* "videos": {
261+
* "video2": {
262+
* "src": "video1.mp4"
263+
* }
264+
* }
265+
* }
266+
* ```
267+
*
102268
* 1. Removes every property from `videos` object if it has `isAd` key with `true` value
103269
*
104270
* ```adblock
105271
* example.org#%#//scriptlet('json-prune', 'videos.{-}.isAd.[=].true')
106272
* ```
107273
*
108-
* For instance, the following call will return `{ videos: { video2: { isAd: false, src: 'video1.mp4' } } }`
274+
* JSON.parse call:
109275
*
110276
* ```html
111277
* JSON.parse('{"videos":{"video1":{"isAd":true,"src":"video1.mp4"},"video2":{"isAd":false,"src":"video1.mp4"}}}')
112278
* ```
113279
*
114-
* 1. Call with no arguments will log the current hostname and json payload at the console
280+
* Input JSON:
281+
*
282+
* ```json
283+
* {
284+
* "videos": {
285+
* "video1": {
286+
* "isAd": true,
287+
* "src": "video1.mp4"
288+
* },
289+
* "video2": {
290+
* "isAd": false,
291+
* "src": "video1.mp4"
292+
* }
293+
* }
294+
* }
295+
* ```
296+
*
297+
* Output:
298+
*
299+
* ```json
300+
* {
301+
* "videos": {
302+
* "video2": {
303+
* "isAd": false,
304+
* "src": "video1.mp4"
305+
* }
306+
* }
307+
* }
308+
* ```
309+
*
310+
* 1. Call with no arguments will log the current hostname and JSON payload at the console
115311
*
116312
* ```adblock
117313
* example.org#%#//scriptlet('json-prune')

0 commit comments

Comments
 (0)