Skip to content

Commit 916749a

Browse files
Improve documentation (mainly on regex options).
1 parent 6656abf commit 916749a

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

README.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ console.log(information.part); // 1
4747
If you want to keep only a part of the matched regular expression, you should use capturing groups
4848
[explained here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp).
4949

50+
For regular expressions, the following options are available:
51+
52+
* `skipIfAlreadyFound` (default to `true`) which will skip the regular expression if a previous handler for the same
53+
information already found something.
54+
* `type` (default to `string`)which indicates what is the expected output of the regular expression.
55+
It can be:
56+
* `string`: does nothing
57+
* `integer`: convert the matching part into an integer
58+
* `lowercase`: convert the matching part to lowercase
59+
* `boolean`: convert to true if there is a matching part
60+
5061
### Handlers
5162

5263
A handler is a function with the title and the resulting information as parameters.
@@ -72,17 +83,18 @@ console.log(information2.isHarryPotterRelated); // true
7283
## Multiple parsers
7384

7485
You may want several different parsers within the same project.
75-
To do that, you can create new parsers simply:
86+
To do that, you can simply create new parsers:
7687
```javascript
77-
const Parser = require("parse-torrent-title").Parser;
88+
const { Parser } = require("parse-torrent-title");
7889
const parser = new Parser();
7990
const anotherParser = new Parser();
8091
```
8192

93+
By default, a freshly created parser has no handler.
8294
If you want to add default handlers to a parser, you can do so using the specific method:
8395
```javascript
84-
const ptt = require("parse-torrent-title");
85-
const parser = new ptt.Parser();
86-
ptt.addDefaults(parser); // parser is now ready
96+
const { Parser, addDefaults } = require("parse-torrent-title");
97+
const parser = new Parser();
98+
addDefaults(parser); // parser is now ready
8799
```
88100

0 commit comments

Comments
 (0)