https://github.com/ehanlin/text-decorator
Be able to help to modify texts.
https://github.com/ehanlin/text-decorator
Last synced: 8 months ago
JSON representation
Be able to help to modify texts.
- Host: GitHub
- URL: https://github.com/ehanlin/text-decorator
- Owner: eHanlin
- Created: 2016-05-03T07:06:25.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2023-06-17T08:28:19.000Z (about 3 years ago)
- Last Synced: 2025-01-30T13:16:02.343Z (over 1 year ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 0
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
text-decorator
=======================================================
[](https://travis-ci.org/eHanlin/text-decorator)
The project is able to help to modify texts.
## Install
```sh
npm install text-decorator
```
## Usage
```js
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.
```js
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
```sh
npm run test
```