# string-replace-enhanced

> A package to go further with string replace

Latest version **1.0.3** (published 2019-04-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install string-replace-enhanced
pnpm add string-replace-enhanced
yarn add string-replace-enhanced
bun add string-replace-enhanced
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2019-04-08 |
| First published | 2019-01-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 40 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Riouallon Vincent |
| Maintainers | artentica |
| Keywords | nbsp, &nbsp;, non-breaking, space, string, replace, string-replace, string-replace-enhanced, regex |

## Links

- npm: https://www.npmjs.com/package/string-replace-enhanced
- Repository: https://github.com/artentica/string-replace-enhanced
- Homepage: https://artentica.github.io/string-replace-enhanced/
- Issues: https://github.com/artentica/string-replace-enhanced/issues
- npm.io page: https://npm.io/package/string-replace-enhanced

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 1.0.3 (latest) — 2019-04-08
- 1.0.2 — 2019-01-11
- 1.0.1 — 2019-01-11

## README

<h1 align="center" style="border-bottom: none;">📝✏️string-replace-enhanced</h1>
<h3 align="center">A package to go further with string replace</h3>
<p align="center">
  <a href="https://opensource.org/licenses/MIT">
    <img alt="MIT licenses" src="https://img.shields.io/badge/License-MIT-yellow.svg">
  </a>
  <a href="https://snyk.io/test/github/artentica/string-replace-enhanced?targetFile=package.json">
    <img alt="snyk" src="https://snyk.io/test/github/artentica/string-replace-enhanced/badge.svg?targetFile=package.json">
  </a>
  <a href="http://badge.fury.io/js/string-replace-enhanced">
    <img alt="NPM version" src="https://badge.fury.io/js/string-replace-enhanced.svg">
  </a>
  <a href="http://badge.fury.io/js/string-replace-enhanced">
    <img alt="NPM dependencies" src="https://img.shields.io/david/artentica/string-replace-enhanced.svg">
  </a>
  <a href="https://travis-ci.com/artentica/string-replace-enhanced">
    <img alt="Travis" src="https://travis-ci.com/artentica/string-replace-enhanced.svg?branch=master">
  </a>
  <a href="https://codecov.io/gh/artentica/string-replace-enhanced">
    <img alt="codecov" src="https://img.shields.io/codecov/c/github/artentica/string-replace-enhanced.svg">
  </a>
  <a class="badge-align" href="https://www.codacy.com/app/artentica/string-replace-enhanced?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=artentica/string-replace-enhanced&amp;utm_campaign=Badge_Grade">
    <img alt="Codacy" src="https://api.codacy.com/project/badge/Grade/e09a761c88be427ba0a43713055b8ce9"/>
  </a>
  <a href="#badge">
    <img alt="bundlephobia" src="https://img.shields.io/bundlephobia/min/string-replace-enhanced.svg">
  </a>
  <a href="#badge">
    <img alt="semantic-release" src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg">
  </a>
  <a href="http://makeapullrequest.com">
    <img alt="PRs Welcome" src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg">
  </a>
</p>

**string-replace-enhanced** allow you to go futher with the command replace for string in javascript. You have two options, use the object and implement his settings or use the functions in a standalone way.

## Installation

Using npm:

    npm install -S string-replace-enhanced

... and then:

```javascript
import stringReplaceEnhanced from 'string-replace-enhanced'
//  or
import {replaceBefore, replaceAfter, replaceAround, replace, replaceRegex} from 'string-replace-enhanced'
//  or
const {default: stringReplaceEnhanced} = require('string-replace-enhanced')
```

In NodeJS:

```javascript
const {default : stringReplaceEnhanced} = require('string-replace-enhanced')
//  or
import {replaceBefore, replaceAfter, replaceAround, replace, replaceRegex} from 'string-replace-enhanced'
```

In a browser:

```html
<script src="https://unpkg.com/string-replace-enhanced@latest/lib/sre.min.js"></script>
<script>
  /* stringReplaceEnhanced is available here */
  /* in object style */

  new StringReplaceEnhanced.default(options) //constructor

  /* standalone functions */

  StringReplaceEnhanced.replace(...args) //function
</script>
```

## Usage

There is two possibilities, use the object ou the separated functions.

### Object

With the object it will be possible to reuse a preset configuration or use the default one.

```javascript
import stringReplaceEnhanced from 'string-replace-enhanced'

// If an option is missing, it will be given a default value
const options =  {
  after: ['«'],
  around: [],
  before: ['!', '?', ':', ';', '»'],
  regex: [],
  replacer: '&nbsp;',
  toReplace: ' ',
};

// Create a new stringReplaceEnhanced object
const sre = new stringReplaceEnhanced(options);

// Use its methods simply giving the string to work on
console.log(sre.replaceBefore('Hello world !'));
// Hello world&nbsp;!
```

### Functions

For the standalone functions you will need to specify every arguments

```javascript
import { replaceBefore } from 'string-replace-enhanced'

console.log(replaceBefore('Hello world !', ' ', '&nbsp;'))
// Hello world&nbsp;!
```

## Options

Check the links below to have the up to date version:

 - All options are documented in [here](https://artentica.github.io/string-replace-enhanced/interfaces/_interfaces_.isettings.html)

 - The default object implementation's settings is [here](https://artentica.github.io/string-replace-enhanced/modules/_defaultsetttings_.html)

| name      | type                            | default                     | description                                                                          |
| --------- | ------------------------------- | --------------------------- | ------------------------------------------------------------------------------------ |
| after     | ReadonlyArray<string> or string | `['«']`                     | Array of char in need of potential need of replacement after itself                  |
| around    | ReadonlyArray<string> or string | `[]`                        | Array of char in need of potential need of replacement around itself                 |
| before    | ReadonlyArray<string> or string | `['!', '?', ':', ';', '»']` | Array of char in need of potential need of replacement before itself                 |
| regex     | ReadonlyArray<RegExp> or RegExp | `[]`                        | Array of regex, replace match by the replacer                                        |
| replacer  | string                          | `'&nbsp;'`                  | Replacer of matching `toReplace`                                                     |
| toReplace | string                          | `' '`                       | String to replace, *in the function _replace_ `toReplace` can be an array of string* |


## Properties and methods

To see more about the methods and properties you can access to the documentation [here](https://artentica.github.io/string-replace-enhanced/modules/_core_.html)


## Documentation

To see more about the functions or the configuration you can access it in the latest documentation [here](https://artentica.github.io/string-replace-enhanced/) or one in the forked project:

    npm i && npm run build:doc

The documentation will be available in the `docs` file.

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