Thought we should have a text processing genie which can extract results, from the way we tell to another human.
This can be used to remove the clutter code from string processing like index variables, split arrays from actual code.
It knows the context of query which can be useful to store all index related variables.
npm install text-parser-genie --save
var TextParserGenie = require('text-parser-genie');
var parseOptions = {'file': './sometext.txt', 'wordDelimitter': ' '};
var query = [ {
'lineNumber': 2,
'subString': {
'startIndex': 0,
'endIndex': {
'indexOf': 'PROVIDER'
}
}
} ];
TextParserGenie(parseOptions)
.parse( query, function(err, results, exceptions){
if (err) {
console.error(err);
return;
}
if (exceptions) {
console.warn(exceptions);
}
console.log(results);
}
);
Data:
TOTAL SOMEHEADER OTHERONE CHECK
12 15 27
Query:
{
'section' : 'TOTAL',
'header': 'CHECK',
'offset': '1'
}
Result:
{
'section' : 'TOTAL',
'header': 'CHECK',
'offset': '1',
'result': '27'
}
Data:
This is the first line
And this is the sample second line
Query:
{
'lineNumber' : 2
'wordNumber' : 5
}
Result:
{
'lineNumber' : 2
'wordNumber' : 5
'result' : 'sample'
}
Data:
This is the first line
And this is the sample second line
Query:
{
'lineNumber': 2,
'subString': {
'startIndex': 0,
'endIndex': {
'indexOf': 'sample'
}
}
}
Result:
{
'lineNumber': 2,
'subString': {
'startIndex': 0,
'endIndex': {
'indexOf': 'sample'
'result': 17
}
'result': 'And this is the'
}
'result': 'And this is the'
}
Data:
This is some text Report No : 12587456
This is some text too
Query:
{
'field': 'Report No'
}
Result:
{
'field': 'Report No',
'result': '12587456'
}