Module: Parser

Parser module
Author:
  • Onien
Source:

Methods

(inner) generateHTML(parsed) → {string}

generates html without using dom methods
Parameters:
Name Type Description
parsed Map
Source:
Returns:
html
Type
string
Example
// returns <div style="background: green">hello</div>
 generateHTML(new Map([
   ["background", "green"],
   ["tag", "div"],
   ["text", "hello"]
 ]));

(inner) generateHTMLDOM() → {string|Array.Object}

generates html using dom
Source:
See:
  • generateHTML
Returns:
if dom isnt exists, it will return array of objects with errors
Type
string | Array.Object

(inner) parse(str, data, options) → {string|Array.<string>}

parses text to html
Parameters:
Name Type Description
str string string to parse
data Object
options Object
Properties
Name Type Description
useDOM boolean
Source:
Returns:
parsed text (html) or array of errors
Type
string | Array.<string>
Example
// returns Hello, onien! I think you want to eat and to do .... Btw, <span style="color: red; ">this is the phrase</span>. Oh, <span style="background: green; ">green back?</span>
 parse("Hello, {name}! I think you want {wants.0} and {wants.1}. Btw, { text=phrase, color='red' }. Oh, { text='green back?', background='green' }", 
 {
   name: "onien",
   wants: [
     "to eat",
     "to do ..."
   ],
   phrase: "this is the phrase"
 })
 

(inner) parseVar(token, data) → {*}

parses and finds varible from given data
Parameters:
Name Type Description
token string varible token
data Object data
Source:
Returns:
value
Type
*
Example
// returns "hello"
 parseVar("data.1.really", {
   data: [
     "something",
     {
       really: "hello"
     }
   ]
 })
 

(inner) Throw(message, trace) → {string}

retuns error message
Parameters:
Name Type Description
message string
trace Object
Properties
Name Type Description
idx number
substr string
substridx number
token string
Source:
Returns:
message
Type
string
Example
// returns "ERROR: message at 2! Substring wowo - 5 in token tokeeen"
 Throw("message", {
   idx: 2, substr: "wowo", substridx: 5, token: "tokeeen"
 })