1.6.0 • Published 6 years ago

parser-template v1.6.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

Parser

"Parser" is a tool designed for extracting data from plain text files.

Usage

Let's say, we have some template filled with values:

Hello, mr. Doe. How are you?

The only changable part of this template is a Name and we need to parse it. We may describe this template:

Hello, mr. <><name>. How are you?

The rest is easy:

const PARSER = require ('parser-template');
const myParser = new PARSER ('Hello, mr. <><name>. How are you?');
const data = myParser.parse (inputString)[0];
// data = {name: 'Doe'}

.

Advanced usage

Parser can process an array of templates without additional params:

Hello, mr. Doe. How are you?
Hello, mr. John. How are you?
Hello, mr. Bill. How are you?
//...
const myParser = new PARSER ('Hello, mr. <><name>. How are you?');
const data = myParser.parse (inputString);
// data = [{name: 'Doe'}, {name: 'John'}, {name: 'Bill'}]

A template may contain several multi-line fields. They are marked by symbol 'm' in the opening part of a tag:

Hello, <><name>.
This is that I think about you:
<m><text>

It's also possible to insert your data into a template string using myParser.stringify (dataObject).

Additional functions

Parser is shipped with several handy functions:

1) removeDuplicates (arr) 2) prettifyList (string) 3) getRegexCaptures (string, regex, callback) 4) stringifyVal (val) 5) filterObject (dataObject)

An info about them will be written in future.

1.6.0

6 years ago

1.5.2

6 years ago

1.5.1

6 years ago

1.5.0

6 years ago

1.4.1

6 years ago

1.4.0

6 years ago

1.3.1

6 years ago

1.2.0

6 years ago

1.1.1

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago