Skip to content

Commit

Permalink
Merge pull request #82 in ADGUARD-FILTERS/scriptlets from feature/66 …
Browse files Browse the repository at this point in the history
…to master

* commit 'a4baba50327fad7fe03a174d345001bcbe9d0ad3':
  delete comments
  edit readme
  fix building of scriptlets as cjs module
  slightly fix rollup
  add scriptlets as a cjs module
  refix gitignore
  get redirects.js back
  add convertAdgToUbo method and few tests for it
  make convert methods return array
  fix convertAbpToAdg, delete comments, up version
  add convertion (to adg), parsing and rule validation methods
  edit scriptlets validation method description
  fix scriptlet validation method in order to get 'name' as a string
  add validate interface for scriptlets
  • Loading branch information
slavaleleka committed Jan 30, 2020
2 parents 396bed7 + a4baba5 commit 44b01e3
Show file tree
Hide file tree
Showing 17 changed files with 4,532 additions and 115 deletions.
74 changes: 69 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,82 @@ yarn browserstack

#### Scriptlets library

`dist/scriptlets.js`
Finally we have build Scriptlets as a CJS module which can be imported from `dist/cjs/scriptlets.js`.

Creates a global variable `scriptlets`.
And also there is a module at `dist/scriptlets.js` which has been exported to a global variable `scriptlets` with such methods:

```javascript
/**
* Returns scriptlet code
*
* @param {Source} source
* @returns {string}
* @returns {String}
*/
scriptlets.invoke(source)
scriptlets.invoke(source);
```

```javascript
/**
* Checks if the scriptlet name is valid
* @param {String} name - scriptlet name
* @returns {Boolean}
*/
scriptlets.validateName(name);
```

```javascript
/**
* Validates any scriptlet rule
* @param {String} input - can be Adguard or Ubo or Abp scriptlet rule
* @returns {Boolean}
*/
scriptlets.validateRule(input);
```

```javascript
/**
* Checks is AdGuard / Ubo / Abp scriptlet rule
* @param {String} rule - rule text
* @returns {Boolean}
*/
scriptlets.isAdgScriptletRule(rule);
scriptlets.isAdgScriptletRule(rule);
scriptlets.isAdgScriptletRule(rule);
```

```javascript
/**
* Converts Ubo scriptlet rule to AdGuard
* @param {String} rule - rule text
* @returns {Array} - array with one item - AdGuard scriptlet rule
*/
scriptlets.convertUboToAdg(rule);
```

```javascript
/**
* Converts Abp snippet rule to AdGuard
* @param {String} rule - rule text
* @returns {Array} - array with AdGuard scriptlet rule or rules if Abp-rule has few snippets in one line
*/
scriptlets.convertAbpToAdg(rule);
```

```javascript
/**
* Checks is any scriptlet rule and converts to AdGuard
* @param {String} rule - rule text
* @returns {Array} - array of AdGuard scriptlet rule - one item for Adg and Ubo or few items for Abp
*/
scriptlets.convertScriptletToAdg(rule);
```

```javascript
/**
* Converts UBO scriptlet rule to AdGuard one
* @param {String} rule - AdGuard scriptlet rule
* @returns {String} - UBO scriptlet rule
*/
scriptlets.convertAdgToUbo(rule);
```

#### Corelibs library
Expand Down
Loading

0 comments on commit 44b01e3

Please sign in to comment.