parse-annotation-blocks

1.1.0 • Public • Published

parse-annotation-blocks

ES6 string splitting by annotated comments. Parse blocks of text wrapped in annotated comments to a JS object.

For example, if your string contains:

/* @start someKey */ 
Some content 
/* @end someKey */ 

The module will extract the text between the @start and @end comments and return an object like:

{
    someKey: "Some content" 
}

Installation

npm install parse-annotation-blocks 

or

yarn add parse-annotation-blocks

Usage

An example:

let parseAnnotations = require('parse-annotation-blocks');

let string = `
  /* @start firstKey */  
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
  /* @end firstKey */

  
  /* @start secondKey */
  Sed at est pellentesque ante ultricies aliquet aliquam a tellus. Donec eget urna velit. Mauris ac scelerisque lacus. 
  /* @end secondKey */
  
  This is outside a comment @start and @end block, so won't get included in the returned object. 
  `

let outputObject = parseAnnotations(string);

Credits

https://github.com/rjjakes

License

MIT

Package Sidebar

Install

npm i parse-annotation-blocks

Weekly Downloads

159

Version

1.1.0

License

MIT

Unpacked Size

7.51 kB

Total Files

7

Last publish

Collaborators

  • rjjakes