1.0.1 • Published 4 years ago

highlight-words-parser v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

Highlight Words Parser

Features

Parse a give string to highlight words.

Installation

yarn add highlight-words-parser

or

npm i highlight-words-parser --save

Usage

import { highlightWordsParser } from 'highlight-words-parser'

const highlightWords = highlightWordsParser('Error: this is a "test" message (from somewind)', {
  keywords: [{
    color: 'red',
    value: [
      'Error'
    ]
  }],
  scopes: [
    {
      color: 'green',
      value: ['"', '"']
    },
    {
      color: 'green',
      value: ['(', ')']
    }
  ]
})

console.log(highlightWords)

// Output:
//
// [ { color: 'red', value: 'Error' },
//   { value: ': this is a ' },
//   { color: 'green', value: '"test"' },
//   { value: ' message ' },
//   { color: 'green', value: '(from somewind)' } ]

You can use the result to render with React or other.

License

MIT