https://github.com/colgatto/Poliparser
The only parser you need
https://github.com/colgatto/Poliparser
css-selector dom dom-parser parser regex text-parsing
Last synced: about 1 year ago
JSON representation
The only parser you need
- Host: GitHub
- URL: https://github.com/colgatto/Poliparser
- Owner: colgatto
- License: other
- Created: 2019-10-06T20:32:51.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-03T07:43:00.000Z (over 3 years ago)
- Last Synced: 2025-03-12T04:23:40.552Z (over 1 year ago)
- Topics: css-selector, dom, dom-parser, parser, regex, text-parsing
- Language: JavaScript
- Size: 263 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

[](https://travis-ci.org/colgatto/Poliparser)
[](https://coveralls.io/github/colgatto/Poliparser?branch=master)

[](https://github.com/colgatto/RWTFPL)

[](https://www.npmjs.com/package/poliparser)
Poliparse is used to extract and parse data from strings, files, urls and many other objects in a simple and fast way.
The Default modules allows you to parse:
- String
- Array
- Object
- DOM Elements
- JSON
- CSV
- Hash & Chipertext
You can use the default modules or easily add your custom one ( see all the modules on the [Examples](https://github.com/colgatto/Poliparser/tree/master/Examples) page ).
## **Install**
```
npm install --save poliparser
```
## **Usage**
Import and Instantiate Poliparser
```js
const Poliparser = require('poliparser');
let p = new Poliparser();
```
set a parser template,
In this example is used the module `between` from `str` library.
```js
p.setParser({
m: 'str_between',
from: '',
to: ''
});
```
```js
let data = `hello
`;
let output = p.parse(data);
console.log(output);
```
**output**
```js
hello
```
---
>ps. The fastest way is to pass it in the declaration like this
```js
let p = new Poliparser({
m: 'between',
from: '',
to: ''
});
```
## **[Documentation](https://github.com/colgatto/Poliparser/tree/master/docgen#documentation)**
**See [Here](https://github.com/colgatto/Poliparser/tree/master/docgen#documentation) for complete modules documentation and [Here](https://github.com/colgatto/Poliparser/tree/master/Examples#real-world-examples) for real world examples.**
### Add Module
You can use `setModule()` and `requireModule()` to add custom modules.
```js
let p = new Poliparser();
p.setModule('my_parse_module', (data, block) => {
return data.map(x => x * block.value);
});
p.setParser({
m: 'my_parse_module',
value: 3
});
let out = p.parse([1,2,3]);
console.log(out);
```
same as
```js
let p = new Poliparser();
p.requireModule('my_parse_module', 'myModule.js');
p.setParser({
m: 'my_parse_module',
value: 3
});
let out = p.parse([1,2,3]);
console.log(out);
```
```js
//myModule.js
module.exports = (data, block) => {
return data.map(x => x * block.value);
};
```
**output**
```js
[ 3, 6, 9 ]
```
### Add Library
You can add a new library with the setLibrary or requireLibrary method.
```js
let p = new Poliparser();
p.setLibrary('myLib', {
mul: (data, block) => {
return data * block.value;
},
sum: (data, block) => {
return data + block.value;
}
});
p.setParser([{
m: 'myLib_mul',
value: 3
},{
m: 'myLib_sum',
value: 2
}]);
let out = p.parse(10);
console.log(out);
```
same as
```js
let p = new Poliparser();
p.requireLibrary('myLib', 'myLib.js');
p.setParser([{
m: 'myLib_mul',
value: 3
},{
m: 'myLib_sum',
value: 2
]);
let out = p.parse(10);
console.log(out);
```
```js
//myLib.js
module.exports = {
mul: (data, block) => {
return data * block.value;
},
sum: (data, block) => {
return data + block.value;
}
}
```
**output**
```js
32
```