# react-text-source

> A package that makes replace jsx components content easier.

Latest version **0.0.2** (published 2019-01-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-text-source
pnpm add react-text-source
yarn add react-text-source
bun add react-text-source
```

## 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.0.2 |
| Published | 2019-01-04 |
| First published | 2019-01-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 7 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Gabriel Freitas |
| Maintainers | nneutrinno |
| Keywords | react, component, string, text, array, replace |

## Links

- npm: https://www.npmjs.com/package/react-text-source
- Repository: https://github.com/nneutrinno/react-text-replace
- Homepage: https://github.com/nneutrinno/react-text-replace#readme
- Issues: https://github.com/nneutrinno/react-text-replace/issues
- npm.io page: https://npm.io/package/react-text-source

## Dependencies (3)

- [uuid](https://npm.io/package/uuid.md) ^3.3.2
- [react](https://npm.io/package/react.md) ^16.7.0
- [react-dom](https://npm.io/package/react-dom.md) ^16.7.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.0.2 (latest) — 2019-01-04

## README

# React Text Replace

A package that makes replace jsx components content easier.

## Install

### [NPM](http://npmjs.org/)
- Use: `require('react-text-replace')`
- Install: `npm install --save react-text-source`

### [YARN](https://yarnpkg.com/)
- Use: `require('react-text-replace')`
- Install: `yarn add react-text-replace`

## Usage

### Basic Example

``` javascript
import React from "react"
import { textReplace } from "react-text-replace"
import uuidv1 from "uuid/v1"

const App = props =>
  textReplace({
    source: ">> Hello >> world >> !!",
    find: />>(.*)/,
    call(match, $1) {
      return <h1 key={uuidv1()}>{$1}</h1>
    }
  })
```
#### First Result

```html
<h1> Hello >> world >> !!</h1>
```

### Multiple Replaces Example

``` javascript
import React from "react"
import { textReplace } from "react-text-replace"
import uuidv1 from "uuid/v1"

const source = ">> Hello >> world >> !!"

const options = [
  {
    find: />>(.*)/,
    call(match, $1) {
      return (
        <span style={{ fontSize: "2em" }} key={uuidv1()}>
          {$1}
        </span>
      )
    }
  },
  {
    find: /!!/,
    call(match) {
      return <i key={uuidv1()}>{match}</i>
    }
  }
]

var App = props =>
  textReplace(source, options) || textReplace(source, ...options)
```

#### The Result Will Be

``` html
<span style="font-size: 2em">
  Hello >> world >> <i>!!</i>
</span>
```


### Recursive Example With Caching

``` javascript
import React from "react"
import { TextReplace } from "react-text-replace"
import uuidv1 from "uuid/v1"

// Creates a cache that lasts until close the page

const App = props => (
  <TextReplace
    source={">> Hello >> world >> !!"}
    pipe={[
      {
        find: />>(.*)/,
        call(match, $1) {
          return (
            <span style={{ fontSize: "2em" }} key={uuidv1()}>
              {$1}
            </span>
          )
        },
        isRecursive: true
      },
      {
        find: /!!/,
        call(match) {
          return <i key={uuidv1()}>{match}</i>
        }
      }
    ]}
  />
)
```

#### Will Result In

``` html
<span style="font-size: 2em"> Hello 
  <span style="font-size: 2em"> world 
    <span style="font-size: 2em">
      <i>!!</i>
    </span>
  </span>
</span>
```

## License

Licensed under [permissive](http://en.wikipedia.org/wiki/Permissive_free_software_licence) [MIT license](http://opensource.org/licenses/MIT)

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