text-decorator

0.1.1 • Public • Published

text-decorator

Build Status

The project is able to help to modify texts.

Install

npm install text-decorator

Usage

var textDecorator = require('text-decorator');

var decorateBold = function( text ) { 
  return `**${text}**`;
};

var result = textDecorator.decorate('This is a dog.', ['dog'], decorateBold);

//print 'This is a **dog**.'
console.log(result.text);

//print ['dog']
console.log(result.matches);

Follow this if you need ignore some words.

var result = textDecorator.decorate('這是一個裝飾者,不是飾者。', ['飾者'], decorateBold, {ignoreTexts:['裝飾者']});

//print '這是一個裝飾者,不是**飾者**。'
console.log(result.text);

API

textDecorator.decorate(text, keywords, replace)

To match keywords then replace.

name type required description
text string * The text will be replaced.
keywords string[] * The keywords will be matched.
replace function * To replace text content by matched.
opts object This is optional value.
opts.ignoreTexts string[] To ignore some words for mapping

Test

npm run test

Package Sidebar

Install

npm i text-decorator

Weekly Downloads

11

Version

0.1.1

License

MIT

Unpacked Size

11.1 kB

Total Files

7

Last publish

Collaborators

  • sparrowjang