# text-decorator

> Be able to help to modify texts

Latest version **0.1.1** (published 2023-06-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install text-decorator
pnpm add text-decorator
yarn add text-decorator
bun add text-decorator
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2023-06-17 |
| First published | 2016-05-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 10.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Sparrow.jang |
| Maintainers | sparrowjang |
| Keywords | decorator, html, text, replace, keyword |

## Links

- npm: https://www.npmjs.com/package/text-decorator
- Repository: https://github.com/eHanlin/text-decorator
- Homepage: https://github.com/eHanlin/text-decorator#readme
- Issues: https://github.com/eHanlin/text-decorator/issues
- npm.io page: https://npm.io/package/text-decorator

## Dependencies (1)

- [escape-string-regexp](https://npm.io/package/escape-string-regexp.md) ^1.0.5

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 0.1.1 (latest) — 2023-06-17
- 0.1.0 — 2023-06-16
- 0.0.7 — 2018-03-22
- 0.0.6 — 2018-03-20
- 0.0.5 — 2018-01-08
- 0.0.4 — 2018-01-05
- 0.0.3 — 2018-01-05
- 0.0.2 — 2016-05-03
- 0.0.1 — 2016-05-03

## README

text-decorator
=======================================================

[![Build Status](https://travis-ci.org/eHanlin/text-decorator.svg?branch=master)](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
```

---
_Source: https://npm.io/package/text-decorator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
