@telenko/string-stream

1.0.1 • Public • Published

#General description Library which allows to work with strings as with streams. Allows to write parsers, tokenizers etc.

#API ..tbd

#Example Pseudo-code of writing html-parser

    function readNode () {
      var childs = [];
      var tag = stream.readNext('<');
      var tagName = stream.readNextWord();
      stream.startRecording();
      var endTag = stream.readNext('>');
      var nodeTemplate = stream.stopRecording();
      while (true) {
          stream.startRecording();
          stream.readNext('<');
          var textNode = stream.stopRecording();
          if (textNode.trim().length > 0) {
              childs.push({type: 'text', template: textNode});
          }
          if (stream.next() === '/') {
              break;
          } else {
              stream.moveBack(2);
              childs.push(readNode());
          }
      }
      var resp = {tagName: tagName, template: nodeTemplate, children: childs};
      return resp;
     }
    
     var nodes = [];
     while (!stream.isCompleted()) {
      nodes.push(readNode());
     }

Readme

Keywords

none

Package Sidebar

Install

npm i @telenko/string-stream

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

11.1 kB

Total Files

8

Last publish

Collaborators

  • andrii.telenko