text-parser

1.1.3 • Public • Published

HOW TO USE:

Firstly init it like that:

var parser=new (require("text-parser"))({
    folder:__dirname+"/lang/parser", //Folder with avail. languages
    langs:["en"]                     //avail. language list
});

Nextly create file with your language (folder/language.json) and fill thim like that:

{
    "stringname": [
        "variant1 {{num:id}}, {{str:string}},{{type:any_or_not}}:{{t:string}}",
        "variant2 {{num:id}}:{{str:string}}:{{t:string}}",
    ]
}

And use it like this:

var stringToParse="variant1 3, test,:test2"
parser.parse("stringname",stringToParse,(out)=>{
    console.log(out);
    //Will write: 
    // {num:3, str:test, type:"", t:test2}
})
stringToParse="variant1 3, test,test3:test2"
parser.parse("stringname",stringToParse,(out)=>{
    console.log(out);
    //Will write: 
    // {num:3, str:test, type:"test3", t:test2}
})

If input string does not matched requested, callback will be not executed.

Readme

Keywords

Package Sidebar

Install

npm i text-parser

Weekly Downloads

1

Version

1.1.3

License

WTFPL

Last publish

Collaborators

  • f6cf