0.1.1 • Published 11 months ago

text-decorator v0.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
11 months ago

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.

nametyperequireddescription
textstring*The text will be replaced.
keywordsstring[]*The keywords will be matched.
replacefunction*To replace text content by matched.
optsobjectThis is optional value.
opts.ignoreTextsstring[]To ignore some words for mapping

Test

npm run test
0.1.0

11 months ago

0.1.1

11 months ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

8 years ago

0.0.1

8 years ago